mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roman Smirnov <r.smirnov@omp.ru>
To: <stable@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Roman Smirnov <r.smirnov@omp.ru>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Khoroshilov <khoroshilov@ispras.ru>,
	Sergey Shtylyov <s.shtylyov@omp.ru>,
	Karina Yankevich <k.yankevich@omp.ru>,
	<lvc-project@linuxtesting.org>, <linux-fsdevel@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	John Hubbard <jhubbard@nvidia.com>,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH 5.10 1/2] mm/truncate: Inline invalidate_complete_page() into its one caller
Date: Thu, 11 Jan 2024 14:37:46 +0000	[thread overview]
Message-ID: <20240111143747.4418-2-r.smirnov@omp.ru> (raw)
In-Reply-To: <20240111143747.4418-1-r.smirnov@omp.ru>

From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

Commit 1b8ddbeeb9b819e62b7190115023ce858a159f5c upstream.

invalidate_inode_page() is the only caller of invalidate_complete_page()
and inlining it reveals that the first check is unnecessary (because we
hold the page locked, and we just retrieved the mapping from the page).
Actually, it does make a difference, in that tail pages no longer fail
at this check, so it's now possible to remove a tail page from a mapping.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
---
 kernel/futex/core.c |  2 +-
 mm/truncate.c       | 31 +++++--------------------------
 2 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index cde0ca876b93..cbbebc3de1d3 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -578,7 +578,7 @@ static int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key,
 	 * found it, but truncated or holepunched or subjected to
 	 * invalidate_complete_page2 before we got the page lock (also
 	 * cases which we are happy to fail).  And we hold a reference,
-	 * so refcount care in invalidate_complete_page's remove_mapping
+	 * so refcount care in invalidate_inode_page's remove_mapping
 	 * prevents drop_caches from setting mapping to NULL beneath us.
 	 *
 	 * The case we do have to guard against is when memory pressure made
diff --git a/mm/truncate.c b/mm/truncate.c
index 8914ca4ce4b1..03998fd86e4a 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -190,30 +190,6 @@ static void truncate_cleanup_page(struct page *page)
 	ClearPageMappedToDisk(page);
 }
 
-/*
- * This is for invalidate_mapping_pages().  That function can be called at
- * any time, and is not supposed to throw away dirty pages.  But pages can
- * be marked dirty at any time too, so use remove_mapping which safely
- * discards clean, unused pages.
- *
- * Returns non-zero if the page was successfully invalidated.
- */
-static int
-invalidate_complete_page(struct address_space *mapping, struct page *page)
-{
-	int ret;
-
-	if (page->mapping != mapping)
-		return 0;
-
-	if (page_has_private(page) && !try_to_release_page(page, 0))
-		return 0;
-
-	ret = remove_mapping(mapping, page);
-
-	return ret;
-}
-
 int truncate_inode_page(struct address_space *mapping, struct page *page)
 {
 	VM_BUG_ON_PAGE(PageTail(page), page);
@@ -258,7 +234,10 @@ int invalidate_inode_page(struct page *page)
 		return 0;
 	if (page_mapped(page))
 		return 0;
-	return invalidate_complete_page(mapping, page);
+	if (page_has_private(page) && !try_to_release_page(page, 0))
+		return 0;
+
+	return remove_mapping(mapping, page);
 }
 
 /**
@@ -645,7 +624,7 @@ void invalidate_mapping_pagevec(struct address_space *mapping,
 }
 
 /*
- * This is like invalidate_complete_page(), except it ignores the page's
+ * This is like invalidate_inode_page(), except it ignores the page's
  * refcount.  We do this because invalidate_inode_pages2() needs stronger
  * invalidation guarantees, and cannot afford to leave pages behind because
  * shrink_page_list() has a temp ref on them, or because they're transiently
-- 
2.34.1


  reply	other threads:[~2024-01-11 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 14:37 [PATCH 5.10 0/2] mm/truncate: fix issue in ext4_set_page_dirty() Roman Smirnov
2024-01-11 14:37 ` Roman Smirnov [this message]
2024-01-11 14:37 ` [PATCH 5.10 2/2] mm/truncate: Replace page_mapped() call in invalidate_inode_page() Roman Smirnov
2024-01-11 15:31 ` [PATCH 5.10 0/2] mm/truncate: fix issue in ext4_set_page_dirty() Matthew Wilcox
2024-01-12 13:40   ` Roman Smirnov

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=20240111143747.4418-2-r.smirnov@omp.ru \
    --to=r.smirnov@omp.ru \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=jhubbard@nvidia.com \
    --cc=k.yankevich@omp.ru \
    --cc=khoroshilov@ispras.ru \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=s.shtylyov@omp.ru \
    --cc=stable@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®