All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Christian Brauner <brauner@kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>,
	Christoph Hellwig <hch@infradead.org>, <linux-mm@kvack.org>,
	Mikhail Rudenko <xyzzy@yandex-team.ru>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Jan Kara <jack@suse.cz>
Subject: [PATCH v5 0/8] fs: Deferred inode reclaim
Date: Tue,  1 Dec 2026 15:35:02 +0100	[thread overview]
Message-ID: <20261201105733.18997-1-jack@suse.cz> (raw)

Hello,

here is the fifth 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).

There is one notable change since v4 - I've dropped the patch implementing
protection of deferred inode reclaim from filesystem freezing. The reasons for
that are:

1) Inode reclaim can hang on frozen fs now the same way as with deferred inode
reclaim. So far nobody complained about kswapd being blocked like that and
blocking deferred inode reclaim worker is going to have even lower impact on
the system. So this apparently isn't a practical problem today.

2) Such blocking of inode eviction on frozen fs is rare (the only scenario I'm
aware of is overlayfs dropping last reference of unlinked inode on lower
fs from its ->evict method).

3) Protecting inode deferred inode reclaim from freezing (and blocking on
frozen fs) would introduce much more visible stalls in reclaim on frozen fs
with possible (userspace) deadlocks when somebody wants to read inode under
reclaim back into memory.

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 fixes queueing of inodes with only timestamps dirty into writeback
lists. The third 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 v4:
* Fix whitespace damage
* Avoid pointless schedule on 0 delays in throttle_inode_deferred_reclaim()
* Added fix for redirty_tail_locked() and process_inode_switch_wbs() to move
  inode to b_dirty_time list of only timestamps are dirty
* Waking of workes now takes into account total number of queued inodes, not
  just the immedialy queued batch so that more workers are woken up for a
  storm of single-inode additions.
* Removed freeze protection of reclaim workers

Changes since v3:
* Improve logic to expedite writeback of I_DIRTY_TIME inodes to handle also
  the case when inode is dirty or under writeback
* Defer reclaim of I_METADATA_WRITEBACK inodes
* Handle kernel workers when throttling deferred inode reclaim
* Fix memory leak in throttling code
* Fix synchronization between superblock teardown and deferred inode reclaim
* Fix synchronization between superblock freezing and deferred inode reclaim

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:
Link: http://lore.kernel.org/r/20260429174850.18223-1-jack@suse.cz # v1
Link: http://lore.kernel.org/r/20260911081309.14137-1-jack@suse.cz # v2
Link: http://lore.kernel.org/r/20261009133253.20102-1-jack@suse.cz # v3
Link: http://lore.kernel.org/r/20261124113450.3451-1-jack@suse.cz # v4
Link: http://lore.kernel.org/r/20261201105048.19293-1-jack@suse.cz # v4

             reply	other threads:[~2026-12-01 14:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:35 Jan Kara [this message]
2026-12-01 14:35 ` [PATCH v5 1/8] writeback: Fix missed lazytime flush Jan Kara
2026-12-01 14:35 ` [PATCH v5 2/8] fs: Fix inode writeback list placement for switched and redirtied inodes Jan Kara
2026-12-02 14:36   ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 3/8] fs: Avoid inode dirtying on last iput Jan Kara
2026-12-02 14:36   ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 4/8] fs: Basic infrastructure for offloading inode reclaim Jan Kara
2026-12-02 14:36   ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 5/8] fs: Defer reclaim of unlinked inodes Jan Kara
2026-12-02 14:36   ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 6/8] fs: Defer reclaim of inodes requiring metadata writeback Jan Kara
2026-12-01 14:35 ` [PATCH v5 7/8] fs: Add throttling to deferred inode reclaim Jan Kara
2026-12-02 14:36   ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 8/8] ext4: Defer inode reclaim if it has preallocations Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201105733.18997-1-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=agruenba@redhat.com \
    --cc=brauner@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=xyzzy@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.