From: Usama Arif <usamaarif642@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: akpm@linux-foundation.org, shakeel.butt@linux.dev,
david@redhat.com, ying.huang@intel.com, hughd@google.com,
willy@infradead.org, yosryahmed@google.com, nphamcs@gmail.com,
chengming.zhou@linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com,
Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH v7 1/2] mm: store zero pages to be swapped out in a bitmap
Date: Fri, 28 Jun 2024 18:30:43 +0300 [thread overview]
Message-ID: <44a57df4-e54c-47ee-96b8-e2361c549239@gmail.com> (raw)
In-Reply-To: <20240627161852.GA469122@cmpxchg.org>
On 27/06/2024 19:18, Johannes Weiner wrote:
> Hi Usama,
>
> On Thu, Jun 27, 2024 at 11:55:29AM +0100, Usama Arif 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).
>>
>> [1] https://lore.kernel.org/all/20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0@epcms5p1/
>>
>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
>> Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
>> Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
>> Reviewed-by: Nhat Pham <nphamcs@gmail.com>
>> Cc: David Hildenbrand <david@redhat.com>
>> Cc: "Huang, Ying" <ying.huang@intel.com>
>> Cc: Hugh Dickins <hughd@google.com>
>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
>> Cc: Shakeel Butt <shakeel.butt@linux.dev>
>> Cc: Usama Arif <usamaarif642@gmail.com>
>> Cc: Andi Kleen <ak@linux.intel.com>
>> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> This looks great to me, and the numbers speak for themselves. A few
> minor comments below:
>
>> ---
>> include/linux/swap.h | 1 +
>> mm/page_io.c | 113 ++++++++++++++++++++++++++++++++++++++++++-
>> mm/swapfile.c | 20 ++++++++
>> 3 files changed, 133 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>> index 3df75d62a835..ed03d421febd 100644
>> --- a/include/linux/swap.h
>> +++ b/include/linux/swap.h
>> @@ -299,6 +299,7 @@ struct swap_info_struct {
>> signed char type; /* strange name for an index */
>> unsigned int max; /* extent of the swap_map */
>> unsigned char *swap_map; /* vmalloc'ed array of usage counts */
>> + unsigned long *zeromap; /* vmalloc'ed bitmap to track zero pages */
>> struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */
>> struct swap_cluster_list free_clusters; /* free clusters list */
>> unsigned int lowest_bit; /* index of first free in swap_map */
>> diff --git a/mm/page_io.c b/mm/page_io.c
>> index 6c1c1828bb88..480b8f221d90 100644
>> --- a/mm/page_io.c
>> +++ b/mm/page_io.c
>> @@ -172,6 +172,88 @@ int generic_swapfile_activate(struct swap_info_struct *sis,
>> goto out;
>> }
>>
> It might be good to have a short comment that gives 1) an overview,
> that we're using a bitmap to avoid doing IO for zero-filled pages and
> 2) the locking, that the bits are protected by the locked swapcache
> folio and atomic updates are used to protect against RMW corruption
> due to other zero swap entries seeing concurrent updates.
Thanks! have addressed the comments and will include them in next
revision. Just a couple of things.
Will add the overview in swap_writepage when the check is made if the
folio is zero filled and zeromap bits are set, instead of at this point.
>> +static bool is_folio_page_zero_filled(struct folio *folio, int i)
>> +{
>> + unsigned long *data;
>> + unsigned int pos, last_pos = PAGE_SIZE / sizeof(*data) - 1;
>> + bool ret = false;
>> +
>> + data = kmap_local_folio(folio, i * PAGE_SIZE);
>> + if (data[last_pos])
>> + goto out;
>> +static void folio_zero_fill(struct folio *folio)
>> +{
>> + unsigned int i;
>> +
>> + for (i = 0; i < folio_nr_pages(folio); i++)
>> + clear_highpage(folio_page(folio, i));
>> +}
> Should this be in highmem.h next to the other folio_zero_* functions?
Thanks for pointing to highmem.h. It already has folio_zero_range, which
should do the same thing, so I think I can just do
folio_zero_range(folio, 0, folio_size(folio)) and this function shouldnt
be needed.
next prev parent reply other threads:[~2024-06-28 15:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 10:55 [PATCH v7 0/2] mm: store zero pages to be swapped out in a bitmap Usama Arif
2024-06-27 10:55 ` [PATCH v7 1/2] " Usama Arif
2024-06-27 16:18 ` Johannes Weiner
2024-06-28 15:30 ` Usama Arif [this message]
2024-07-01 15:01 ` Usama Arif
2024-07-01 15:37 ` Usama Arif
2024-07-01 17:15 ` Usama Arif
2024-07-04 23:22 ` Andrew Morton
2024-07-05 9:41 ` Usama Arif
2024-06-27 10:55 ` [PATCH v7 2/2] mm: remove code to handle same filled pages Usama Arif
2024-06-27 16:19 ` Johannes Weiner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44a57df4-e54c-47ee-96b8-e2361c549239@gmail.com \
--to=usamaarif642@gmail.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).