Re: [PATCH v3 1/3] mm, swap: make SWAPFILE_CLUSTER runtime
From: IBM
Date: Fri Jun 19 2026 - 00:11:23 EST
Kairui Song <ryncsn@xxxxxxxxx> writes:
> 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) <ritesh.list@xxxxxxxxx>
>> ---
>> 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.
>
Thanks Kairui for taking a look at this. Sorry about the delayed
response, (was on travel to #OSSMumbai).
>>
>> 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?
>
yup. I can change that.
>> +#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?
>
Right. Earlier I was playing with different values of this via an
arch_xxx variant. But for book3s64 usecase, the default values are fine.
So, I agree, we need not change SWAPFILE_CLUSTER here. I can update the
patch with the suggested changes in v4.
-ritesh