All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: akpm@linux-foundation.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Jeff Layton <jlayton@kernel.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	William Kucharski <william.kucharski@oracle.com>
Subject: [PATCH v11 12/33] mm: Handle per-folio private data
Date: Mon, 14 Jun 2021 21:14:14 +0100	[thread overview]
Message-ID: <20210614201435.1379188-13-willy@infradead.org> (raw)
In-Reply-To: <20210614201435.1379188-1-willy@infradead.org>

Add folio_get_private() which mirrors page_private() -- ie folio private
data is the same as page private data.  The only difference is that these
return a void * instead of an unsigned long, which matches the majority
of users.

Turn attach_page_private() into folio_attach_private() and reimplement
attach_page_private() as a wrapper.  No filesystem which uses page private
data currently supports compound pages, so we're free to define the rules.
attach_page_private() may only be called on a head page; if you want
to add private data to a tail page, you can call set_page_private()
directly (and shouldn't increment the page refcount!  That should be
done when adding private data to the head page / folio).

This saves 813 bytes of text with the distro-derived config that I'm
testing due to removing the calls to compound_head() in get_page()
& put_page().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
---
 include/linux/mm_types.h | 11 +++++++++
 include/linux/pagemap.h  | 48 ++++++++++++++++++++++++----------------
 2 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 3118ba8b5a4e..943854268986 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -302,6 +302,12 @@ static inline atomic_t *compound_pincount_ptr(struct page *page)
 #define PAGE_FRAG_CACHE_MAX_SIZE	__ALIGN_MASK(32768, ~PAGE_MASK)
 #define PAGE_FRAG_CACHE_MAX_ORDER	get_order(PAGE_FRAG_CACHE_MAX_SIZE)
 
+/*
+ * page_private can be used on tail pages.  However, PagePrivate is only
+ * checked by the VM on the head page.  So page_private on the tail pages
+ * should be used for data that's ancillary to the head page (eg attaching
+ * buffer heads to tail pages after attaching buffer heads to the head page)
+ */
 #define page_private(page)		((page)->private)
 
 static inline void set_page_private(struct page *page, unsigned long private)
@@ -309,6 +315,11 @@ static inline void set_page_private(struct page *page, unsigned long private)
 	page->private = private;
 }
 
+static inline void *folio_get_private(struct folio *folio)
+{
+	return folio->private;
+}
+
 struct page_frag_cache {
 	void * va;
 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c34abf2acc8b..91aaf3207ad0 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -184,42 +184,52 @@ static inline bool page_cache_get_speculative(struct page *page)
 }
 
 /**
- * attach_page_private - Attach private data to a page.
- * @page: Page to attach data to.
- * @data: Data to attach to page.
+ * folio_attach_private - Attach private data to a folio.
+ * @folio: Folio to attach data to.
+ * @data: Data to attach to folio.
  *
- * Attaching private data to a page increments the page's reference count.
- * The data must be detached before the page will be freed.
+ * Attaching private data to a folio increments the page's reference count.
+ * The data must be detached before the folio will be freed.
  */
-static inline void attach_page_private(struct page *page, void *data)
+static inline void folio_attach_private(struct folio *folio, void *data)
 {
-	get_page(page);
-	set_page_private(page, (unsigned long)data);
-	SetPagePrivate(page);
+	folio_get(folio);
+	folio->private = data;
+	folio_set_private_flag(folio);
 }
 
 /**
- * detach_page_private - Detach private data from a page.
- * @page: Page to detach data from.
+ * folio_detach_private - Detach private data from a folio.
+ * @folio: Folio to detach data from.
  *
- * Removes the data that was previously attached to the page and decrements
+ * Removes the data that was previously attached to the folio and decrements
  * the refcount on the page.
  *
- * Return: Data that was attached to the page.
+ * Return: Data that was attached to the folio.
  */
-static inline void *detach_page_private(struct page *page)
+static inline void *folio_detach_private(struct folio *folio)
 {
-	void *data = (void *)page_private(page);
+	void *data = folio_get_private(folio);
 
-	if (!PagePrivate(page))
+	if (!folio_private(folio))
 		return NULL;
-	ClearPagePrivate(page);
-	set_page_private(page, 0);
-	put_page(page);
+	folio_clear_private_flag(folio);
+	folio->private = NULL;
+	folio_put(folio);
 
 	return data;
 }
 
+static inline void attach_page_private(struct page *page, void *data)
+{
+	folio_attach_private(page_folio(page), data);
+}
+
+static inline void *detach_page_private(struct page *page)
+{
+	return folio_detach_private(page_folio(page));
+}
+
 #ifdef CONFIG_NUMA
 extern struct page *__page_cache_alloc(gfp_t gfp);
 #else
-- 
2.30.2


  parent reply	other threads:[~2021-06-14 20:24 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 20:14 [PATCH v11 00/33] Memory folios Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 01/33] mm: Convert get_page_unless_zero() to return bool Matthew Wilcox (Oracle)
2021-06-15  6:24   ` Christoph Hellwig
2021-06-14 20:14 ` [PATCH v11 02/33] mm: Introduce struct folio Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 03/33] mm: Add folio_pgdat(), folio_zone() and folio_zonenum() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 04/33] mm/vmstat: Add functions to account folio statistics Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 05/33] mm/debug: Add VM_BUG_ON_FOLIO() and VM_WARN_ON_ONCE_FOLIO() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 06/33] mm: Add folio reference count functions Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 07/33] mm: Add folio_put() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 08/33] mm: Add folio_get() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 09/33] mm: Add folio_try_get_rcu() Matthew Wilcox (Oracle)
2021-06-15  6:25   ` Christoph Hellwig
2021-06-14 20:14 ` [PATCH v11 10/33] mm: Add folio flag manipulation functions Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 11/33] mm/lru: Add folio LRU functions Matthew Wilcox (Oracle)
2021-06-15  6:27   ` Christoph Hellwig
2021-06-14 20:14 ` Matthew Wilcox (Oracle) [this message]
2021-06-14 20:14 ` [PATCH v11 13/33] mm/filemap: Add folio_index(), folio_file_page() and folio_contains() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 14/33] mm/filemap: Add folio_next_index() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 15/33] mm/filemap: Add folio_offset() and folio_file_offset() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 16/33] mm/util: Add folio_mapping() and folio_file_mapping() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 17/33] mm/memcg: Add folio wrappers for various functions Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 18/33] mm/filemap: Add folio_unlock() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 19/33] mm/filemap: Add folio_lock() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 20/33] mm/filemap: Add folio_lock_killable() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 21/33] mm/filemap: Add __folio_lock_async() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 22/33] mm/filemap: Add folio_wait_locked() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 23/33] mm/filemap: Add __folio_lock_or_retry() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 24/33] mm/swap: Add folio_rotate_reclaimable() Matthew Wilcox (Oracle)
2021-06-15  6:29   ` Christoph Hellwig
2021-06-14 20:14 ` [PATCH v11 25/33] mm/filemap: Add folio_end_writeback() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 26/33] mm/writeback: Add folio_wait_writeback() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 27/33] mm/writeback: Add folio_wait_stable() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 28/33] mm/filemap: Add folio_wait_bit() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 29/33] mm/filemap: Add folio_wake_bit() Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 30/33] mm/filemap: Convert page wait queues to be folios Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 31/33] mm/filemap: Add folio private_2 functions Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 32/33] fs/netfs: Add folio fscache functions Matthew Wilcox (Oracle)
2021-06-14 20:14 ` [PATCH v11 33/33] mm: Add folio_mapped() Matthew Wilcox (Oracle)
2021-06-15  6:31   ` Christoph Hellwig
2021-06-16  9:16 ` [PATCH v11 32/33] fs/netfs: Add folio fscache functions David Howells
2021-06-16  9:19 ` [PATCH v11 01/33] mm: Convert get_page_unless_zero() to return bool David Howells
2021-06-16  9:31 ` [PATCH v11 02/33] mm: Introduce struct folio David Howells
2021-06-16  9:36 ` [PATCH v11 04/33] mm/vmstat: Add functions to account folio statistics David Howells
2021-06-16  9:54 ` [PATCH v11 05/33] mm/debug: Add VM_BUG_ON_FOLIO() and VM_WARN_ON_ONCE_FOLIO() David Howells
2021-06-16  9:55 ` [PATCH v11 06/33] mm: Add folio reference count functions David Howells
2021-06-16  9:55 ` [PATCH v11 07/33] mm: Add folio_put() David Howells
2021-06-16  9:56 ` [PATCH v11 08/33] mm: Add folio_get() David Howells
2021-06-16  9:58 ` [PATCH v11 10/33] mm: Add folio flag manipulation functions David Howells
2021-06-16 10:00 ` [PATCH v11 11/33] mm/lru: Add folio LRU functions David Howells
2021-06-16 10:03 ` [PATCH v11 13/33] mm/filemap: Add folio_index(), folio_file_page() and folio_contains() David Howells
2021-06-16 11:38   ` Matthew Wilcox
2021-06-16 10:04 ` [PATCH v11 14/33] mm/filemap: Add folio_next_index() David Howells
2021-06-16 10:05 ` [PATCH v11 15/33] mm/filemap: Add folio_offset() and folio_file_offset() David Howells
2021-06-16 10:10 ` [PATCH v11 16/33] mm/util: Add folio_mapping() and folio_file_mapping() David Howells
2021-06-16 10:13 ` [PATCH v11 18/33] mm/filemap: Add folio_unlock() David Howells
2021-06-16 10:17 ` [PATCH v11 19/33] mm/filemap: Add folio_lock() David Howells
2021-06-16 10:22 ` [PATCH v11 21/33] mm/filemap: Add __folio_lock_async() David Howells
2021-06-16 10:23 ` [PATCH v11 22/33] mm/filemap: Add folio_wait_locked() David Howells
2021-06-16 10:27 ` [PATCH v11 24/33] mm/swap: Add folio_rotate_reclaimable() David Howells
2021-06-16 11:46   ` Matthew Wilcox
2021-06-16 10:30 ` [PATCH v11 26/33] mm/writeback: Add folio_wait_writeback() David Howells
2021-06-16 11:55   ` Matthew Wilcox
2021-06-16 10:32 ` [PATCH v11 27/33] mm/writeback: Add folio_wait_stable() David Howells
2021-06-16 10:33 ` [PATCH v11 28/33] mm/filemap: Add folio_wait_bit() David Howells
2021-06-16 10:35 ` [PATCH v11 30/33] mm/filemap: Convert page wait queues to be folios David Howells
2021-06-16 10:37 ` [PATCH v11 33/33] mm: Add folio_mapped() David Howells
2021-06-16 10:41 ` [PATCH v11 02/33] mm: Introduce struct folio David Howells
2021-06-16 10:54 ` [PATCH v11 00/33] Memory folios David Howells

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=20210614201435.1379188-13-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=jlayton@kernel.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    --cc=william.kucharski@oracle.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.