[PATCH makedumpfile v2 6/9] Simplify arguments for page checks
Stephen Brennan <[email protected]>
| Newsgroups | org.infradead.lists.kexec |
|---|---|
| Message-ID | <[email protected]> |
Many isSomething() helpers need to use several fields in order to make a determination (e.g. flags, _mapcount, private, _count). All of the info we extract about a page's identity is now grouped together into struct pginfo, so we can instead pass a pointer to that struct directly. This makes it easier to read and write the code, and it also sets an easy calling convention that extensions can use. For helpers that require a single field, e.g. flags, still pass it directly. The benefits of replacing that value with a structure pointer aren't so obvious to me. Signed-off-by: Stephen Brennan <[email protected]> --- makedumpfile.c | 22 ++++++++++------------ makedumpfile.h | 21 +++++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index b04a1e3..6c62930 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -6008,10 +6008,9 @@ exclude_free_page(struct cycle *cycle) * For the kernel versions from v2.6.17 to v2.6.37. */ static int -page_is_buddy_v2(unsigned long flags, unsigned int _mapcount, - unsigned long private, unsigned int _count) +page_is_buddy_v2(const struct pginfo *i) { - if (flags & (1UL << NUMBER(PG_buddy))) + if (i->flags & (1UL << NUMBER(PG_buddy))) return TRUE; return FALSE; @@ -6021,13 +6020,12 @@ page_is_buddy_v2(unsigned long flags, unsigned int _mapcount, * For v2.6.38 and later kernel versions. */ static int -page_is_buddy_v3(unsigned long flags, unsigned int _mapcount, - unsigned long private, unsigned int _count) +page_is_buddy_v3(const struct pginfo *i) { - if (isSlab(flags, _mapcount)) + if (isSlab(i)) return FALSE; - if (_mapcount == (int)NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)) + if (i->_mapcount == (int)NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)) return TRUE; return FALSE; @@ -6589,7 +6587,7 @@ check_order: */ if ((info->dump_level & DL_EXCLUDE_FREE) && info->page_is_buddy - && info->page_is_buddy(i.flags, i._mapcount, i.private, i._count)) { + && info->page_is_buddy(&i)) { if ((ARRAY_LENGTH(zone.free_area) != NOT_FOUND_STRUCTURE) && (i.private >= ARRAY_LENGTH(zone.free_area))) { MSG("WARNING: Invalid free page order: pfn=%llx, order=%lu, max order=%lu\n", @@ -6615,7 +6613,7 @@ check_order: */ else if ((info->dump_level & DL_EXCLUDE_CACHE) && is_cache_page(i.flags) - && !isPrivate(i.flags) && !isAnon(i.mapping, i.flags, i._mapcount)) { + && !isPrivate(i.flags) && !isAnon(&i)) { pfn_counter = &pfn_cache; } /* @@ -6623,7 +6621,7 @@ check_order: */ else if ((info->dump_level & DL_EXCLUDE_CACHE_PRI) && is_cache_page(i.flags) - && !isAnon(i.mapping, i.flags, i._mapcount)) { + && !isAnon(&i)) { if (isPrivate(i.flags)) pfn_counter = &pfn_cache_private; else @@ -6635,7 +6633,7 @@ check_order: * - hugetlbfs pages */ else if ((info->dump_level & DL_EXCLUDE_USER_DATA) - && (isAnon(i.mapping, i.flags, i._mapcount) || isHugetlb(i.compound_dtor))) { + && (isAnon(&i) || isHugetlb(i.compound_dtor))) { pfn_counter = &pfn_user; } /* @@ -6647,7 +6645,7 @@ check_order: /* * Exclude pages that are logically offline. */ - else if (isOffline(i.flags, i._mapcount)) { + else if (isOffline(&i)) { pfn_counter = &pfn_offline; } /* diff --git a/makedumpfile.h b/makedumpfile.h index 3d64677..cf9d22b 100644 --- a/makedumpfile.h +++ b/makedumpfile.h @@ -161,8 +161,8 @@ test_bit(int nr, unsigned long addr) #define isSwapBacked(flags) test_bit(NUMBER(PG_swapbacked), flags) #define isHWPOISON(flags) (test_bit(NUMBER(PG_hwpoison), flags) \ && (NUMBER(PG_hwpoison) != NOT_FOUND_NUMBER)) -#define isAnon(mapping, flags, _mapcount) \ - (((unsigned long)mapping & PAGE_MAPPING_ANON) != 0 && !isSlab(flags, _mapcount)) +#define isAnon(i) \ + (((unsigned long)(i)->mapping & PAGE_MAPPING_ANON) != 0 && !isSlab(i)) #define isUnaccepted(_mapcount) (_mapcount == (int)NUMBER(PAGE_UNACCEPTED_MAPCOUNT_VALUE) \ && (NUMBER(PAGE_UNACCEPTED_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)) @@ -1763,8 +1763,7 @@ struct DumpInfo { /* * for filtering free pages managed by buddy system: */ - int (*page_is_buddy)(unsigned long flags, unsigned int _mapcount, - unsigned long private, unsigned int _count); + int (*page_is_buddy)(const struct pginfo *); /* * for cyclic_splitting mode, setup splitblock_size */ @@ -2657,28 +2656,26 @@ isHugetlb(unsigned long dtor) && (SYMBOL(free_huge_page) == dtor)); } -static inline int -isSlab(unsigned long flags, unsigned int _mapcount) +static inline int isSlab(const struct pginfo *i) { /* Linux 6.10 and later */ if (NUMBER(PAGE_SLAB_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) { - if (_mapcount == (int)NUMBER(PAGE_SLAB_MAPCOUNT_VALUE)) + if (i->_mapcount == (int)NUMBER(PAGE_SLAB_MAPCOUNT_VALUE)) return TRUE; } - return flags & (1UL << NUMBER(PG_slab)); + return i->flags & (1UL << NUMBER(PG_slab)); } -static inline int -isOffline(unsigned long flags, unsigned int _mapcount) +static inline int isOffline(const struct pginfo *i) { if (NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER) return FALSE; - if (isSlab(flags, _mapcount)) + if (isSlab(i)) return FALSE; - if (_mapcount == (int)NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE)) + if (i->_mapcount == (int)NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE)) return TRUE; return FALSE; -- 2.52.0