From: Luis Chamberlain <mcgrof@kernel.org>
To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org
Cc: linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net,
a.manzanares@samsung.com, linux-kernel@vger.kernel.org,
Luis Chamberlain <mcgrof@kernel.org>
Subject: [RFC 1/2] shmem: set shmem_writepage() variables early
Date: Mon, 6 Feb 2023 18:52:58 -0800 [thread overview]
Message-ID: <20230207025259.2522793-2-mcgrof@kernel.org> (raw)
In-Reply-To: <20230207025259.2522793-1-mcgrof@kernel.org>
shmem_writepage() sets up variables typically used *after* a possible
huge page split. However even if that does happen the address space
mapping should not change. So it should be safe to set that from
the beginning.
The folio should always be locked from the start as well. It however
was not clear if the folio address can / should change, as well as
the first inode.
This commit makes no functional changes other a double check on the
folio locking which might be superflous. This change should help make
the subsequent patch easier to review.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
mm/shmem.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index 28f3c699c8ce..a2c6aa11aab8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1332,11 +1332,13 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
{
struct folio *folio = page_folio(page);
struct shmem_inode_info *info;
- struct address_space *mapping;
- struct inode *inode;
+ struct address_space *mapping = folio->mapping;
+ struct inode *inode = mapping->host;
swp_entry_t swap;
pgoff_t index;
+ BUG_ON(!folio_test_locked(folio));
+
/*
* If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or
* "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages,
@@ -1351,8 +1353,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
folio_clear_dirty(folio);
}
+ /* Can the folio or first inode change on after a split? */
BUG_ON(!folio_test_locked(folio));
- mapping = folio->mapping;
index = folio->index;
inode = mapping->host;
info = SHMEM_I(inode);
--
2.39.0
next prev parent reply other threads:[~2023-02-07 2:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 2:52 [RFC 0/2] tmpfs: add the option to disable swap Luis Chamberlain
2023-02-07 2:52 ` Luis Chamberlain [this message]
2023-02-07 3:52 ` [RFC 1/2] shmem: set shmem_writepage() variables early Matthew Wilcox
2023-02-08 16:08 ` Luis Chamberlain
2023-02-07 2:52 ` [RFC 2/2] shmem: add support to ignore swap Luis Chamberlain
2023-02-07 4:01 ` Matthew Wilcox
2023-02-08 16:01 ` Luis Chamberlain
2023-02-08 17:45 ` Matthew Wilcox
2023-02-08 20:33 ` Yosry Ahmed
2023-02-23 0:53 ` Luis Chamberlain
2023-02-23 1:04 ` Yosry Ahmed
2023-02-23 1:35 ` Luis Chamberlain
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=20230207025259.2522793-2-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=a.manzanares@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=p.raghav@samsung.com \
--cc=willy@infradead.org \
/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