lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 28 Jun 2024 18:30:43 +0300
From: Usama Arif <usamaarif642@...il.com>
To: Johannes Weiner <hannes@...xchg.org>
Cc: akpm@...ux-foundation.org, shakeel.butt@...ux.dev, david@...hat.com,
 ying.huang@...el.com, hughd@...gle.com, willy@...radead.org,
 yosryahmed@...gle.com, nphamcs@...il.com, chengming.zhou@...ux.dev,
 linux-mm@...ck.org, linux-kernel@...r.kernel.org, kernel-team@...a.com,
 Andi Kleen <ak@...ux.intel.com>
Subject: Re: [PATCH v7 1/2] mm: store zero pages to be swapped out in a bitmap


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@...il.com>
>> Reviewed-by: Chengming Zhou <chengming.zhou@...ux.dev>
>> Reviewed-by: Yosry Ahmed <yosryahmed@...gle.com>
>> Reviewed-by: Nhat Pham <nphamcs@...il.com>
>> Cc: David Hildenbrand <david@...hat.com>
>> Cc: "Huang, Ying" <ying.huang@...el.com>
>> Cc: Hugh Dickins <hughd@...gle.com>
>> Cc: Johannes Weiner <hannes@...xchg.org>
>> Cc: Matthew Wilcox (Oracle) <willy@...radead.org>
>> Cc: Shakeel Butt <shakeel.butt@...ux.dev>
>> Cc: Usama Arif <usamaarif642@...il.com>
>> Cc: Andi Kleen <ak@...ux.intel.com>
>> Signed-off-by: Andrew Morton <akpm@...ux-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.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ