On Fri, 18 Jul 2025 10:41:32 +0800 Ye Liu <[email protected]> wrote:

> From: Ye Liu <[email protected]>
> 
> Replace repeated (20 - PAGE_SHIFT) calculations with standard macros:
> - MB_TO_PAGES(mb)    converts MB to page count
> - PAGES_TO_MB(pages) converts pages to MB
> 
> No functional change.
> 
> ...
>
> +/*
> + * Convert between pages and MB
> + * 20 is the shift for 1MB (2^20 = 1MB)
> + * PAGE_SHIFT is the shift for page size (e.g., 12 for 4KB pages)
> + * So (20 - PAGE_SHIFT) converts between pages and MB
> + */
> +#define PAGES_TO_MB(pages) ((pages) >> (20 - PAGE_SHIFT))
> +#define MB_TO_PAGES(mb)    ((mb) << (20 - PAGE_SHIFT))
> +
>  #ifdef CONFIG_SYSCTL
>  extern int sysctl_legacy_va_layout;
>  #else
>
> ...
>
> @@ -796,7 +796,7 @@ kfree_scale_thread(void *arg)
>               pr_alert("Total time taken by all kfree'ers: %llu ns, loops: 
> %d, batches: %ld, memory footprint: %lldMB\n",
>                      (unsigned long long)(end_time - start_time), kfree_loops,
>                      rcuscale_seq_diff(b_rcu_gp_test_finished, 
> b_rcu_gp_test_started),
> -                    (mem_begin - mem_during) >> (20 - PAGE_SHIFT));
> +                    PAGES_TO_MB(mem_begin - mem_during));
>  
>               if (shutdown) {
>                       smp_mb(); /* Assign before wake. */

But, but, but, obscure hard-coded magic numbers are there for our job
security!

Oh well, we got caught.  Applied, thanks.

Reply via email to