linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
       [not found] <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com>
@ 2020-04-30 21:44 ` Guoqing Jiang
  2020-04-30 22:10   ` Andreas Grünbacher
  2020-04-30 22:13   ` Matthew Wilcox
  2020-04-30 21:44 ` [RFC PATCH V2 3/9] btrfs: use attach/clear_page_private Guoqing Jiang
  1 sibling, 2 replies; 9+ messages in thread
From: Guoqing Jiang @ 2020-04-30 21:44 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: hch, david, willy, Guoqing Jiang, Andrew Morton, 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/clear_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 the new names from
Christoph Hellwig.

Suggested-by: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.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 -> 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 | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a8f7bd8ea1c6..2e515f210b18 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count)
 	return __page_cache_add_speculative(page, count);
 }
 
+/**
+ * attach_page_private - attach data to page's private field and set PG_private.
+ * @page: page to be attached and set flag.
+ * @data: data to attach to page's private field.
+ *
+ * Need to take reference as mm.h said "Setting PG_private should also increment
+ * the refcount".
+ */
+static inline void attach_page_private(struct page *page, void *data)
+{
+	get_page(page);
+	set_page_private(page, (unsigned long)data);
+	SetPagePrivate(page);
+}
+
+/**
+ * clear_page_private - clear page's private field and PG_private.
+ * @page: page to be cleared.
+ *
+ * The counterpart function of attach_page_private.
+ * Return: private data of page or NULL if page doesn't have private data.
+ */
+static inline void *clear_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] 9+ messages in thread

* [RFC PATCH V2 3/9] btrfs: use attach/clear_page_private
       [not found] <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com>
  2020-04-30 21:44 ` [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Guoqing Jiang
@ 2020-04-30 21:44 ` Guoqing Jiang
  1 sibling, 0 replies; 9+ messages in thread
From: Guoqing Jiang @ 2020-04-30 21:44 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: hch, david, willy, Guoqing Jiang, Chris Mason, Josef Bacik,
	David Sterba, linux-btrfs

Since the new pair function is introduced, we can call them to clean the
code in btrfs.

Cc: Chris Mason <clm@fb.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
---
RFC -> RFC V2
1. change the name of new functions to attach/clear_page_private.
2. call attach_page_private(newpage, clear_page_private(page)) to
   cleanup code further as suggested by Dave Chinner.

 fs/btrfs/disk-io.c   |  4 +---
 fs/btrfs/extent_io.c | 21 ++++++---------------
 fs/btrfs/inode.c     | 23 +++++------------------
 3 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a6cb5cbbdb9f..fe4acf821110 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -980,9 +980,7 @@ static void btree_invalidatepage(struct page *page, unsigned int offset,
 		btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info,
 			   "page private not zero on page %llu",
 			   (unsigned long long)page_offset(page));
-		ClearPagePrivate(page);
-		set_page_private(page, 0);
-		put_page(page);
+		clear_page_private(page);
 	}
 }
 
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 39e45b8a5031..095a5e83e660 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3076,22 +3076,16 @@ static int submit_extent_page(unsigned int opf,
 static void attach_extent_buffer_page(struct extent_buffer *eb,
 				      struct page *page)
 {
-	if (!PagePrivate(page)) {
-		SetPagePrivate(page);
-		get_page(page);
-		set_page_private(page, (unsigned long)eb);
-	} else {
+	if (!PagePrivate(page))
+		attach_page_private(page, eb);
+	else
 		WARN_ON(page->private != (unsigned long)eb);
-	}
 }
 
 void set_page_extent_mapped(struct page *page)
 {
-	if (!PagePrivate(page)) {
-		SetPagePrivate(page);
-		get_page(page);
-		set_page_private(page, EXTENT_PAGE_PRIVATE);
-	}
+	if (!PagePrivate(page))
+		attach_page_private(page, (void *)EXTENT_PAGE_PRIVATE);
 }
 
 static struct extent_map *
@@ -4929,10 +4923,7 @@ static void btrfs_release_extent_buffer_pages(struct extent_buffer *eb)
 			 * We need to make sure we haven't be attached
 			 * to a new eb.
 			 */
-			ClearPagePrivate(page);
-			set_page_private(page, 0);
-			/* One for the page private */
-			put_page(page);
+			clear_page_private(page);
 		}
 
 		if (mapped)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 320d1062068d..34b09ab2c32a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8303,11 +8303,8 @@ btrfs_readpages(struct file *file, struct address_space *mapping,
 static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)
 {
 	int ret = try_release_extent_mapping(page, gfp_flags);
-	if (ret == 1) {
-		ClearPagePrivate(page);
-		set_page_private(page, 0);
-		put_page(page);
-	}
+	if (ret == 1)
+		clear_page_private(page);
 	return ret;
 }
 
@@ -8329,14 +8326,8 @@ static int btrfs_migratepage(struct address_space *mapping,
 	if (ret != MIGRATEPAGE_SUCCESS)
 		return ret;
 
-	if (page_has_private(page)) {
-		ClearPagePrivate(page);
-		get_page(newpage);
-		set_page_private(newpage, page_private(page));
-		set_page_private(page, 0);
-		put_page(page);
-		SetPagePrivate(newpage);
-	}
+	if (page_has_private(page))
+		attach_page_private(newpage, clear_page_private(page));
 
 	if (PagePrivate2(page)) {
 		ClearPagePrivate2(page);
@@ -8458,11 +8449,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
 	}
 
 	ClearPageChecked(page);
-	if (PagePrivate(page)) {
-		ClearPagePrivate(page);
-		set_page_private(page, 0);
-		put_page(page);
-	}
+	clear_page_private(page);
 }
 
 /*
-- 
2.17.1


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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-04-30 21:44 ` [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Guoqing Jiang
@ 2020-04-30 22:10   ` Andreas Grünbacher
  2020-05-01  6:38     ` Guoqing Jiang
  2020-04-30 22:13   ` Matthew Wilcox
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Grünbacher @ 2020-04-30 22:10 UTC (permalink / raw)
  To: Guoqing Jiang
  Cc: Linux FS-devel Mailing List, Linux Kernel Mailing List,
	Christoph Hellwig, Dave Chinner, willy, Andrew Morton,
	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

Hi,

Am Do., 30. Apr. 2020 um 23:56 Uhr schrieb Guoqing Jiang
<guoqing.jiang@cloud.ionos.com>:
> 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/clear_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 the new names from
> Christoph Hellwig.
>
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Cc: Andrew Morton <akpm@linux-foundation.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 -> 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 | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index a8f7bd8ea1c6..2e515f210b18 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count)
>         return __page_cache_add_speculative(page, count);
>  }
>
> +/**
> + * attach_page_private - attach data to page's private field and set PG_private.
> + * @page: page to be attached and set flag.
> + * @data: data to attach to page's private field.
> + *
> + * Need to take reference as mm.h said "Setting PG_private should also increment
> + * the refcount".
> + */
> +static inline void attach_page_private(struct page *page, void *data)
> +{
> +       get_page(page);
> +       set_page_private(page, (unsigned long)data);
> +       SetPagePrivate(page);
> +}
> +
> +/**
> + * clear_page_private - clear page's private field and PG_private.
> + * @page: page to be cleared.
> + *
> + * The counterpart function of attach_page_private.
> + * Return: private data of page or NULL if page doesn't have private data.
> + */
> +static inline void *clear_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;
> +}
> +

I like this in general, but the name clear_page_private suggests that
this might be the inverse operation of set_page_private, which it is
not. So maybe this can be renamed to detach_page_private to more
clearly indicate that it pairs with attach_page_private?

>  #ifdef CONFIG_NUMA
>  extern struct page *__page_cache_alloc(gfp_t gfp);
>  #else
> --
> 2.17.1
>

Thanks,
Andreas

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-04-30 21:44 ` [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Guoqing Jiang
  2020-04-30 22:10   ` Andreas Grünbacher
@ 2020-04-30 22:13   ` Matthew Wilcox
  2020-05-01  1:42     ` Al Viro
  2020-05-01  6:39     ` Guoqing Jiang
  1 sibling, 2 replies; 9+ messages in thread
From: Matthew Wilcox @ 2020-04-30 22:13 UTC (permalink / raw)
  To: Guoqing Jiang
  Cc: linux-fsdevel, linux-kernel, hch, david, Andrew Morton,
	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

On Thu, Apr 30, 2020 at 11:44:42PM +0200, Guoqing Jiang wrote:
> +/**
> + * attach_page_private - attach data to page's private field and set PG_private.
> + * @page: page to be attached and set flag.
> + * @data: data to attach to page's private field.
> + *
> + * Need to take reference as mm.h said "Setting PG_private should also increment
> + * the refcount".
> + */

I don't think this will read well when added to the API documentation.
Try this:

/**
 * 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.
 */

> +/**
> + * clear_page_private - clear page's private field and PG_private.
> + * @page: page to be cleared.
> + *
> + * The counterpart function of attach_page_private.
> + * Return: private data of page or NULL if page doesn't have private data.
> + */

Seems to me that the opposite of "attach" is "detach", not "clear".

/**
 * 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.
 */

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-04-30 22:13   ` Matthew Wilcox
@ 2020-05-01  1:42     ` Al Viro
  2020-05-01  1:49       ` Al Viro
  2020-05-01  6:39     ` Guoqing Jiang
  1 sibling, 1 reply; 9+ messages in thread
From: Al Viro @ 2020-05-01  1:42 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Guoqing Jiang, linux-fsdevel, linux-kernel, hch, david,
	Andrew Morton, 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, 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

On Thu, Apr 30, 2020 at 03:13:38PM -0700, Matthew Wilcox wrote:

> > +/**
> > + * clear_page_private - clear page's private field and PG_private.
> > + * @page: page to be cleared.
> > + *
> > + * The counterpart function of attach_page_private.
> > + * Return: private data of page or NULL if page doesn't have private data.
> > + */
> 
> Seems to me that the opposite of "attach" is "detach", not "clear".

Or "remove", perhaps...

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-05-01  1:42     ` Al Viro
@ 2020-05-01  1:49       ` Al Viro
  2020-05-01  6:41         ` Guoqing Jiang
  0 siblings, 1 reply; 9+ messages in thread
From: Al Viro @ 2020-05-01  1:49 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Guoqing Jiang, linux-fsdevel, linux-kernel, hch, david,
	Andrew Morton, 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, 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

On Fri, May 01, 2020 at 02:42:29AM +0100, Al Viro wrote:
> On Thu, Apr 30, 2020 at 03:13:38PM -0700, Matthew Wilcox wrote:
> 
> > > +/**
> > > + * clear_page_private - clear page's private field and PG_private.
> > > + * @page: page to be cleared.
> > > + *
> > > + * The counterpart function of attach_page_private.
> > > + * Return: private data of page or NULL if page doesn't have private data.
> > > + */
> > 
> > Seems to me that the opposite of "attach" is "detach", not "clear".
> 
> Or "remove", perhaps...

Actually, "detach" is better - neither "clear" nor "remove" imply "... and give
me what used to be attached there", as this thing is doing.

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-04-30 22:10   ` Andreas Grünbacher
@ 2020-05-01  6:38     ` Guoqing Jiang
  0 siblings, 0 replies; 9+ messages in thread
From: Guoqing Jiang @ 2020-05-01  6:38 UTC (permalink / raw)
  To: Andreas Grünbacher
  Cc: Linux FS-devel Mailing List, Linux Kernel Mailing List,
	Christoph Hellwig, Dave Chinner, willy, Andrew Morton,
	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

On 5/1/20 12:10 AM, Andreas Grünbacher wrote:
> Hi,
>
> Am Do., 30. Apr. 2020 um 23:56 Uhr schrieb Guoqing Jiang
> <guoqing.jiang@cloud.ionos.com>:
>> 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/clear_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 the new names from
>> Christoph Hellwig.
>>
>> Suggested-by: Matthew Wilcox <willy@infradead.org>
>> Cc: Andrew Morton <akpm@linux-foundation.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 -> 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 | 35 +++++++++++++++++++++++++++++++++++
>>   1 file changed, 35 insertions(+)
>>
>> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
>> index a8f7bd8ea1c6..2e515f210b18 100644
>> --- a/include/linux/pagemap.h
>> +++ b/include/linux/pagemap.h
>> @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count)
>>          return __page_cache_add_speculative(page, count);
>>   }
>>
>> +/**
>> + * attach_page_private - attach data to page's private field and set PG_private.
>> + * @page: page to be attached and set flag.
>> + * @data: data to attach to page's private field.
>> + *
>> + * Need to take reference as mm.h said "Setting PG_private should also increment
>> + * the refcount".
>> + */
>> +static inline void attach_page_private(struct page *page, void *data)
>> +{
>> +       get_page(page);
>> +       set_page_private(page, (unsigned long)data);
>> +       SetPagePrivate(page);
>> +}
>> +
>> +/**
>> + * clear_page_private - clear page's private field and PG_private.
>> + * @page: page to be cleared.
>> + *
>> + * The counterpart function of attach_page_private.
>> + * Return: private data of page or NULL if page doesn't have private data.
>> + */
>> +static inline void *clear_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;
>> +}
>> +
> I like this in general, but the name clear_page_private suggests that
> this might be the inverse operation of set_page_private, which it is
> not. So maybe this can be renamed to detach_page_private to more
> clearly indicate that it pairs with attach_page_private?

Yes, the new name is better, thank you!

Cheers,
Guoqing

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-04-30 22:13   ` Matthew Wilcox
  2020-05-01  1:42     ` Al Viro
@ 2020-05-01  6:39     ` Guoqing Jiang
  1 sibling, 0 replies; 9+ messages in thread
From: Guoqing Jiang @ 2020-05-01  6:39 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-fsdevel, linux-kernel, hch, david, Andrew Morton,
	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

On 5/1/20 12:13 AM, Matthew Wilcox wrote:
> On Thu, Apr 30, 2020 at 11:44:42PM +0200, Guoqing Jiang wrote:
>> +/**
>> + * attach_page_private - attach data to page's private field and set PG_private.
>> + * @page: page to be attached and set flag.
>> + * @data: data to attach to page's private field.
>> + *
>> + * Need to take reference as mm.h said "Setting PG_private should also increment
>> + * the refcount".
>> + */
> I don't think this will read well when added to the API documentation.
> Try this:
>
> /**
>   * 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.
>   */
>
>> +/**
>> + * clear_page_private - clear page's private field and PG_private.
>> + * @page: page to be cleared.
>> + *
>> + * The counterpart function of attach_page_private.
>> + * Return: private data of page or NULL if page doesn't have private data.
>> + */
> Seems to me that the opposite of "attach" is "detach", not "clear".
>
> /**
>   * 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.
>   */

Thanks you very much, Mattew! Will change them in next version.

Best Regards,
Guoqing

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

* Re: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private
  2020-05-01  1:49       ` Al Viro
@ 2020-05-01  6:41         ` Guoqing Jiang
  0 siblings, 0 replies; 9+ messages in thread
From: Guoqing Jiang @ 2020-05-01  6:41 UTC (permalink / raw)
  To: Al Viro, Matthew Wilcox
  Cc: linux-fsdevel, linux-kernel, hch, david, Andrew Morton,
	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, 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

On 5/1/20 3:49 AM, Al Viro wrote:
> On Fri, May 01, 2020 at 02:42:29AM +0100, Al Viro wrote:
>> On Thu, Apr 30, 2020 at 03:13:38PM -0700, Matthew Wilcox wrote:
>>
>>>> +/**
>>>> + * clear_page_private - clear page's private field and PG_private.
>>>> + * @page: page to be cleared.
>>>> + *
>>>> + * The counterpart function of attach_page_private.
>>>> + * Return: private data of page or NULL if page doesn't have private data.
>>>> + */
>>> Seems to me that the opposite of "attach" is "detach", not "clear".
>> Or "remove", perhaps...
> Actually, "detach" is better - neither "clear" nor "remove" imply "... and give
> me what used to be attached there", as this thing is doing.

Ok, seems we have reached the agreement about the new name ;-), will 
follow the instruction.

Thanks & Regards,
Guoqing

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

end of thread, other threads:[~2020-05-01  6:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com>
2020-04-30 21:44 ` [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Guoqing Jiang
2020-04-30 22:10   ` Andreas Grünbacher
2020-05-01  6:38     ` Guoqing Jiang
2020-04-30 22:13   ` Matthew Wilcox
2020-05-01  1:42     ` Al Viro
2020-05-01  1:49       ` Al Viro
2020-05-01  6:41         ` Guoqing Jiang
2020-05-01  6:39     ` Guoqing Jiang
2020-04-30 21:44 ` [RFC PATCH V2 3/9] btrfs: use attach/clear_page_private 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).