Re: [PATCH v4 1/2] mm: store zero pages to be swapped out in a bitmap

From: Yosry Ahmed
Date: Wed Sep 04 2024 - 19:58:52 EST


[..]
> well. i feel i have a much cheaper way to implement this, which
> can entirely iteration even in your original code:
>
> +/*
> + * Return the number of entries which are zero-filled according to
> + * swap_info_struct->zeromap. It isn't precise if the return value
> + * is 1 for nr > 1. In this case, it means entries have inconsistent
> + * zeromap.
> + */
> +static inline unsigned int swap_zeromap_entries_count(swp_entry_t
> entry, int nr)

FWIW I am not really a fan of the count() function not returning an
actual count. I think an enum with three states is more appropriate
here, and renaming the function to swap_zeromap_entries_check() or
similar.

> +{
> + struct swap_info_struct *sis = swp_swap_info(entry);
> + unsigned long start = swp_offset(entry);
> + unsigned long end = start + nr;
> + unsigned long idx = 0;
> +
> + idx = find_next_bit(sis->zeromap, end, start);
> + if (idx == end)
> + return 0;
> + if (idx > start)
> + return 1;
> + return nr;
> +}
> +
>
>