On Fri, Jun 12, 2026 at 11:39:15PM +0800, Ritesh Harjani (IBM) wrote: > On PowerPC Book3S64, MMU is selected at runtime, so macros like > PMD_SHIFT are effectively runtime variables in the Book3S64 code. THP > swap code uses these macros to size some of its array data structures > based on PMD_ORDER e.g. SWAPFILE_CLUSTER macro is used for this very > purpose. > Hence this patch initializes SWAPFILE_CLUSTER at runtime and also > modifies swap_table and swap_memcg_table which were earlier using this > macro for defining the number of table entries. > > Signed-off-by: Ritesh Harjani (IBM) <[email protected]> > --- > mm/swap.h | 5 +++-- > mm/swap_table.h | 6 ++---- > mm/swapfile.c | 27 ++++++++++++++++++++++----- > 3 files changed, 27 insertions(+), 11 deletions(-)
Hi Ritesh, Thanks for the patch. > > diff --git a/mm/swap.h b/mm/swap.h > index 77d2d14eda42..956879a69ddd 100644 > --- a/mm/swap.h > +++ b/mm/swap.h > @@ -26,11 +26,12 @@ extern int page_cluster; > #define SWAP_TABLE_HAS_ZEROFLAG ((BITS_PER_LONG - > SWAP_CACHE_PFN_MARK_BITS - \ > SWAP_CACHE_PFN_BITS) > > SWAP_COUNT_MIN_BITS) > > +extern unsigned int swap_slots_in_cluster __read_mostly; Maybe __ro_after_init is better for this kind of use case? > +#define SWAPFILE_CLUSTER swap_slots_in_cluster > + > #ifdef CONFIG_THP_SWAP > -#define SWAPFILE_CLUSTER HPAGE_PMD_NR So on Book3S64, HPAGE_PMD_NR is also a variable right? Then we don't really need to change the SWAPFILE_CLUSTER defination here? We just need to adjust the users of this macro so the build will pass? Or maybe use another macro instead of HPAGE_PMD_NR here, whichever is more arch friendly. That way if that is a build time constant, all users are folded to just one mask/shift which is super efficient especially for inline helpers, and there are a lot of them. Only special archs live with the dynamic load overhead.
