linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Usama Arif <usamaarif642@gmail.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
	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
Subject: Re: [PATCH v2 1/2] mm: clear pte for folios that are zero filled
Date: Wed, 5 Jun 2024 01:55:17 -0700	[thread overview]
Message-ID: <nes73bwc5p6yhwt5tw3upxcqrn5kenn6lvqb6exrf4yppmz6jx@ywhuevpkxlvh> (raw)
In-Reply-To: <20240604105950.1134192-2-usamaarif642@gmail.com>

On Tue, Jun 04, 2024 at 11:58:24AM GMT, Usama Arif wrote:
[...]
>  
> +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;
> +

Use memchr_inv() instead of the following.

> +	for (pos = 0; pos < last_pos; pos++) {
> +		if (data[pos])
> +			goto out;
> +	}
> +	ret = true;
> +out:
> +	kunmap_local(data);
> +	return ret;
> +}
> +
[...]
> +
>  /*
>   * shrink_folio_list() returns the number of reclaimed pages
>   */
> @@ -1053,6 +1085,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
>  		enum folio_references references = FOLIOREF_RECLAIM;
>  		bool dirty, writeback;
>  		unsigned int nr_pages;
> +		bool folio_zero_filled = false;
>  
>  		cond_resched();
>  
> @@ -1270,6 +1303,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
>  			nr_pages = 1;
>  		}
>  
> +		folio_zero_filled = is_folio_zero_filled(folio);

You need to check for zeroes after the unmap below otherwise you may
lost data. So you need to do two rmap walks. Most probably the first one
would be the standard one (inserting swap entry in the ptes) but the
second one would be different where swap entries should be replaced by
the zeropage. Also at the end you need to make sure to release all the
swap resources associated with the given page/folio.

>  		/*
>  		 * The folio is mapped into the page tables of one or more
>  		 * processes. Try to unmap it here.
> @@ -1295,6 +1329,9 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
>  			if (folio_test_large(folio) && list_empty(&folio->_deferred_list))
>  				flags |= TTU_SYNC;
>  
> +			if (folio_zero_filled)
> +				flags |= TTU_ZERO_FOLIO;
> +
>  			try_to_unmap(folio, flags);
>  			if (folio_mapped(folio)) {
>  				stat->nr_unmap_fail += nr_pages;


  parent reply	other threads:[~2024-06-05  8:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 10:58 [PATCH v2 0/2] " Usama Arif
2024-06-04 10:58 ` [PATCH v2 1/2] " Usama Arif
2024-06-04 12:18   ` Matthew Wilcox
2024-06-04 12:42     ` Usama Arif
2024-06-04 12:30   ` David Hildenbrand
2024-06-04 12:43     ` David Hildenbrand
2024-06-07 10:24       ` Usama Arif
2024-06-07 11:16         ` David Hildenbrand
2024-06-05  8:55   ` Shakeel Butt [this message]
2024-06-07 10:40     ` Usama Arif
2024-06-04 10:58 ` [PATCH v2 2/2] mm: remove code to handle same filled pages Usama Arif

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=nes73bwc5p6yhwt5tw3upxcqrn5kenn6lvqb6exrf4yppmz6jx@ywhuevpkxlvh \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=usamaarif642@gmail.com \
    --cc=willy@infradead.org \
    --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