linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org, Liam.Howlett@oracle.com,
	lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>
Subject: [PATCH 1/3] mm/vma: miss to restore vmi.index on expansion failure
Date: Fri, 25 Oct 2024 03:18:45 +0000	[thread overview]
Message-ID: <20241025031847.6274-2-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20241025031847.6274-1-richard.weiyang@gmail.com>

On expansion failure, we try to restore vmg state, but we missed to
restore vmi.index. The reason is we have reset vmg->vma before checking.
So let's put the operation before reset vmg->vma.

Also we don't need to do the restore if there is no mergeable adjacent
VMA. Let's take it out to skip the unnecessary operations.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 mm/vma.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/vma.c b/mm/vma.c
index fb4f1863f88e..c94d953d453c 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -954,23 +954,27 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
 		vma_prev(vmg->vmi); /* Equivalent to going to the previous range */
 	}
 
+	/* No mergeable adjacent VMA, return */
+	if (!vmg->vma)
+		return NULL;
+
 	/*
 	 * Now try to expand adjacent VMA(s). This takes care of removing the
 	 * following VMA if we have VMAs on both sides.
 	 */
-	if (vmg->vma && !vma_expand(vmg)) {
+	if (!vma_expand(vmg)) {
 		khugepaged_enter_vma(vmg->vma, vmg->flags);
 		vmg->state = VMA_MERGE_SUCCESS;
 		return vmg->vma;
 	}
 
 	/* If expansion failed, reset state. Allows us to retry merge later. */
+	if (vmg->vma == prev)
+		vma_iter_set(vmg->vmi, start);
 	vmg->vma = NULL;
 	vmg->start = start;
 	vmg->end = end;
 	vmg->pgoff = pgoff;
-	if (vmg->vma == prev)
-		vma_iter_set(vmg->vmi, start);
 
 	return NULL;
 }
-- 
2.34.1



  reply	other threads:[~2024-10-25  3:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25  3:18 [PATCH 0/3] " Wei Yang
2024-10-25  3:18 ` Wei Yang [this message]
2024-10-25  7:06   ` [PATCH 1/3] " Lorenzo Stoakes
2024-10-25  7:43     ` Wei Yang
2024-10-25  7:59     ` Wei Yang
2024-10-25  8:10       ` Lorenzo Stoakes
2024-10-25  8:32         ` Wei Yang
2024-10-25  8:40           ` Lorenzo Stoakes
2024-10-25  8:49             ` Wei Yang
2024-10-25  8:51               ` Lorenzo Stoakes
2024-10-25  8:54                 ` Wei Yang
2024-10-25  9:01                   ` Lorenzo Stoakes
2024-10-25  9:11                     ` Wei Yang
2024-10-25  3:18 ` [PATCH 2/3] tools: test vmi.index would be restored on merge failure Wei Yang
2024-10-25  3:18 ` [PATCH 3/3] tools: fix build error on parameter name omitted Wei Yang
2024-10-25  6:50   ` Lorenzo Stoakes
2024-10-25 20:06 ` [PATCH 0/3] mm/vma: miss to restore vmi.index on expansion failure Liam R. Howlett
2024-10-25 20:14   ` Lorenzo Stoakes

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=20241025031847.6274-2-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=jannh@google.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=vbabka@suse.cz \
    /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