linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 01/11] mm: Introduce struct folio
Date: Tue,  8 Dec 2020 19:46:43 +0000	[thread overview]
Message-ID: <20201208194653.19180-2-willy@infradead.org> (raw)
In-Reply-To: <20201208194653.19180-1-willy@infradead.org>

We have trouble keeping track of whether we've already called
compound_head() to ensure we're not operating on a tail page.  Further,
it's never clear whether we intend a struct page to refer to PAGE_SIZE
bytes or page_size(compound_head(page)).

Introduce a new type 'struct folio' that always refers to an entire
(possibly compound) page, and points to the head page (or base page).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/mm.h       |  5 +++++
 include/linux/mm_types.h | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d1f64744ace2..7db9a10f084b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -916,6 +916,11 @@ static inline unsigned int compound_order(struct page *page)
 	return page[1].compound_order;
 }
 
+static inline unsigned int folio_order(struct folio *folio)
+{
+	return compound_order(&folio->page);
+}
+
 static inline bool hpage_pincount_available(struct page *page)
 {
 	/*
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 65df8abd90bd..d7e487d9998f 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -223,6 +223,23 @@ struct page {
 #endif
 } _struct_page_alignment;
 
+/*
+ * A struct folio is either a base (order-0) page or the head page of
+ * a compound page.
+ */
+struct folio {
+	struct page page;
+};
+
+static inline struct folio *page_folio(struct page *page)
+{
+	unsigned long head = READ_ONCE(page->compound_head);
+
+	if (unlikely(head & 1))
+		return (struct folio *)(head - 1);
+	return (struct folio *)page;
+}
+
 static inline atomic_t *compound_mapcount_ptr(struct page *page)
 {
 	return &page[1].compound_mapcount;
-- 
2.29.2



  reply	other threads:[~2020-12-08 20:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08 19:46 [RFC PATCH 00/11] Page folios Matthew Wilcox (Oracle)
2020-12-08 19:46 ` Matthew Wilcox (Oracle) [this message]
2020-12-08 19:46 ` [RFC PATCH 02/11] mm: Add put_folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 03/11] mm: Add get_folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 04/11] mm: Create FolioFlags Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 05/11] mm: Add unlock_folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 06/11] mm: Add lock_folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 07/11] mm: Add lock_folio_killable Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 08/11] mm/filemap: Convert end_page_writeback to use a folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 09/11] mm/filemap: Convert mapping_get_entry and pagecache_get_page to folio Matthew Wilcox (Oracle)
2020-12-08 19:46 ` [RFC PATCH 10/11] mm/filemap: Add folio_add_to_page_cache Matthew Wilcox (Oracle)
2020-12-11  8:32   ` Nikolay Borisov
2020-12-08 19:46 ` [RFC PATCH 11/11] mm/swap: Convert rotate_reclaimable_page to folio Matthew Wilcox (Oracle)

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=20201208194653.19180-2-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).