[2/2] f2fs: clean up with {attach,detach}_page_private()

Message ID 20230410022418.1843178-2-chao@kernel.org
State New
Headers
Series [1/2] f2fs: remove folio_detach_private() in .invalidate_folio and .release_folio |

Commit Message

Chao Yu April 10, 2023, 2:24 a.m. UTC
  No logic changes.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/f2fs.h | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)
  

Comments

Jaegeuk Kim April 10, 2023, 6:47 p.m. UTC | #1
On 04/10, Chao Yu wrote:
> No logic changes.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>  fs/f2fs/f2fs.h | 32 ++++++++------------------------
>  1 file changed, 8 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index ec8387da7f74..c378aedcadea 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1416,11 +1416,8 @@ static inline bool page_private_##name(struct page *page) \
>  #define PAGE_PRIVATE_SET_FUNC(name, flagname) \
>  static inline void set_page_private_##name(struct page *page) \
>  { \
> -	if (!PagePrivate(page)) { \
> -		get_page(page); \
> -		SetPagePrivate(page); \
> -		set_page_private(page, 0); \
> -	} \
> +	if (!PagePrivate(page)) \
> +		attach_page_private(page, (void *)page->private); \

		attach_page_private(page, (void *)0);

>  	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \
>  	set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
>  }
> @@ -1429,13 +1426,8 @@ static inline void set_page_private_##name(struct page *page) \
>  static inline void clear_page_private_##name(struct page *page) \
>  { \
>  	clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
> -	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) { \
> -		set_page_private(page, 0); \
> -		if (PagePrivate(page)) { \
> -			ClearPagePrivate(page); \
> -			put_page(page); \
> -		}\
> -	} \
> +	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) \
> +		detach_page_private(page); \
>  }
>  
>  PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
> @@ -1464,11 +1456,8 @@ static inline unsigned long get_page_private_data(struct page *page)
>  
>  static inline void set_page_private_data(struct page *page, unsigned long data)
>  {
> -	if (!PagePrivate(page)) {
> -		get_page(page);
> -		SetPagePrivate(page);
> -		set_page_private(page, 0);
> -	}
> +	if (!PagePrivate(page))
> +		attach_page_private(page, 0);
>  	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page));
>  	page_private(page) |= data << PAGE_PRIVATE_MAX;
>  }
> @@ -1476,13 +1465,8 @@ static inline void set_page_private_data(struct page *page, unsigned long data)
>  static inline void clear_page_private_data(struct page *page)
>  {
>  	page_private(page) &= GENMASK(PAGE_PRIVATE_MAX - 1, 0);
> -	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) {
> -		set_page_private(page, 0);
> -		if (PagePrivate(page)) {
> -			ClearPagePrivate(page);
> -			put_page(page);
> -		}
> -	}
> +	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER))
> +		detach_page_private(page);
>  }
>  
>  /* For compression */
> -- 
> 2.25.1
  
Chao Yu April 11, 2023, 8:37 a.m. UTC | #2
On 2023/4/11 2:47, Jaegeuk Kim wrote:
> On 04/10, Chao Yu wrote:
>> No logic changes.
>>
>> Signed-off-by: Chao Yu <chao@kernel.org>
>> ---
>>   fs/f2fs/f2fs.h | 32 ++++++++------------------------
>>   1 file changed, 8 insertions(+), 24 deletions(-)
>>
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index ec8387da7f74..c378aedcadea 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -1416,11 +1416,8 @@ static inline bool page_private_##name(struct page *page) \
>>   #define PAGE_PRIVATE_SET_FUNC(name, flagname) \
>>   static inline void set_page_private_##name(struct page *page) \
>>   { \
>> -	if (!PagePrivate(page)) { \
>> -		get_page(page); \
>> -		SetPagePrivate(page); \
>> -		set_page_private(page, 0); \
>> -	} \
>> +	if (!PagePrivate(page)) \
>> +		attach_page_private(page, (void *)page->private); \
> 
> 		attach_page_private(page, (void *)0);

Correct, thanks for fixing this.

Thanks,

> 
>>   	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \
>>   	set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
>>   }
>> @@ -1429,13 +1426,8 @@ static inline void set_page_private_##name(struct page *page) \
>>   static inline void clear_page_private_##name(struct page *page) \
>>   { \
>>   	clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
>> -	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) { \
>> -		set_page_private(page, 0); \
>> -		if (PagePrivate(page)) { \
>> -			ClearPagePrivate(page); \
>> -			put_page(page); \
>> -		}\
>> -	} \
>> +	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) \
>> +		detach_page_private(page); \
>>   }
>>   
>>   PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
>> @@ -1464,11 +1456,8 @@ static inline unsigned long get_page_private_data(struct page *page)
>>   
>>   static inline void set_page_private_data(struct page *page, unsigned long data)
>>   {
>> -	if (!PagePrivate(page)) {
>> -		get_page(page);
>> -		SetPagePrivate(page);
>> -		set_page_private(page, 0);
>> -	}
>> +	if (!PagePrivate(page))
>> +		attach_page_private(page, 0);
>>   	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page));
>>   	page_private(page) |= data << PAGE_PRIVATE_MAX;
>>   }
>> @@ -1476,13 +1465,8 @@ static inline void set_page_private_data(struct page *page, unsigned long data)
>>   static inline void clear_page_private_data(struct page *page)
>>   {
>>   	page_private(page) &= GENMASK(PAGE_PRIVATE_MAX - 1, 0);
>> -	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) {
>> -		set_page_private(page, 0);
>> -		if (PagePrivate(page)) {
>> -			ClearPagePrivate(page);
>> -			put_page(page);
>> -		}
>> -	}
>> +	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER))
>> +		detach_page_private(page);
>>   }
>>   
>>   /* For compression */
>> -- 
>> 2.25.1
  

Patch

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index ec8387da7f74..c378aedcadea 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1416,11 +1416,8 @@  static inline bool page_private_##name(struct page *page) \
 #define PAGE_PRIVATE_SET_FUNC(name, flagname) \
 static inline void set_page_private_##name(struct page *page) \
 { \
-	if (!PagePrivate(page)) { \
-		get_page(page); \
-		SetPagePrivate(page); \
-		set_page_private(page, 0); \
-	} \
+	if (!PagePrivate(page)) \
+		attach_page_private(page, (void *)page->private); \
 	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \
 	set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
 }
@@ -1429,13 +1426,8 @@  static inline void set_page_private_##name(struct page *page) \
 static inline void clear_page_private_##name(struct page *page) \
 { \
 	clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
-	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) { \
-		set_page_private(page, 0); \
-		if (PagePrivate(page)) { \
-			ClearPagePrivate(page); \
-			put_page(page); \
-		}\
-	} \
+	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) \
+		detach_page_private(page); \
 }
 
 PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
@@ -1464,11 +1456,8 @@  static inline unsigned long get_page_private_data(struct page *page)
 
 static inline void set_page_private_data(struct page *page, unsigned long data)
 {
-	if (!PagePrivate(page)) {
-		get_page(page);
-		SetPagePrivate(page);
-		set_page_private(page, 0);
-	}
+	if (!PagePrivate(page))
+		attach_page_private(page, 0);
 	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page));
 	page_private(page) |= data << PAGE_PRIVATE_MAX;
 }
@@ -1476,13 +1465,8 @@  static inline void set_page_private_data(struct page *page, unsigned long data)
 static inline void clear_page_private_data(struct page *page)
 {
 	page_private(page) &= GENMASK(PAGE_PRIVATE_MAX - 1, 0);
-	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER)) {
-		set_page_private(page, 0);
-		if (PagePrivate(page)) {
-			ClearPagePrivate(page);
-			put_page(page);
-		}
-	}
+	if (page_private(page) == BIT(PAGE_PRIVATE_NOT_POINTER))
+		detach_page_private(page);
 }
 
 /* For compression */