All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org,
	brauner@kernel.org
Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com,
	a.manzanares@samsung.com, dave@stgolabs.net,
	yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org,
	patches@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 3/6] shmem: move reclaim check early on writepages()
Date: Thu,  2 Mar 2023 15:27:55 -0800	[thread overview]
Message-ID: <20230302232758.888157-4-mcgrof@kernel.org> (raw)
In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org>

i915_gem requires huge folios to be split when swapping.
However we have  check for usage of writepages() to ensure
it used only for swap purposes later. Avoid the splits if
we're not being called for reclaim, even if they should in
theory not happen.

This makes the conditions easier to follow on shem_writepage().

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 mm/shmem.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 2b9ff585a553..a5a6da51087e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1340,6 +1340,18 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 	swp_entry_t swap;
 	pgoff_t index;
 
+	/*
+	 * Our capabilities prevent regular writeback or sync from ever calling
+	 * shmem_writepage; but a stacking filesystem might use ->writepage of
+	 * its underlying filesystem, in which case tmpfs should write out to
+	 * swap only in response to memory pressure, and not for the writeback
+	 * threads or sync.
+	 */
+	if (!wbc->for_reclaim) {
+		WARN_ON_ONCE(1);	/* Still happens? Tell us about it! */
+		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,
@@ -1360,18 +1372,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 	if (!total_swap_pages)
 		goto redirty;
 
-	/*
-	 * Our capabilities prevent regular writeback or sync from ever calling
-	 * shmem_writepage; but a stacking filesystem might use ->writepage of
-	 * its underlying filesystem, in which case tmpfs should write out to
-	 * swap only in response to memory pressure, and not for the writeback
-	 * threads or sync.
-	 */
-	if (!wbc->for_reclaim) {
-		WARN_ON_ONCE(1);	/* Still happens? Tell us about it! */
-		goto redirty;
-	}
-
 	/*
 	 * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC
 	 * value into swapfile.c, the only way we can correctly account for a
-- 
2.39.1


  parent reply	other threads:[~2023-03-02 23:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 23:27 [PATCH 0/6] tmpfs: add the option to disable swap Luis Chamberlain
2023-03-02 23:27 ` [PATCH 1/6] shmem: remove check for folio lock on writepage() Luis Chamberlain
2023-03-06 13:59   ` David Hildenbrand
2023-03-02 23:27 ` [PATCH 2/6] shmem: set shmem_writepage() variables early Luis Chamberlain
2023-03-06 13:59   ` David Hildenbrand
2023-03-06 17:06   ` Christian Brauner
2023-03-02 23:27 ` Luis Chamberlain [this message]
2023-03-06 14:01   ` [PATCH 3/6] shmem: move reclaim check early on writepages() David Hildenbrand
2023-03-08 21:30     ` Luis Chamberlain
2023-03-06 19:49   ` Yosry Ahmed
2023-03-02 23:27 ` [PATCH 4/6] shmem: skip page split if we're not reclaiming Luis Chamberlain
2023-03-06 14:02   ` David Hildenbrand
2023-03-06 19:49   ` Yosry Ahmed
2023-03-02 23:27 ` [PATCH 5/6] shmem: update documentation Luis Chamberlain
2023-03-06 14:04   ` David Hildenbrand
2023-03-08 22:16     ` Luis Chamberlain
2023-03-06 17:05   ` Christian Brauner
2023-03-02 23:27 ` [PATCH 6/6] shmem: add support to ignore swap Luis Chamberlain
2023-03-06 20:03   ` Yosry Ahmed
2023-03-08 22:21     ` Luis Chamberlain
2023-03-06 17:09 ` [PATCH 0/6] tmpfs: add the option to disable swap Christian Brauner

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=20230302232758.888157-4-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=a.manzanares@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=da.gomez@samsung.com \
    --cc=dave@stgolabs.net \
    --cc=hughd@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=p.raghav@samsung.com \
    --cc=patches@lists.linux.dev \
    --cc=willy@infradead.org \
    --cc=yosryahmed@google.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 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.