On Wed, Nov 02, 2022 at 05:41:07PM -0600, Andreas Dilger wrote: > I was looking at the /sys/fs/ext4/*/lifetime_write_kbytes counters on > my home server and wondering about how accurate they are. That is most > interesting in the case of flash devices, to get a good idea of the > lifetime writes vs. actual rated drive writes per day. > > It looks like s_kbytes_written is only updated on clean unmount > via ext4_commit_super->ext4_update_super() and in a few error handling > codepaths. This means any in-memory updates are typically lost if the > server crashes or loses power (which is typical for long-running servers, > rather than a clean shutdown). > > It would be useful to periodically update the superblock with the current > value, maybe once an hour if the value has changed more than some small > margin (to take into account the *previous* update). The superblock used > to be written frequently via ->write_super(), but this has not been the > case since commit v3.5-rc5-19-g4d47603d9703. > > Any thoughts/objections to a periodic task calling ext4_update_super() > every hour if there have been any noticeable writes since the last time > it was called? This could potentially be more clever so that it only > writes if the disk is not asleep, and do the writes the next time it wakes, > but I'm not sure how easy/hard that is to detect at the filesystem level. > > Cheers, Andreas > > PS: there is *also* a function resize.c::ext4_update_super() for added > confusion, but that does something completely different... Hi Andreas, I don't have too much to contribute other than to say I think it's a good idea. Having the counter be more precise and as such more reliable is a good thing especially with what looks to me like a litte effort required. Thanks! -Lukas