Introduce basic utility functions for zsdesc to avoid directly accessing fields of struct page. More helpers will be defined later. zsdesc_page() is defined with _Generic to preserve constness. page_zsdesc() does not call compound_head() because zsdesc is always a base page. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@xxxxxxxxx> --- mm/zsmalloc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 2204bea4f289..11c203e79c39 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -293,6 +293,39 @@ ZSDESC_MATCH(_refcount, _refcount); #undef ZSDESC_MATCH static_assert(sizeof(struct zsdesc) <= sizeof(struct page)); +#define zsdesc_page(zdesc) (_Generic((zdesc), \ + const struct zsdesc *: (const struct page *)zdesc, \ + struct zsdesc *: (struct page *)zdesc)) + +static inline struct zsdesc *page_zsdesc(struct page *page) +{ + return (struct zsdesc *)page; +} + +static inline unsigned long zsdesc_pfn(const struct zsdesc *zsdesc) +{ + return page_to_pfn(zsdesc_page(zsdesc)); +} + +static inline struct zsdesc *pfn_zsdesc(unsigned long pfn) +{ + return page_zsdesc(pfn_to_page(pfn)); +} + +static inline void zsdesc_get(struct zsdesc *zsdesc) +{ + struct folio *folio = (struct folio *)zsdesc; + + folio_get(folio); +} + +static inline void zsdesc_put(struct zsdesc *zsdesc) +{ + struct folio *folio = (struct folio *)zsdesc; + + folio_put(folio); +} + /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ static void SetZsHugePage(struct zspage *zspage) { -- 2.41.0