Skip to content

fs: Deferred inode reclaim

Jan Kara linux-fsdevel linux-mm 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 4 repliesIn review
  2. v25 patches 13 repliesSuperseded
  3. v1 RFC4 patches 0 repliesSuperseded

Changes in v3 from the cover letter

* Some cleanups and simplifications from Andreas Grunbacher
* Fixed couple of bugs pointed out by Sashiko
* Added support for auto-deferring eviction from iput() when inode has 0 link count and we are in reclaim path
* Added protection of deferred reclaim from filesystem freezing
* Throttling now doesn't happen directly in mark_inode_reclaim_deferred() but on exit to userspace

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7writeback: Fix missed lazytime flushfs/fs-writeback.c+2 -20 replies
2/7fs: Avoid inode dirtying on last iputfs/fs-writeback.c fs/inode.c fs/internal.h+52 -80 replies
3/7fs: Basic infrastructure for offloading inode reclaimfs/inode.c fs/super.c include/linux/fs.h +2 more+219 -40 replies
4/7fs: Defer reclaim of unlinked inodesfs/inode.c+17 -00 replies
5/7fs: Add throttling to deferred inode reclaimfs/inode.c include/linux/fs/super_types.h include/trace/events/writeback.h+170 -110 replies
6/7fs: Protect deferred inode reclaim from freezingfs/inode.c fs/super.c include/linux/fs/super.h +1 more+90 -160 replies
7/7ext4: Defer inode reclaim if it has preallocationsfs/ext4/mballoc.c+7 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH 0/7 v3] fs: Deferred inode reclaim

Hello,

here is the third revision of my patches implementing deferred inode reclaim to deal with MM warnings due to GFP_NOFAIL allocations from reclaim paths. This happens because to reclaim some inodes, filesystems have to do IO including complex operations using journalling and forward progress of these depends on successful memory allocations (which is impossible to guarantee from reclaim context).

Since the last revision the most notable changes include addition of automatic deferal of inode eviction from iput() when inode link-count is 0 and we are in reclaim (PF_MEMALLOC flag set). This path gets triggered e.g. by overlayfs whose inodes hold dentry references on upper filesystem and thus slab reclaim of overlayfs inodes can trigger the last dput() (and thus iput()) of already unlinked files. Since inode deletion is practically guaranteed to require IO (and thus possibly e.g. loading allocation information into memory) I've decided to unconditionally defer reclaim in this case instead of marking inodes in each filesystem.

Another bigger change in this series is that we now protect deferred inode reclaim from filesystem freezing. Otherwise inode eviction could block the reclaim worker on frozen filesystem which could stall deferred inode reclaim on the whole system. Deferred reclaim workers now skip reclaiming inodes on frozen filesystem and we block filesystem freezing while the worker is evicting current batch of its inodes.

The last bigger change is that mark_inode_reclaim_deferred() does not block when the queue of deferred inodes grows over limit anymore. Instead it queues task work to delay the task appropriately when returning to userspace. This solves possible lockups when tasks would get throttled when calling mark_inode_reclaim_deferred() with some locks or transaction started.

The patches have survived full fstests run on ext4 when marking all loaded ext4 inodes for deferred reclaim to stress the deferred reclaim paths. I have also tested (when marking all inodes for deferred reclaim) the patches by creating a memcg with 128m memory limit and then scanning from 10 processes 1m inodes in total which heavily exercises deferred inode reclaim paths. This also verified efficiency of throttling of marking of inodes for deferred reclaim. Basically we cannot guarantee any particular limit on the number of inodes queued for deferred reclaim as that is bound only by their number in memory and memory pressure. But as the number of queued inodes grows, the tasks creating them get slowed down so eventually some equilibrium is hit. In my VM this was at ~10k inodes (only slightly above the 8k limit when throttling kicks in) but this all very much depends on the reclaim pressure, speed of deferred reclaim etc. so I don't think this is some representative number.

The first patch is a pure fix for a problem I've hit when running fstests. The second patch deals with lazy timestamp updates which I've decided to handle better directly inside the writeback infrastructure instead of deferring reclaim. The remaining patches implement the inode reclaim deferal. Ext4 use of deferred inode reclaim is there mostly as a demonstration. Other filesystems need to determine which inodes need deferred reclaim and mark them as such which generally requires good internal knowledge of the filesystem. I'm hoping that once the infrastructure is there, fs developers prompted by MM warnings will start using it :). I know for a fact that besides ext4 e.g. gfs2 wants to use this infrastructure.

Honza

Changes since v2:
* Some cleanups and simplifications from Andreas Grunbacher
* Fixed couple of bugs pointed out by Sashiko
* Added support for auto-deferring eviction from iput() when inode has 0 link count and we are in reclaim path
* Added protection of deferred reclaim from filesystem freezing
* Throttling now doesn't happen directly in mark_inode_reclaim_deferred() but on exit to userspace

Changes since v1:
* Multiple workers to reclaim deferred inodes, related to that I've moved lists of deferred inodes from per-sb to global ones
* Added missed lazytime sync fix

Previous versions: