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

From: Andrew Morton
Date: Thu May 30 2024 - 15:58:42 EST


On Thu, 30 May 2024 11:19:07 +0100 Usama Arif <usamaarif642@xxxxxxxxx> wrote:

> Approximately 10-20% of pages to be swapped out are zero pages [1].
> Rather than reading/writing these pages to flash resulting
> in increased I/O and flash wear, a bitmap can be used to mark these
> pages as zero at write time, and the pages can be filled at
> read time if the bit corresponding to the page is set.
> With this patch, NVMe writes in Meta server fleet decreased
> by almost 10% with conventional swap setup (zswap disabled).

A little nitlet as you'll be altering the code...

> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -172,6 +172,77 @@ int generic_swapfile_activate(struct swap_info_struct *sis,
> goto out;
> }
>
> +static bool is_folio_page_zero_filled(struct folio *folio, int i)
> +{
> + unsigned long *page;
> + unsigned int pos;
> + bool ret = false;
> +
> + page = kmap_local_folio(folio, i * PAGE_SIZE);

It's rather expected that a local variable called `page' has type
`struct page *'. Can we use something like `addr' here?

> + for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) {
> + if (page[pos] != 0)
> + goto out;
> + }
> + ret = true;
> +out:
> + kunmap_local(page);
> + return ret;
> +}