From patchwork Fri Oct 25 03:18:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13849980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA81D116E0 for ; Fri, 25 Oct 2024 03:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8524D6B009D; Thu, 24 Oct 2024 23:18:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 802056B009E; Thu, 24 Oct 2024 23:18:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C90C6B009F; Thu, 24 Oct 2024 23:18:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 450F46B009D for ; Thu, 24 Oct 2024 23:18:58 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 25314ABBF3 for ; Fri, 25 Oct 2024 03:18:20 +0000 (UTC) X-FDA: 82710666906.09.4EB01B6 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf10.hostedemail.com (Postfix) with ESMTP id CB905C0013 for ; Fri, 25 Oct 2024 03:18:47 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G5jme+EZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729826296; a=rsa-sha256; cv=none; b=qJomu+maEYbBdgIKyYtWF5+b+FEMpgSH2FZsTuSr4A0SMpqLnKNq0Z5oA2jBJLbVvqV7XL Ft3yNTdkUWh22NdOFCvHUydgN3yrhmaRG+E6XvDyFZfaQ0MElUsoyVcAmWukBdVoLL0vA3 Ynw9Sy9HFnvp7eAS/MF2jgyNgKnH8rI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G5jme+EZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729826296; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=+ayWe0cd4kSx4dE5xBlMiTQYZFm4Rg9mYHFy0YuaQWM=; b=giqz9RWeoiSnMbcEJGs7nwvsNM7hz4Xi96TMIodFE71MV+V4CutkvoyEufyuOynrJME1lG wBX9BM70hef3bzz/E70XlwwjmlmJy+YFFD5IaSyClnrYj/AjqsYsWaDtIb+HB8ZuzykQCR LVlHvq/WdNaDAxB7l9Q5ziH7iMD14SU= Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5cb6ca2a776so2007467a12.0 for ; Thu, 24 Oct 2024 20:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729826335; x=1730431135; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=+ayWe0cd4kSx4dE5xBlMiTQYZFm4Rg9mYHFy0YuaQWM=; b=G5jme+EZVeEf7fs5kuDXe4xyoD7a8gPT4kRps+mctdUKPmApTkgaPc4okjEZ/xgc7l ABgZcpzrKiBtYQ8hJN4aFzOjba5xgd2TcUQ0HE7TFU3Ylk2syEqkoSLHgFrrTdMpeUUp YnaU5OIEPqH4XgJtvGphkPbV2ynY+f/KDL+7vEyc+kkjHPEzPkaua2fnteOgbaxkr1Da FJk+rbQP1EiZGvtVWGc8wxLNbs1mW1ABT/6CuDZtAvMAu1fhehiFrDnq6M8Qc+a9sFCN 6hkeE2rJ8zKE1SOkXyJdUYg8yRFDfTkfN7d446B6W7j7bWoaVsWhMx98v6ZmspA+BNwN Y39w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729826335; x=1730431135; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+ayWe0cd4kSx4dE5xBlMiTQYZFm4Rg9mYHFy0YuaQWM=; b=Ht3nG82QaW44hx0fPKse+q+82L1lPCU4q3S0Nub8R4SRGY5uNjlOjzNAoCYR5PCO5t C6mRSup/ypoCR1IaeKBASKFfCXS710wMIBfiaKVcxEHiw80RXnekKxI41BqkSP9Cf/8C SsNVC9KFROD/iBaogbLkKnP2SBJM54P0l11JzSOpjOjLnN25V21GResS6WiKphLVdYPl pc8JKQvUU0W9OJUakH38mlsD7lAOMDXw4QSJNNiJ3oLWklVYYYoNfugDdgKp7vNaZ+CI BuGXNBg9W6qae7WjiOPd9dzI9ABM8A9Ni8ua2UP32uKbG6ssdQ8j8vufwMSfiMtmswM2 5uTA== X-Gm-Message-State: AOJu0Yxwjr5tj+LlbAQagrtB/sV+jFjbalb8BKpBEBAt7+AmsguLBGA8 CogQDBvQzdA02fPJzRDNydR3kNOgTfISiqm4u7elhoZKUrH4u3k8 X-Google-Smtp-Source: AGHT+IHT9OzlHQFrtCFBszAVWcZDz49oMuYXM4h8zdUdL88cXhUcghR/ecDN3T1s347BQJgivs5CCg== X-Received: by 2002:a05:6402:51c8:b0:5c2:439d:90d4 with SMTP id 4fb4d7f45d1cf-5cb8b1a1084mr5808296a12.30.1729826334592; Thu, 24 Oct 2024 20:18:54 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb62c3da7sm136569a12.55.2024.10.24.20.18.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2024 20:18:53 -0700 (PDT) From: Wei Yang 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 Subject: [PATCH 1/3] mm/vma: miss to restore vmi.index on expansion failure Date: Fri, 25 Oct 2024 03:18:45 +0000 Message-Id: <20241025031847.6274-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20241025031847.6274-1-richard.weiyang@gmail.com> References: <20241025031847.6274-1-richard.weiyang@gmail.com> X-Rspam-User: X-Stat-Signature: g1qk6soffzkgbisw4sjbfs1i4qkq5yi8 X-Rspamd-Queue-Id: CB905C0013 X-Rspamd-Server: rspam02 X-HE-Tag: 1729826327-66622 X-HE-Meta: U2FsdGVkX18RYmbJin+jdPDtZKcpg7ghO6qXmGAJ+Zd4bz1hTu3uBp/ULEnL9gQ+Xj1IozWfwbenPkpz0NBQEzbkjC0m1EkRH5mqPxPHIIrrquSxYfM8pL5sok0/BAXBk4JjRrBQPyYNwBM3Sw1/z2wuM+18iFdN2nRIfuyA7Yk5VipJBf3yc4mweEEW3GGUU3kFLKKHCPBOoLRAnd15LNJejcrh6MjIU4yZln+3VyOVKbctSNadWqYXy60T4bDPHDsV1Mhs+iWEL1vsWfXZ1speG2/CSBE1l2dx3NFATFMBrJqDk2xDMpgQXVEeqnqcW/qvuSnMzpZ+zRlwFght55GLmyvc2L73Wrqq+yh+8X5njImBvB7TJSM3y1P585Xx0vwPZEtK1cISKyBRCKT3YVoAnl+kzhUjfXNSCCQgkdMQa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ender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 CC: Lorenzo Stoakes --- 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; }