Linux-mm Archive on
 help / color / Atom feed
* [patch 151/158] mm: shmem: use proper gfp flags for shmem_writepage()
@ 2019-12-01  1:58 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2019-12-01  1:58 UTC (permalink / raw)
  To: akpm, hughd, linux-mm, mhocko, mm-commits, torvalds, yang.shi

From: Yang Shi <>
Subject: mm: shmem: use proper gfp flags for shmem_writepage()

The shmem_writepage() uses GFP_ATOMIC to allocate swap cache.  GFP_ATOMIC
used to mean __GFP_HIGH, but now it means __GFP_HIGH | __GFP_ATOMIC |
__GFP_KSWAPD_RECLAIM.  However, shmem_writepage() should write out to swap
only in response to memory pressure, so __GFP_KSWAPD_RECLAIM looks useless
since the caller may be kswapd itself or in direct reclaim already.

In addition, XArray node allocations from PF_MEMALLOC contexts could
completely exhaust the page allocator, __GFP_NOMEMALLOC stops emergency
reserves from being allocated.

Here just copy the gfp flags used by add_to_swap().

Hugh: "a cleanup to make the two calls look the same when they don't need
to be different (whereas the call from __read_swap_cache_async() rightly
uses a lower priority gfp)".

Signed-off-by: Yang Shi <>
Acked-by: Hugh Dickins <>
Cc: Michal Hocko <>
Signed-off-by: Andrew Morton <>

 mm/shmem.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/mm/shmem.c~mm-shmem-use-proper-gfp-flags-for-shmem_writepage
+++ a/mm/shmem.c
@@ -1369,7 +1369,8 @@ static int shmem_writepage(struct page *
 	if (list_empty(&info->swaplist))
 		list_add(&info->swaplist, &shmem_swaplist);
-	if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {
+	if (add_to_swap_cache(page, swap,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  1:58 [patch 151/158] mm: shmem: use proper gfp flags for shmem_writepage() akpm

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone