Re: [PATCH v3 3/3] kselftest: mm: introduce size_to_shift() helper

From: David Hildenbrand (Arm)

Date: Mon Sep 14 2026 - 11:48:41 EST


On 9/14/26 09:30, Yeoreum Yun wrote:
> Introduce size_to_shift() for future users that need to
> obtain shift of a huge-page which is other than pmd_psize().
>
> Suggested-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
> ---
> tools/testing/selftests/mm/vm_util.c | 10 +++++++++-
> tools/testing/selftests/mm/vm_util.h | 1 +
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index fd1432dc6152..1fef1266429f 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -157,6 +157,14 @@ bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len)
> return false;
> }
>
> +uint64_t size_to_shift(uint64_t size)
> +{
> + if (__builtin_popcountll(size) != 1)
> + return 0;
> +
> + return ffsl(size) - 1;
> +}

Could likely just be an inline helper?

--
Cheers,

David