[PATCH makedumpfile v2 5/9] Move page checks into makedumpfile.h
Stephen Brennan <[email protected]>
| Newsgroups | org.infradead.lists.kexec |
|---|---|
| Message-ID | <[email protected]> |
Most checks are already macros in makedumpfile.h, but some are simple helper functions in makedumpfile.c. They are not accessible to extensions as a result. It's helpful to keep as much of this logic available to extensions as possible, so that they do not need to re-implement more than necessary. Move isHugetlb, isSlab, isOffline, and is_cache_page to the header. Signed-off-by: Stephen Brennan <[email protected]> --- makedumpfile.c | 57 -------------------------------------------------- makedumpfile.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index fca42e1..b04a1e3 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -266,63 +266,6 @@ is_in_same_page(unsigned long vaddr1, unsigned long vaddr2) return FALSE; } -/* For Linux 6.6 and later */ -#define IS_HUGETLB ((unsigned long)-1) - -static inline int -isHugetlb(unsigned long dtor) -{ - return (dtor == IS_HUGETLB) - || ((NUMBER(HUGETLB_PAGE_DTOR) != NOT_FOUND_NUMBER) - && (NUMBER(HUGETLB_PAGE_DTOR) == dtor)) - || ((SYMBOL(free_huge_page) != NOT_FOUND_SYMBOL) - && (SYMBOL(free_huge_page) == dtor)); -} - -static inline int -isSlab(unsigned long flags, unsigned int _mapcount) -{ - /* Linux 6.10 and later */ - if (NUMBER(PAGE_SLAB_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) { - if (_mapcount == (int)NUMBER(PAGE_SLAB_MAPCOUNT_VALUE)) - return TRUE; - } - - return flags & (1UL << NUMBER(PG_slab)); -} - -static int -isOffline(unsigned long flags, unsigned int _mapcount) -{ - if (NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER) - return FALSE; - - if (isSlab(flags, _mapcount)) - return FALSE; - - if (_mapcount == (int)NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE)) - return TRUE; - - return FALSE; -} - -static int -is_cache_page(unsigned long flags) -{ - if (isLRU(flags)) - return TRUE; - - /* PG_swapcache is valid only if: - * a. PG_swapbacked bit is set, or - * b. PG_swapbacked did not exist (kernels before 4.10-rc1). - */ - if ((NUMBER(PG_swapbacked) == NOT_FOUND_NUMBER || isSwapBacked(flags)) - && isSwapCache(flags)) - return TRUE; - - return FALSE; -} - static inline unsigned long calculate_len_buf_out(long page_size) { diff --git a/makedumpfile.h b/makedumpfile.h index 87f973d..3d64677 100644 --- a/makedumpfile.h +++ b/makedumpfile.h @@ -2644,6 +2644,63 @@ is_zero_page(unsigned char *buf, long page_size) return TRUE; } +/* For Linux 6.6 and later */ +#define IS_HUGETLB ((unsigned long)-1) + +static inline int +isHugetlb(unsigned long dtor) +{ + return (dtor == IS_HUGETLB) + || ((NUMBER(HUGETLB_PAGE_DTOR) != NOT_FOUND_NUMBER) + && (NUMBER(HUGETLB_PAGE_DTOR) == dtor)) + || ((SYMBOL(free_huge_page) != NOT_FOUND_SYMBOL) + && (SYMBOL(free_huge_page) == dtor)); +} + +static inline int +isSlab(unsigned long flags, unsigned int _mapcount) +{ + /* Linux 6.10 and later */ + if (NUMBER(PAGE_SLAB_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) { + if (_mapcount == (int)NUMBER(PAGE_SLAB_MAPCOUNT_VALUE)) + return TRUE; + } + + return flags & (1UL << NUMBER(PG_slab)); +} + +static inline int +isOffline(unsigned long flags, unsigned int _mapcount) +{ + if (NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER) + return FALSE; + + if (isSlab(flags, _mapcount)) + return FALSE; + + if (_mapcount == (int)NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE)) + return TRUE; + + return FALSE; +} + +static inline int +is_cache_page(unsigned long flags) +{ + if (isLRU(flags)) + return TRUE; + + /* PG_swapcache is valid only if: + * a. PG_swapbacked bit is set, or + * b. PG_swapbacked did not exist (kernels before 4.10-rc1). + */ + if ((NUMBER(PG_swapbacked) == NOT_FOUND_NUMBER || isSwapBacked(flags)) + && isSwapCache(flags)) + return TRUE; + + return FALSE; +} + void write_vmcoreinfo_data(void); int set_bit_on_1st_bitmap(mdf_pfn_t pfn, struct cycle *cycle); int clear_bit_on_1st_bitmap(mdf_pfn_t pfn, struct cycle *cycle); -- 2.52.0