On Tue, Jan 04, 2022 at 12:01:45AM -0800, Christoph Hellwig wrote: > On Sun, Jan 02, 2022 at 09:57:14PM +0000, Matthew Wilcox (Oracle) wrote: > > -static inline bool hpage_pincount_available(struct page *page) > > +static inline bool folio_pincount_available(struct folio *folio) > > { > > /* > > - * Can the page->hpage_pinned_refcount field be used? That field is in > > + * Can the folio->hpage_pinned_refcount field be used? That field is in > > * the 3rd page of the compound page, so the smallest (2-page) compound > > * pages cannot support it. > > */ > > + return folio_order(folio) > 1; > > +} > > Maybe convert the comment into a kerneldoc one? I'm actually thinking about getting rid of it by moving the hpage_pinned_refcount into page[1]: diff --git a/include/linux/mm.h b/include/linux/mm.h index 4e763a590c9c..07fa8af564ed 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -950,7 +950,9 @@ static inline int head_compound_pincount(struct page *head) static inline void set_compound_order(struct page *page, unsigned int order) { page[1].compound_order = order; +#ifdef CONFIG_64BIT page[1].compound_nr = 1U << order; +#endif } /* Returns the number of pages in this potentially compound page. */ @@ -958,7 +960,11 @@ static inline unsigned long compound_nr(struct page *page) { if (!PageHead(page)) return 1; +#ifdef CONFIG_64BIT return page[1].compound_nr; +#else + return 1UL << compound_order(page); +#endif } /* Returns the number of bytes in this potentially compound page. */ diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 09d9e2c4a2c5..e19af4a90a6c 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -150,11 +150,14 @@ struct page { unsigned char compound_dtor; unsigned char compound_order; atomic_t compound_mapcount; + atomic_t hpage_pinned_refcount; +#ifdef CONFIG_64BIT unsigned int compound_nr; /* 1 << compound_order */ +#endif }; struct { /* Second tail page of compound page */ unsigned long _compound_pad_1; /* compound_head */ - atomic_t hpage_pinned_refcount; + unsigned long _compound_pad_2; /* For both global and memcg */ struct list_head deferred_list; }; Now it's always available for every compound page.