linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH V3 01/10] include/linux/pagemap.h: introduce attach/detach_page_private
       [not found] <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com>
@ 2020-05-07 21:43 ` Guoqing Jiang
  2020-05-07 21:44 ` [RFC PATCH V3 10/10] mm/migrate.c: call detach_page_private to cleanup code Guoqing Jiang
  1 sibling, 0 replies; 2+ messages in thread
From: Guoqing Jiang @ 2020-05-07 21:43 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: david, hch, willy, Guoqing Jiang, Andrew Morton, linux-mm,
	Darrick J. Wong, William Kucharski, Kirill A. Shutemov,
	Andreas Gruenbacher, Yang Shi, Yafang Shao, Song Liu, linux-raid,
	Chris Mason, Josef Bacik, David Sterba, linux-btrfs,
	Alexander Viro, Jaegeuk Kim, Chao Yu, linux-f2fs-devel,
	linux-xfs, Anton Altaparmakov, linux-ntfs-dev, Mike Marshall,
	Martin Brandenburg, devel, Thomas Gleixner,
	Sebastian Andrzej Siewior, Roman Gushchin, Andreas Dilger

The logic in attach_page_buffers and  __clear_page_buffers are quite
paired, but

1. they are located in different files.

2. attach_page_buffers is implemented in buffer_head.h, so it could be
   used by other files. But __clear_page_buffers is static function in
   buffer.c and other potential users can't call the function, md-bitmap
   even copied the function.

So, introduce the new attach/detach_page_private to replace them. With
the new pair of function, we will remove the usage of attach_page_buffers
and  __clear_page_buffers in next patches. Thanks for suggestions about
the function name from Alexander Viro, Andreas Grünbacher, Christoph
Hellwig and Matthew Wilcox.

Suggested-by: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Yafang Shao <laoar.shao@gmail.com>
Cc: Song Liu <song@kernel.org>
Cc: linux-raid@vger.kernel.org
Cc: Chris Mason <clm@fb.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Cc: Christoph Hellwig <hch@infradead.org>
Cc: linux-xfs@vger.kernel.org
Cc: Anton Altaparmakov <anton@tuxera.com>
Cc: linux-ntfs-dev@lists.sourceforge.net
Cc: Mike Marshall <hubcap@omnibond.com>
Cc: Martin Brandenburg <martin@omnibond.com>
Cc: devel@lists.orangefs.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Roman Gushchin <guro@fb.com>
Cc: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
---
RFC V2 -> RFC V3:
1. rename clear_page_private to detach_page_private.
2. updated the comments for the two functions.

RFC -> RFC V2:  Address the comments from Christoph Hellwig
1. change function names to attach/clear_page_private and add comments.
2. change the return type of attach_page_private.

 include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a8f7bd8ea1c6..99dd93188a5e 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -205,6 +205,43 @@ static inline int page_cache_add_speculative(struct page *page, int count)
 	return __page_cache_add_speculative(page, count);
 }
 
+/**
+ * attach_page_private - Attach private data to a page.
+ * @page: Page to attach data to.
+ * @data: Data to attach to page.
+ *
+ * Attaching private data to a page increments the page's reference count.
+ * The data must be detached before the page will be freed.
+ */
+static inline void attach_page_private(struct page *page, void *data)
+{
+	get_page(page);
+	set_page_private(page, (unsigned long)data);
+	SetPagePrivate(page);
+}
+
+/**
+ * detach_page_private - Detach private data from a page.
+ * @page: Page to detach data from.
+ *
+ * Removes the data that was previously attached to the page and decrements
+ * the refcount on the page.
+ *
+ * Return: Data that was attached to the page.
+ */
+static inline void *detach_page_private(struct page *page)
+{
+	void *data = (void *)page_private(page);
+
+	if (!PagePrivate(page))
+		return NULL;
+	ClearPagePrivate(page);
+	set_page_private(page, 0);
+	put_page(page);
+
+	return data;
+}
+
 #ifdef CONFIG_NUMA
 extern struct page *__page_cache_alloc(gfp_t gfp);
 #else
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [RFC PATCH V3 10/10] mm/migrate.c: call detach_page_private to cleanup code
       [not found] <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com>
  2020-05-07 21:43 ` [RFC PATCH V3 01/10] include/linux/pagemap.h: introduce attach/detach_page_private Guoqing Jiang
@ 2020-05-07 21:44 ` Guoqing Jiang
  1 sibling, 0 replies; 2+ messages in thread
From: Guoqing Jiang @ 2020-05-07 21:44 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: david, hch, willy, Guoqing Jiang, Andrew Morton, linux-mm

We can cleanup code a little by call detach_page_private here.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
---
Added since RFC V3.

 mm/migrate.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 7160c1556f79..f214adfb3fa4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -797,10 +797,7 @@ static int __buffer_migrate_page(struct address_space *mapping,
 	if (rc != MIGRATEPAGE_SUCCESS)
 		goto unlock_buffers;
 
-	ClearPagePrivate(page);
-	set_page_private(newpage, page_private(page));
-	set_page_private(page, 0);
-	put_page(page);
+	set_page_private(newpage, detach_page_private(page));
 	get_page(newpage);
 
 	bh = head;
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-07 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com>
2020-05-07 21:43 ` [RFC PATCH V3 01/10] include/linux/pagemap.h: introduce attach/detach_page_private Guoqing Jiang
2020-05-07 21:44 ` [RFC PATCH V3 10/10] mm/migrate.c: call detach_page_private to cleanup code Guoqing Jiang

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).