diff mbox series

[1/7] mm/hugetlb: add folio support to hugetlb specific flag macros

Message ID 20220829230014.384722-2-sidhartha.kumar@oracle.com (mailing list archive)
State New
Headers show
Series begin converting hugetlb code to folios | expand

Commit Message

Sidhartha Kumar Aug. 29, 2022, 11 p.m. UTC
Allows the macros which test, set, and clear hugetlb specific page
flags to take a hugetlb folio as an input. The marcros are generated as
folio_{test, set, clear}_hugetlb_{restore_reserve, migratable,
temporary, freed, vmemmap_optimized, raw_hwp_unreliable}.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
 include/linux/hugetlb.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Matthew Wilcox Aug. 30, 2022, 3:33 a.m. UTC | #1
On Mon, Aug 29, 2022 at 04:00:08PM -0700, Sidhartha Kumar wrote:
>  #define TESTHPAGEFLAG(uname, flname)				\
> +static __always_inline								\
> +int folio_test_hugetlb_##flname(struct folio *folio)		\

One change I made was to have folio_test_foo() return bool instead of
int.  It helps the compiler really understand what's going on.  Maybe
some humans too ;-)

> +	{	void **private = &folio->private;		\
> +		return test_bit(HPG_##flname, (void *)((unsigned long)private));	\

I've made this tricky for you by making folio->private a void * instead
of the unsigned long in page.  Would this look better as ...

	{							\
		void *private = &folio->private;		\
		return test_bit(HPG_##flname, private);		\

perhaps?
Sidhartha Kumar Aug. 30, 2022, 6:09 p.m. UTC | #2
On 8/29/22 8:33 PM, Matthew Wilcox wrote:
> On Mon, Aug 29, 2022 at 04:00:08PM -0700, Sidhartha Kumar wrote:
>>   #define TESTHPAGEFLAG(uname, flname)				\
>> +static __always_inline								\
>> +int folio_test_hugetlb_##flname(struct folio *folio)		\
> One change I made was to have folio_test_foo() return bool instead of
> int.  It helps the compiler really understand what's going on.  Maybe
> some humans too ;-)
>

I went with returning an int to stay consistent with the page version
of the macros which return an int. I'm fine with changing it to return
a bool.

>> +	{	void **private = &folio->private;		\
>> +		return test_bit(HPG_##flname, (void *)((unsigned long)private));	\
> I've made this tricky for you by making folio->private a void * instead
> of the unsigned long in page.  Would this look better as ...
>
> 	{							\
> 		void *private = &folio->private;		\
> 		return test_bit(HPG_##flname, private);		\
>
> perhaps?

Ya this looks much better and passes the tests, will add to v2.
Mike Kravetz Sept. 1, 2022, 4:55 p.m. UTC | #3
On 08/30/22 11:09, Sidhartha Kumar wrote:
> 
> 
> On 8/29/22 8:33 PM, Matthew Wilcox wrote:
> > On Mon, Aug 29, 2022 at 04:00:08PM -0700, Sidhartha Kumar wrote:
> > >   #define TESTHPAGEFLAG(uname, flname)				\
> > > +static __always_inline								\
> > > +int folio_test_hugetlb_##flname(struct folio *folio)		\
> > One change I made was to have folio_test_foo() return bool instead of
> > int.  It helps the compiler really understand what's going on.  Maybe
> > some humans too ;-)
> > 
> 
> I went with returning an int to stay consistent with the page version
> of the macros which return an int. I'm fine with changing it to return
> a bool.

I believe the page test macros returned an int when I added the hugetlb
specific versions.  So, I just did the same.  Since they are now bool,
it makes sense to have these be consistent.
diff mbox series

Patch

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index acace1a25226..ac4e98edd5b0 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -583,26 +583,47 @@  enum hugetlb_page_flags {
  */
 #ifdef CONFIG_HUGETLB_PAGE
 #define TESTHPAGEFLAG(uname, flname)				\
+static __always_inline								\
+int folio_test_hugetlb_##flname(struct folio *folio)		\
+	{	void **private = &folio->private;		\
+		return test_bit(HPG_##flname, (void *)((unsigned long)private));	\
+	}	\
 static inline int HPage##uname(struct page *page)		\
 	{ return test_bit(HPG_##flname, &(page->private)); }
 
 #define SETHPAGEFLAG(uname, flname)				\
+static __always_inline							\
+void folio_set_hugetlb_##flname(struct folio *folio)		\
+	{	void **private = &folio->private;		\
+		set_bit(HPG_##flname, (void *)((unsigned long)private));		\
+	}	\
 static inline void SetHPage##uname(struct page *page)		\
 	{ set_bit(HPG_##flname, &(page->private)); }
 
 #define CLEARHPAGEFLAG(uname, flname)				\
+static __always_inline								\
+void folio_clear_hugetlb_##flname(struct folio *folio)		\
+	{	void **private = &folio->private;		\
+		clear_bit(HPG_##flname, (void *)((unsigned long)private));		\
+	}	\
 static inline void ClearHPage##uname(struct page *page)		\
 	{ clear_bit(HPG_##flname, &(page->private)); }
 #else
 #define TESTHPAGEFLAG(uname, flname)				\
+static inline int folio_test_hugetlb_##flname(struct folio *folio)		\
+	{ return 0; }										\
 static inline int HPage##uname(struct page *page)		\
 	{ return 0; }
 
 #define SETHPAGEFLAG(uname, flname)				\
+static inline void folio_set_hugetlb_##flname(struct folio *folio)		\
+	{ }		                                                \
 static inline void SetHPage##uname(struct page *page)		\
 	{ }
 
 #define CLEARHPAGEFLAG(uname, flname)				\
+static inline void folio_clear_hugetlb_##flname(struct folio *folio)	\
+	{ }		                                                \
 static inline void ClearHPage##uname(struct page *page)		\
 	{ }
 #endif