From: Peter Xu <peterx@redhat.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Mike Kravetz <mike.kravetz@oracle.com>,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
peterx@redhat.com, Yu Zhao <yuzhao@google.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Yang Shi <shy828301@gmail.com>, Hugh Dickins <hughd@google.com>,
"Kirill A . Shutemov" <kirill@shutemov.name>
Subject: [PATCH RFC v2 1/3] mm: Add TAIL_MAPPING_REUSED_MAX
Date: Mon, 14 Aug 2023 14:44:09 -0400 [thread overview]
Message-ID: <20230814184411.330496-2-peterx@redhat.com> (raw)
In-Reply-To: <20230814184411.330496-1-peterx@redhat.com>
Tail pages have a sanity check on ->mapping fields, not all of them but
only upon index>2. It's because we reused ->mapping fields of the tail
pages index=0,1 for other things.
Define a macro for "max index of tail pages that got ->mapping field
reused" on top of folio definition, because when we grow folio tail pages
we'd want to boost this too together.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/linux/mm_types.h | 9 +++++++++
mm/huge_memory.c | 6 +++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 291c05cacd48..3f2b0d46f5d6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -248,6 +248,15 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page)
return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page);
}
+/*
+ * This macro defines the maximum tail pages (of a folio) that can have the
+ * page->mapping field reused (offset 12 for 32bits, or 24 for 64bits).
+ *
+ * When the tail page's mapping field reused, it'll be exempted from
+ * ->mapping poisoning and checks. Also see the macro TAIL_MAPPING.
+ */
+#define TAIL_MAPPING_REUSED_MAX (2)
+
/**
* struct folio - Represents a contiguous set of bytes.
* @flags: Identical to the page flags.
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0b709d2c46c6..72f244e16dcb 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2444,9 +2444,9 @@ static void __split_huge_page_tail(struct page *head, int tail,
(1L << PG_dirty) |
LRU_GEN_MASK | LRU_REFS_MASK));
- /* ->mapping in first and second tail page is replaced by other uses */
- VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING,
- page_tail);
+ /* ->mapping in <=TAIL_MAPPING_REUSED_MAX tail pages are reused */
+ VM_BUG_ON_PAGE(tail > TAIL_MAPPING_REUSED_MAX &&
+ page_tail->mapping != TAIL_MAPPING, page_tail);
page_tail->mapping = head->mapping;
page_tail->index = head->index + tail;
--
2.41.0
next prev parent reply other threads:[~2023-08-14 18:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 18:44 [PATCH RFC v2 0/3] mm: Properly document tail pages for a folio Peter Xu
2023-08-14 18:44 ` Peter Xu [this message]
2023-08-14 18:52 ` [PATCH RFC v2 1/3] mm: Add TAIL_MAPPING_REUSED_MAX Peter Xu
2023-08-14 19:08 ` Matthew Wilcox
2023-08-14 19:51 ` Peter Xu
2023-08-14 18:44 ` [PATCH RFC v2 2/3] mm: Reorg and declare free spaces in struct folio tails Peter Xu
2023-08-14 18:44 ` [PATCH RFC v2 3/3] mm: Proper document tail pages fields for folio Peter Xu
2023-08-14 23:01 ` Randy Dunlap
2023-08-14 19:58 ` [PATCH RFC v2 0/3] mm: Properly document tail pages for a folio Matthew Wilcox
2023-08-14 20:21 ` Peter Xu
2023-08-15 3:45 ` Matthew Wilcox
2023-08-15 19:37 ` Peter Xu
2023-08-15 20:16 ` Matthew Wilcox
2023-08-15 20:39 ` Peter Xu
2023-08-15 21:03 ` Matthew Wilcox
2023-08-14 23:01 ` Randy Dunlap
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=20230814184411.330496-2-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=yuzhao@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox