Skip to content

mm/percpu: Fix possible NOFS/NOIO reclaim recursion

Kaitao Cheng linux-mm lkml 4 versions – Applied

Status from this message: [merged mm-stable] mm-percpu-avoid-io-fs-reclaim-in-backing-allocations.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 5 repliesApplied 4/4
  2. v33 patches 7 repliesSuperseded
  3. v23 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches15 repliesSuperseded

Changes in v4 from the cover letter

- Make cached pages lookup explicit; (Dennis Zhou)
- Remove the changes in v3 and add a comment explaining why __GFP_NOFAIL must not be passed. (Dennis Zhou, Michal Hocko, Andrew Morton)

Patches in v4 All 4 applied

#Subject and filesSizeRepliesApplied
1/4mm/vmalloc: honor GFP constraints in pcpu_get_vm_areas()include/linux/vmalloc.h mm/percpu-vm.c mm/vmalloc.c+15 -141 replyApplied
2/4mm/percpu: honor GFP constraints when populating chunksmm/percpu-vm.c mm/percpu.c+27 -131 replyApplied
3/4mm/percpu: Make cached pages lookup explicitmm/percpu-vm.c+9 -30 repliesApplied
4/4mm/percpu: Avoid IO/FS reclaim in backing allocationsmm/percpu.c+13 -53 repliesApplied

Reviews trailers per patch

3 of 4 patches have a Reviewed-by or Acked-by.

PatchUladzislau Rezki (Sony)Shivam KalraDennis ZhouMichal Hocko
1/4R-b R-b A-b A-b
2/4A-b A-b
3/4
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/4] mm/percpu: Fix possible NOFS/NOIO reclaim recursion

Commit 9a5b183941b5 ("mm, percpu: do not consider sleepable allocations atomic") allowed GFP_NOFS and GFP_NOIO percpu allocations to use pcpu_alloc_mutex and the chunk creation slow path. This restored the allocation capability that was lost when those constrained allocations were treated as atomic, but it also makes the percpu slow path visible to callers from constrained reclaim contexts.

There are two related problems.

First, the create and populate slow paths do not fully preserve the caller's allocation constraints. pcpu_alloc_noprof() derives pcpu_gfp from the caller supplied GFP mask and passes it down to the percpu backing page allocator. However, chunk creation calls pcpu_get_vm_areas(), and chunk population can allocate temporary metadata or vmalloc page tables while mapping backing pages. Those internal allocations can still use GFP_KERNEL, so a caller using GFP_NOFS or GFP_NOIO can enter unconstrained FS or IO reclaim while holding pcpu_alloc_mutex.

One possible case is blk-cgroup after commit 5d726c4dbeed ("blk-cgroup: fix possible deadlock while configuring policy"). blkg_conf_prep() now serializes against blkcg_deactivate_policy() with q->blkcg_mutex, and blkg_alloc() uses GFP_NOIO because queue freeze and IO reclaim dependencies can otherwise deadlock. If the percpu slow path loses that GFP_NOIO context, direct reclaim or writeback can issue IO to a frozen queue while q->blkcg_mutex is held.

Second, allowing sleepable GFP_NOFS/GFP_NOIO allocations to take pcpu_alloc_mutex means that unconstrained backing allocations made under the mutex can create an FS/IO reclaim dependency against a constrained caller which already holds an FS or IO lock and then waits for pcpu_alloc_mutex.

This series fixes those issues in three steps:

- pass the caller supplied GFP mask into pcpu_get_vm_areas() and use it

    for vmalloc metadata and KASAN shadow allocations;
  - pass the GFP mask through the chunk population path, including the
    temporary pages array and vmalloc page table allocation scope;

- restrict percpu backing allocations performed while holding pcpu_alloc_mutex to GFP_NOIO, so they cannot recurse into IO or FS reclaim.

This keeps sleepable GFP_NOFS/GFP_NOIO percpu allocations working, while avoiding the reclaim recursion risks introduced by making those allocations eligible for the mutex-protected slow path.

Changes in v4:
- Make cached pages lookup explicit; (Dennis Zhou)
- Remove the changes in v3 and add a comment explaining why __GFP_NOFAIL must not be passed. (Dennis Zhou, Michal Hocko, Andrew Morton)

Changes in v3:
- Allow @gfp to pass __GFP_NOFAIL through.

Changes in v2:
- split the previous first patch into vmalloc-area creation and chunk population changes; (Pedro Falcato)
- pass the GFP mask explicitly to pcpu_get_vm_areas(); (Pedro Falcato)
- apply the corresponding memalloc scope around vmalloc page table allocation during chunk population;
- replace the reclaim recursion avoidance with a GFP_NOIO backing allocation mask instead of only rejecting nested reclaim. (Michal Hocko)

Link to v3:
https://lore.kernel.org/all/[email protected]/

Link to v2:
https://lore.kernel.org/all/[email protected]/

Link to v1:
https://lore.kernel.org/all/[email protected]/

Kaitao Cheng (4):
mm/vmalloc: honor GFP constraints in pcpu_get_vm_areas() mm/percpu: honor GFP constraints when populating chunks mm/percpu: Make cached pages lookup explicit mm/percpu: Avoid IO/FS reclaim in backing allocations

 include/linux/vmalloc.h |  4 ++--
 mm/percpu-vm.c          | 48 +++++++++++++++++++++++++++++------------
 mm/percpu.c             | 20 +++++++++++------
 mm/vmalloc.c            | 23 ++++++++++----------
 4 files changed, 62 insertions(+), 33 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)