linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rik van Riel <riel@surriel.com>
To: hughd@google.com
Cc: xuyu@linux.alibaba.com, akpm@linux-foundation.org,
	mgorman@suse.de, aarcange@redhat.com, willy@infradead.org,
	linux-kernel@vger.kernel.org, kernel-team@fb.com,
	linux-mm@kvack.org, vbabka@suse.cz, mhocko@suse.com,
	Rik van Riel <riel@surriel.com>
Subject: [PATCH 2/3] mm,thp,shm: limit gfp mask to no more than specified
Date: Tue, 24 Nov 2020 14:49:24 -0500	[thread overview]
Message-ID: <20201124194925.623931-3-riel@surriel.com> (raw)
In-Reply-To: <20201124194925.623931-1-riel@surriel.com>

Matthew Wilcox pointed out that the i915 driver opportunistically
allocates tmpfs memory, but will happily reclaim some of its
pool if no memory is available.

Make sure the gfp mask used to opportunistically allocate a THP
is always at least as restrictive as the original gfp mask.

Signed-off-by: Rik van Riel <riel@surriel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
---
 mm/shmem.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mm/shmem.c b/mm/shmem.c
index 6c3cb192a88d..ee3cea10c2a4 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1531,6 +1531,26 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
 	return page;
 }
 
+/*
+ * Make sure huge_gfp is always more limited than limit_gfp.
+ * Some of the flags set permissions, while others set limitations.
+ */
+static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp)
+{
+	gfp_t allowflags = __GFP_IO | __GFP_FS | __GFP_RECLAIM;
+	gfp_t denyflags = __GFP_NOWARN | __GFP_NORETRY;
+	gfp_t result = huge_gfp & ~allowflags;
+
+	/*
+	 * Minimize the result gfp by taking the union with the deny flags,
+	 * and the intersection of the allow flags.
+	 */
+	result |= (limit_gfp & denyflags);
+	result |= (huge_gfp & limit_gfp) & allowflags;
+
+	return result;
+}
+
 static struct page *shmem_alloc_hugepage(gfp_t gfp,
 		struct shmem_inode_info *info, pgoff_t index)
 {
@@ -1889,6 +1909,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
 
 alloc_huge:
 	huge_gfp = vma_thp_gfp_mask(vma);
+	huge_gfp = limit_gfp_mask(huge_gfp, gfp);
 	page = shmem_alloc_and_acct_page(huge_gfp, inode, index, true);
 	if (IS_ERR(page)) {
 alloc_nohuge:
-- 
2.25.4



  parent reply	other threads:[~2020-11-24 19:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 19:49 [PATCH v6 0/3] mm,thp,shm: limit shmem THP alloc gfp_mask Rik van Riel
2020-11-24 19:49 ` [PATCH 1/3] mm,thp,shmem: " Rik van Riel
2020-11-26 16:56   ` Vlastimil Babka
2020-11-27  8:15   ` Michal Hocko
2020-11-24 19:49 ` Rik van Riel [this message]
2020-11-26 13:40   ` [PATCH 2/3] mm,thp,shm: limit gfp mask to no more than specified Michal Hocko
2020-11-26 18:04     ` Rik van Riel
2020-11-27  7:52       ` Michal Hocko
2020-11-27 19:03         ` Rik van Riel
2020-11-30 10:00           ` Michal Hocko
2020-11-30 14:40             ` Rik van Riel
2020-11-24 19:49 ` [PATCH 3/3] mm,thp,shmem: make khugepaged obey tmpfs mount flags Rik van Riel
2020-11-26 17:18   ` Vlastimil Babka
2020-11-26 18:14     ` Rik van Riel
2020-11-26 19:42       ` Vlastimil Babka
2020-11-26 20:14         ` Rik van Riel
2020-12-14 21:16 ` [PATCH v6 0/3] mm,thp,shm: limit shmem THP alloc gfp_mask Hugh Dickins
2020-12-14 22:20   ` Andrew Morton
2020-12-14 22:52   ` Vlastimil Babka
2021-02-24  8:41     ` Hugh Dickins
2021-02-24 14:46       ` Rik van Riel
2021-02-24 16:55         ` Hugh Dickins
2021-02-24 17:10           ` [PATCH 4/3] mm,shmem,thp: limit shmem THP allocations to requested zones Rik van Riel
2021-02-26 12:34             ` Vlastimil Babka

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=20201124194925.623931-3-riel@surriel.com \
    --to=riel@surriel.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=xuyu@linux.alibaba.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).