Skip to content

Commit

Permalink
shmem: skip page split if we're not reclaiming
Browse files Browse the repository at this point in the history
In theory when info->flags & VM_LOCKED we should not be getting
shem_writepage() called so we should be verifying this with a
WARN_ON_ONCE().  Since we should not be swapping then best to ensure we
also don't do the folio split earlier too.  So just move the check early
to avoid folio splits in case its a dubious call.

We also have a similar early bail when !total_swap_pages so just move that
earlier to avoid the possible folio split in the same situation.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Luis Chamberlain <[email protected]>
Acked-by: David Hildenbrand <[email protected]>
Reviewed-by: Christian Brauner <[email protected]>
Reviewed-by: Yosry Ahmed <[email protected]>
Tested-by: Xin Hao <[email protected]>
Reviewed-by: Davidlohr Bueso <[email protected]>
Cc: Adam Manzanares <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Pankaj Raghav <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
mcgrof authored and akpm00 committed Mar 28, 2023
1 parent cf7992b commit 9a976f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,12 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
if (WARN_ON_ONCE(!wbc->for_reclaim))
goto redirty;

if (WARN_ON_ONCE(info->flags & VM_LOCKED))
goto redirty;

if (!total_swap_pages)
goto redirty;

/*
* If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or
* "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages,
Expand All @@ -1362,10 +1368,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
}

index = folio->index;
if (info->flags & VM_LOCKED)
goto redirty;
if (!total_swap_pages)
goto redirty;

/*
* This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC
Expand Down

0 comments on commit 9a976f0

Please sign in to comment.