linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
	akpm@linux-foundation.org, hughd@google.com
Cc: willy@infradead.org, 21cnbao@gmail.com, ryan.roberts@arm.com,
	ziy@nvidia.com, gshan@redhat.com, ioworker0@gmail.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm: shmem: fix incorrect aligned index when checking conflicts
Date: Wed, 31 Jul 2024 11:18:53 +0200	[thread overview]
Message-ID: <db464483-5aa1-499d-9e66-ac30541499f9@redhat.com> (raw)
In-Reply-To: <07433b0f16a152bffb8cee34934a5c040e8e2ad6.1722404078.git.baolin.wang@linux.alibaba.com>

On 31.07.24 07:46, Baolin Wang wrote:
> In the shmem_suitable_orders() function, xa_find() is used to check for
> conflicts in the pagecache to select suitable huge orders. However, when
> checking each huge order in every loop, the aligned index is calculated
> from the previous iteration, which may cause suitable huge orders to be
> missed.
> 
> We should use the original index each time in the loop to calculate a
> new aligned index for checking conflicts to avoid this issue.
> 
> Fixes: e7a2ab7b3bb5 ("mm: shmem: add mTHP support for anonymous shmem")
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
>   mm/shmem.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index a4332a97558c..6e9836b1bd1d 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1686,6 +1686,7 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
>   					   unsigned long orders)
>   {
>   	struct vm_area_struct *vma = vmf->vma;
> +	pgoff_t aligned_index;
>   	unsigned long pages;
>   	int order;
>   
> @@ -1697,9 +1698,9 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
>   	order = highest_order(orders);
>   	while (orders) {
>   		pages = 1UL << order;
> -		index = round_down(index, pages);
> -		if (!xa_find(&mapping->i_pages, &index,
> -			     index + pages - 1, XA_PRESENT))
> +		aligned_index = round_down(index, pages);
> +		if (!xa_find(&mapping->i_pages, &aligned_index,
> +			     aligned_index + pages - 1, XA_PRESENT))
>   			break;
>   		order = next_order(&orders, order);
>   	}

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2024-07-31  9:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  5:46 [PATCH 1/2] mm: shmem: avoid allocating huge pages larger than MAX_PAGECACHE_ORDER for shmem Baolin Wang
2024-07-31  5:46 ` [PATCH 2/2] mm: shmem: fix incorrect aligned index when checking conflicts Baolin Wang
2024-07-31  9:18   ` David Hildenbrand [this message]
2024-07-31  6:18 ` [PATCH 1/2] mm: shmem: avoid allocating huge pages larger than MAX_PAGECACHE_ORDER for shmem Barry Song
2024-07-31  8:56   ` Baolin Wang
2024-07-31  9:59     ` Kefeng Wang
2024-07-31 10:22       ` Baolin Wang
2024-07-31 20:48         ` Andrew Morton
2024-08-01  0:06           ` Baolin Wang
2024-08-01 19:55             ` Andrew Morton
2024-08-02  3:11               ` Baolin Wang
2024-07-31  9:17 ` David Hildenbrand
2024-07-31 13:09 ` Zi Yan

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=db464483-5aa1-499d-9e66-ac30541499f9@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=gshan@redhat.com \
    --cc=hughd@google.com \
    --cc=ioworker0@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.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).