Message ID | 20210409185105.188284-1-willy@infradead.org (mailing list archive) |
---|---|
Headers | show |
Series | Memory Folios | expand |
On Fri, Apr 09, 2021 at 07:50:39PM +0100, Matthew Wilcox (Oracle) wrote: > A struct folio is a new abstraction to replace the venerable struct page. > A function which takes a struct folio argument declares that it will > operate on the entire (possibly compound) page, not just PAGE_SIZE bytes. > In return, the caller guarantees that the pointer it is passing does > not point to a tail page. > +++ b/include/linux/mm_types.h [...] > +static inline struct folio *page_folio(struct page *page) > +{ > + unsigned long head = READ_ONCE(page->compound_head); > + > + if (unlikely(head & 1)) > + return (struct folio *)(head - 1); > + return (struct folio *)page; > +} I'm looking at changing this for the next revision, and basing it on my recent patch to make compound_head() const-preserving: +#define page_folio(page) _Generic((page), \ + const struct page *: (const struct folio *)_compound_head(page), \ + struct page *: (struct folio *)_compound_head(page)) I've also noticed an awkward pattern occurring that I think this makes less awkward: +/** + * folio_page - Return a page from a folio. + * @folio: The folio. + * @n: The page number to return. + * + * @n is relative to the start of the folio. It should be between + * 0 and folio_nr_pages(@folio) - 1, but this is not checked for. + */ +#define folio_page(folio, n) nth_page(&(folio)->page, n) That lets me simplify folio_next(): +static inline struct folio *folio_next(struct folio *folio) +{ + return (struct folio *)folio_page(folio, folio_nr_pages(folio)); +} (it occurs to me this should also be const-preserving, but it's not clear that's needed yet)
On Fri, Apr 16, 2021 at 04:55:16PM +0100, Matthew Wilcox wrote: > On Fri, Apr 09, 2021 at 07:50:39PM +0100, Matthew Wilcox (Oracle) wrote: > > A struct folio is a new abstraction to replace the venerable struct page. > > A function which takes a struct folio argument declares that it will > > operate on the entire (possibly compound) page, not just PAGE_SIZE bytes. > > In return, the caller guarantees that the pointer it is passing does > > not point to a tail page. > > +++ b/include/linux/mm_types.h > [...] > > +static inline struct folio *page_folio(struct page *page) > > +{ > > + unsigned long head = READ_ONCE(page->compound_head); > > + > > + if (unlikely(head & 1)) > > + return (struct folio *)(head - 1); > > + return (struct folio *)page; > > +} > > I'm looking at changing this for the next revision, and basing it on > my recent patch to make compound_head() const-preserving: > > +#define page_folio(page) _Generic((page), \ > + const struct page *: (const struct folio *)_compound_head(page), \ > + struct page *: (struct folio *)_compound_head(page)) > > I've also noticed an awkward pattern occurring that I think this makes > less awkward: > > +/** > + * folio_page - Return a page from a folio. > + * @folio: The folio. > + * @n: The page number to return. > + * > + * @n is relative to the start of the folio. It should be between > + * 0 and folio_nr_pages(@folio) - 1, but this is not checked for. > + */ > +#define folio_page(folio, n) nth_page(&(folio)->page, n) > > That lets me simplify folio_next(): > > +static inline struct folio *folio_next(struct folio *folio) > +{ > + return (struct folio *)folio_page(folio, folio_nr_pages(folio)); > +} > > (it occurs to me this should also be const-preserving, but it's not clear > that's needed yet) Are we risking that we would need to replace inline functions with macros all the way down? Not sure const-preserving worth it.
On Fri, Apr 09, 2021 at 07:50:46PM +0100, Matthew Wilcox (Oracle) wrote: > These new functions are the folio analogues of the PageFlags functions. > If CONFIG_DEBUG_VM_PGFLAGS is enabled, we check the folio is not a tail > page at every invocation. Note that this will also catch the PagePoisoned > case as a poisoned page has every bit set, which would include PageTail. > > This saves 1727 bytes of text with the distro-derived config that > I'm testing due to removing a double call to compound_head() in > PageSwapCache(). I vote for dropping the Camels if we're going to rework all this.
On Mon, Apr 19, 2021 at 03:25:46PM +0200, Peter Zijlstra wrote: > On Fri, Apr 09, 2021 at 07:50:46PM +0100, Matthew Wilcox (Oracle) wrote: > > These new functions are the folio analogues of the PageFlags functions. > > If CONFIG_DEBUG_VM_PGFLAGS is enabled, we check the folio is not a tail > > page at every invocation. Note that this will also catch the PagePoisoned > > case as a poisoned page has every bit set, which would include PageTail. > > > > This saves 1727 bytes of text with the distro-derived config that > > I'm testing due to removing a double call to compound_head() in > > PageSwapCache(). > > I vote for dropping the Camels if we're going to rework all this. I'm open to that. It's a bit of rework now, but easier to do it as part of this than as a separate series. So, concretely: PageReferences() becomes folio_referenced() SetPageReferenced() becomes folio_set_referenced() ClearPageReferenced() becomes folio_clear_referenced() __SetFolioReferenced() becomes __folio_set_referenced() __ClearFolioReferenced() becomes __folio_clear_referenced() TestSetPageReferenced() becomes folio_test_set_referenced() TestClearPageReferenced() becomes folio_test_clear_referenced() We do have some functions already like set_page_writeback(), but I think those can become folio_set_writeback() without doing any harm. We also have page_is_young(), page_is_pfmemalloc(), page_is_guard(), etc. Should it be folio_referenced()? or folio_is_referenced()?