linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: change the type to bool for page_has_xxx's val
@ 2022-09-15  2:56 zhaoyang.huang
  2022-09-15 21:45 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: zhaoyang.huang @ 2022-09-15  2:56 UTC (permalink / raw)
  To: Andrew Morton, Zhaoyang Huang, linux-mm, linux-kernel, ke.wang

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

It is proper to return bool value for such functions

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 include/linux/page-flags.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index e66f7aa..9a46c8b 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -946,9 +946,9 @@ static inline bool is_page_hwpoison(struct page *page)
 #define PageType(page, flag)						\
 	((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
 
-static inline int page_has_type(struct page *page)
+static inline bool page_has_type(struct page *page)
 {
-	return (int)page->page_type < PAGE_MAPCOUNT_RESERVE;
+	return !!((int)page->page_type < PAGE_MAPCOUNT_RESERVE);
 }
 
 #define PAGE_TYPE_OPS(uname, lname)					\
@@ -1081,7 +1081,7 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page)
  * Determine if a page has private stuff, indicating that release routines
  * should be invoked upon it.
  */
-static inline int page_has_private(struct page *page)
+static inline bool page_has_private(struct page *page)
 {
 	return !!(page->flags & PAGE_FLAGS_PRIVATE);
 }
-- 
1.9.1



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

* Re: [PATCH] mm: change the type to bool for page_has_xxx's val
  2022-09-15  2:56 [PATCH] mm: change the type to bool for page_has_xxx's val zhaoyang.huang
@ 2022-09-15 21:45 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-09-15 21:45 UTC (permalink / raw)
  To: zhaoyang.huang; +Cc: Zhaoyang Huang, linux-mm, linux-kernel, ke.wang

On Thu, 15 Sep 2022 10:56:40 +0800 "zhaoyang.huang" <zhaoyang.huang@unisoc.com> wrote:

> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> 
> It is proper to return bool value for such functions
> 
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  include/linux/page-flags.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index e66f7aa..9a46c8b 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -946,9 +946,9 @@ static inline bool is_page_hwpoison(struct page *page)
>  #define PageType(page, flag)						\
>  	((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
>  
> -static inline int page_has_type(struct page *page)
> +static inline bool page_has_type(struct page *page)
>  {
> -	return (int)page->page_type < PAGE_MAPCOUNT_RESERVE;
> +	return !!((int)page->page_type < PAGE_MAPCOUNT_RESERVE);

Much nicer to simply do this:

	return page->page_type < PAGE_MAPCOUNT_RESERVE;

>  }
>  
>  #define PAGE_TYPE_OPS(uname, lname)					\
> @@ -1081,7 +1081,7 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page)
>   * Determine if a page has private stuff, indicating that release routines
>   * should be invoked upon it.
>   */
> -static inline int page_has_private(struct page *page)
> +static inline bool page_has_private(struct page *page)
>  {
>  	return !!(page->flags & PAGE_FLAGS_PRIVATE);
>  }

Maybe.  This might cause the compiler to emit more code, to convert the
integer to a bool having value 0 or 1.  It would do so if the code was
uninlined.

But given that it's inlined, the compiler hopefully has the brains to
avoid doing that and to test the integer directly.  Please check this -
the above change shouldn't increase the .o file's text section size.



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

end of thread, other threads:[~2022-09-15 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15  2:56 [PATCH] mm: change the type to bool for page_has_xxx's val zhaoyang.huang
2022-09-15 21:45 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox