diff mbox series

[RFC,6/9] iomap: use set/clear_fs_page_private

Message ID 20200426214925.10970-7-guoqing.jiang@cloud.ionos.com (mailing list archive)
State New, archived
Headers show
Series Introduce set/clear_fs_page_private to cleanup code | expand

Commit Message

Guoqing Jiang April 26, 2020, 9:49 p.m. UTC
Since the new pair function is introduced, we can call them to clean the
code in iomap.

Cc: Christoph Hellwig <hch@infradead.org>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
---
 fs/iomap/buffered-io.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Matthew Wilcox April 27, 2020, 12:26 a.m. UTC | #1
On Sun, Apr 26, 2020 at 11:49:22PM +0200, Guoqing Jiang wrote:
> @@ -59,24 +59,18 @@ iomap_page_create(struct inode *inode, struct page *page)
>  	 * migrate_page_move_mapping() assumes that pages with private data have
>  	 * their count elevated by 1.
>  	 */
> -	get_page(page);
> -	set_page_private(page, (unsigned long)iop);
> -	SetPagePrivate(page);
> -	return iop;
> +	return (struct iomap_page *)set_fs_page_private(page, iop);
>  }

This cast is unnecessary.  void * will be automatically cast to the
appropriate pointer type.

> @@ -556,11 +550,9 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,
>  
>  	if (page_has_private(page)) {
>  		ClearPagePrivate(page);
> -		get_page(newpage);
> -		set_page_private(newpage, page_private(page));
> +		set_fs_page_private(newpage, (void *)page_private(page));
>  		set_page_private(page, 0);
>  		put_page(page);
> -		SetPagePrivate(newpage);
>  	}

Same comment here as for the btrfs migrate page that Dave reviewed.
Christoph Hellwig April 27, 2020, 5:55 a.m. UTC | #2
On Sun, Apr 26, 2020 at 05:26:31PM -0700, Matthew Wilcox wrote:
> On Sun, Apr 26, 2020 at 11:49:22PM +0200, Guoqing Jiang wrote:
> > @@ -59,24 +59,18 @@ iomap_page_create(struct inode *inode, struct page *page)
> >  	 * migrate_page_move_mapping() assumes that pages with private data have
> >  	 * their count elevated by 1.
> >  	 */
> > -	get_page(page);
> > -	set_page_private(page, (unsigned long)iop);
> > -	SetPagePrivate(page);
> > -	return iop;
> > +	return (struct iomap_page *)set_fs_page_private(page, iop);
> >  }
> 
> This cast is unnecessary.  void * will be automatically cast to the
> appropriate pointer type.

I also find the pattern eather strange.  A:

	attach_page_private(page, iop);
	return iop;

explains the intent much better.
Christoph Hellwig April 27, 2020, 5:57 a.m. UTC | #3
FYI, you've only Cced the xfs list on this one patch.  Please Cc the
whole list to everyone, otherwise a person just on the xfs list has
no idea what your helpers added in patch 1 actually do.
Guoqing Jiang April 27, 2020, 8:12 a.m. UTC | #4
On 4/27/20 7:57 AM, Christoph Hellwig wrote:
> FYI, you've only Cced the xfs list on this one patch.  Please Cc the
> whole list to everyone, otherwise a person just on the xfs list has
> no idea what your helpers added in patch 1 actually do.

Sorry, I should cc more lists for patch 1, thanks for reminder!

Thanks,
Guoqing
Guoqing Jiang April 27, 2020, 8:15 a.m. UTC | #5
On 4/27/20 7:55 AM, Christoph Hellwig wrote:
> On Sun, Apr 26, 2020 at 05:26:31PM -0700, Matthew Wilcox wrote:
>> On Sun, Apr 26, 2020 at 11:49:22PM +0200, Guoqing Jiang wrote:
>>> @@ -59,24 +59,18 @@ iomap_page_create(struct inode *inode, struct page *page)
>>>   	 * migrate_page_move_mapping() assumes that pages with private data have
>>>   	 * their count elevated by 1.
>>>   	 */
>>> -	get_page(page);
>>> -	set_page_private(page, (unsigned long)iop);
>>> -	SetPagePrivate(page);
>>> -	return iop;
>>> +	return (struct iomap_page *)set_fs_page_private(page, iop);
>>>   }
>> This cast is unnecessary.  void * will be automatically cast to the
>> appropriate pointer type.
> I also find the pattern eather strange.  A:
>
> 	attach_page_private(page, iop);
> 	return iop;
>
> explains the intent much better.

Thanks for the review, will do it.

Thanks,
Guoqing
Guoqing Jiang April 27, 2020, 8:15 a.m. UTC | #6
On 4/27/20 2:26 AM, Matthew Wilcox wrote:
> On Sun, Apr 26, 2020 at 11:49:22PM +0200, Guoqing Jiang wrote:
>> @@ -59,24 +59,18 @@ iomap_page_create(struct inode *inode, struct page *page)
>>   	 * migrate_page_move_mapping() assumes that pages with private data have
>>   	 * their count elevated by 1.
>>   	 */
>> -	get_page(page);
>> -	set_page_private(page, (unsigned long)iop);
>> -	SetPagePrivate(page);
>> -	return iop;
>> +	return (struct iomap_page *)set_fs_page_private(page, iop);
>>   }
> This cast is unnecessary.  void * will be automatically cast to the
> appropriate pointer type.
>
>> @@ -556,11 +550,9 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,
>>   
>>   	if (page_has_private(page)) {
>>   		ClearPagePrivate(page);
>> -		get_page(newpage);
>> -		set_page_private(newpage, page_private(page));
>> +		set_fs_page_private(newpage, (void *)page_private(page));
>>   		set_page_private(page, 0);
>>   		put_page(page);
>> -		SetPagePrivate(newpage);
>>   	}
> Same comment here as for the btrfs migrate page that Dave reviewed.

Yes, thanks for the review.

Thanks,
Guoqing
diff mbox series

Patch

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 89e21961d1ad..cc48bf4f1193 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -59,24 +59,18 @@  iomap_page_create(struct inode *inode, struct page *page)
 	 * migrate_page_move_mapping() assumes that pages with private data have
 	 * their count elevated by 1.
 	 */
-	get_page(page);
-	set_page_private(page, (unsigned long)iop);
-	SetPagePrivate(page);
-	return iop;
+	return (struct iomap_page *)set_fs_page_private(page, iop);
 }
 
 static void
 iomap_page_release(struct page *page)
 {
-	struct iomap_page *iop = to_iomap_page(page);
+	struct iomap_page *iop = clear_fs_page_private(page);
 
 	if (!iop)
 		return;
 	WARN_ON_ONCE(atomic_read(&iop->read_count));
 	WARN_ON_ONCE(atomic_read(&iop->write_count));
-	ClearPagePrivate(page);
-	set_page_private(page, 0);
-	put_page(page);
 	kfree(iop);
 }
 
@@ -556,11 +550,9 @@  iomap_migrate_page(struct address_space *mapping, struct page *newpage,
 
 	if (page_has_private(page)) {
 		ClearPagePrivate(page);
-		get_page(newpage);
-		set_page_private(newpage, page_private(page));
+		set_fs_page_private(newpage, (void *)page_private(page));
 		set_page_private(page, 0);
 		put_page(page);
-		SetPagePrivate(newpage);
 	}
 
 	if (mode != MIGRATE_SYNC_NO_COPY)