From patchwork Thu Oct 24 09:33:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13848630 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 A0A00D0BB7A for ; Thu, 24 Oct 2024 09:34:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 220B66B0083; Thu, 24 Oct 2024 05:34:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D0B26B0085; Thu, 24 Oct 2024 05:34:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 098E86B0089; Thu, 24 Oct 2024 05:34:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DE9CE6B0083 for ; Thu, 24 Oct 2024 05:34:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4C505141207 for ; Thu, 24 Oct 2024 09:34:12 +0000 (UTC) X-FDA: 82707985374.28.D26F44D Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by imf30.hostedemail.com (Postfix) with ESMTP id 371018000A for ; Thu, 24 Oct 2024 09:33:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vt9sehhg; spf=pass (imf30.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729762418; 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:references:dkim-signature; bh=C2o5Tb8yVVKQHyEzW8mTATCiOvDfyZHhWirjILULyt0=; b=BcaTGv22ZrnlSFcmhm1crYrOU75hbN828/c8Yx2TbWT7T1s3PMw2k+jPppvXtcsfiWT/xr mq2/VobBJKKyXBSQxsrLksvvXRD+UIpNwGLiMm9l7V/WYW4YG9c+DSrCjJ99bLccl6zaUQ UDML2lRD9v6Od5qTcILbZmfcUbtxPtg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vt9sehhg; spf=pass (imf30.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729762418; a=rsa-sha256; cv=none; b=oVyd7aPVpcdVdEQNE2paNwr0yQyXpNwRoZT4kyWzMzBAoGghfhdZ/iWJIioMQLNAC8uW7g qJ8SQd6nt2FC5Fm5Rl3c3//E5FYvk6lvNLqcNPtZch1CceX/EHrltTj+QcfNquGGxXhohO Nc8OKv9JKpfyhGoR/THF+LilRMLu/Hs= Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a9a0c40849cso99188466b.3 for ; Thu, 24 Oct 2024 02:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729762468; x=1730367268; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C2o5Tb8yVVKQHyEzW8mTATCiOvDfyZHhWirjILULyt0=; b=Vt9sehhgqlD50Pb/3QkMo08/TLAuivwT+J4LO0XrLeZD5PKf/6lPzgsSJ4ui5U8qMo wzbwmzK4qc7PRpZV5uBXtzafmuWWh4z7xHapzabmaPbz/A4tOfUFyzfTlWXq5sdkl2aJ AQiKtAhjUq4g+wV8l7bXtrFgUkfkzNDL1w659H0tClPaKym9gFV2HBNO/7Fu9NcRjpjb sscnVYbuXwMnWrRb2vDxZv52aj9TU6h/KRN4cThgD0N+NCpCp/4uvw7Kt8zlbP0qErwJ NfdmKPKz03ZDjAawzt6FO7V7ds6w6v8aaKoITzdVB+7WW/qRbGlfiB7Zl2XByPEMLKL0 2WOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729762468; x=1730367268; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C2o5Tb8yVVKQHyEzW8mTATCiOvDfyZHhWirjILULyt0=; b=c/w9CDau3LTZlxFmZiZnJW9o5cfaodjA7EUazz4KO2be7BemKHq/nLJbeYP4oqpTek Nd+wrxy/iSxnS5WnRnmZ+Wr4a+DMQw6hmqL4ffjbBdF0uwBKlyhRH1sh/8GggQtb8MWJ jkOX2iOnugEgVgljoDPFabSH0MqFB4iaF2/xKls5MtaJBO6Rs9B1l7iK4GK58Sq49KqJ nVNqNp6Pu1/aCT/7L96lkzLMTE7U7MFp86XcHlyZp7GXa2N6r9eZ//lonDOjx0Wu1xJU QUnq0ngxB46mYdjQiqL/MvzXusEonaEYUiHSsfh+r9zO5fAf9hXtG7pLOqiHMW2IJlCo lSEw== X-Gm-Message-State: AOJu0YyHzMG/RZfVnaawTh2YJgbWW/d0Bdz0B/7IMC+VTcKkd89C2+M6 TqvTVT3FcozhHaL3Q/ToPyFjL4UJAzhQLQeUy440fIihHypPJwCb X-Google-Smtp-Source: AGHT+IEJPfjlpWqXX2mvUe55301VSJNiOQAt1iwpMaWkRaxRe+K7I8xBEPJyY/8COkuEIgbzlsopcA== X-Received: by 2002:a17:907:7d8e:b0:a8a:6c5d:63b2 with SMTP id a640c23a62f3a-a9abf8759a8mr550520266b.18.1729762468201; Thu, 24 Oct 2024 02:34:28 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91598f05sm592504066b.196.2024.10.24.02.34.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2024 02:34:27 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH v2] mm/vma: the pgoff is correct if can_merge_right Date: Thu, 24 Oct 2024 09:33:47 +0000 Message-Id: <20241024093347.18057-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Stat-Signature: ohyds65a5fyc6eii9j8t53x9go1ec4jb X-Rspamd-Queue-Id: 371018000A X-Rspamd-Server: rspam11 X-HE-Tag: 1729762435-318955 X-HE-Meta: U2FsdGVkX18XkGqvfFwfzmy8eO4UocBNitsA36yTeY/oIbDOgg4fHlFz8PTU6PBBPMqpRRDT/7YzY88IzNgWGAAKPSUntn024LlSKSMwRu5mVgf6IWNsp8jJ6LyQ426etd2Z/YdaVUbZ50xlk8wbJhgKDzb5eOBVDVeAuznihLQaIhVGQYsrVCc4UqahKIxWoMddFvagfhRw3Y5/iMDV1PVVbWMPnXlb0ULP7ecVYDgY4mgZM3jlHSVgXpqEBUFH9FVpwccD6MTrSMsFu9s0CBgpr9oAYFX8UkQKaIaTZZy4q2q66SfTgq369T+Y9SxEYQ6yUdk1OpsFrhsWVBsGT7U26oNBDqNqaW2ss2SyfI7cCMtg77BtLcN5gSPpwFt1IWjssqz2nK6nLyEjW2uJg88PlsmM0JlGSNKUC9zdFg6JhME/ZK/0Bx6/Z6dAELgb/ggm04eIhr5fBnT+x5id7PpqcHGAZ7vBkKBu8vZMOxvGbCnMe+uJW60wT6Jofj5J7iQhnbTsPaVNjvRuL7U73WJtkw4ItO/15+miI9HkxGvcMuiRDGFz8XHtIcCJ9esKKJj824LO/gUofOsNOvyvBk+w2wlrqxP0P6uZ5beYyaqRaBefl4ojOYIP26Z6ZTyhf0F7VoGOYiGv+rt691CwA7r7v7fbkhFD+Pm6gfaQMX6mFOlwRudlEvQ6guB7ujXavDPT+5KIc5cqkKESgHmYNCDUDApjzAQjrfIQs/T/DonUbFenWbpK0o8hqeb5kXsmR2Tz64xbjoWrRqhX3uO4tHaIv+kJHpcy9mshbj5QN3BFYJRcxORnEhyf7FllbfzTtiIKbxMlTqJdO++HTltlBhXL3QDKN5oSbuspKEn5pGHwQOvzTo84HZr8ZHdzfMzFmkvNFL5cLtWgz7fkSBmPqi8xFRq+U6RS9eQxHBI59QblTuQZ3RaGyA+J9U6rfxfe6oE0djfuGHG5sL88kk/ qDQUQCfh SrnihDxQxVwkrsizN9fABwsHsKkm5lPRRcHRbyPNtGWcf74RVpHNvzSb9TqgVpMCSu5WAD+wOY7rBWdI8mrj6/6nvb1vVFAihIBSJ54HL7KF/2IDIqI9KhPvEhhdzB6i0XJzDUrPACQUHRX+IXtvEtlayCzLZpoC9eUeoc7UJKtkf4pwdAnA9wOiLu5xTqOUNB1YjrHbS1sw8v3FNEhui96HvxJclsPm9IY7xfOI+Q9FLHcONGAjABGTMSadYYgAv59rDouVtEd18E2FXfAoAxquiCFNNyeD6/+wn2UE1uSEa3I7NZLn2kzYzbu2WeErNCmh5i3WPRlIUFpeddKC4/sim7ShE4TrC2CB3l/+C5ZFi2kgy/1a96k1dhaLKYTmZ++RPTskjLaCPckn2AcELF0gBrVeGUXLoI85Y2JVVNr2TedgkW1E21VhHQjfsbmQZgFQ4z5eRQZ7nkwO9URzp+wybpTzYc/Vt7kr+Fg3mKAUVRLE8Uy6iYWzgz/FRzcbOs4er X-Bogosity: Ham, tests=bogofilter, spamicity=0.000269, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: By this point can_vma_merge_right() must have returned true, which implies can_vma_merge_before() also returned true, which already asserts that the pgoff is as expected for a merge with the following VMA, thus this assignment is redundant. Below is a more detail explanation. Current definition of can_vma_merge_right() is: static bool can_vma_merge_right(struct vma_merge_struct *vmg, bool can_merge_left) { if (!vmg->next || vmg->end != vmg->next->vm_start || !can_vma_merge_before(vmg)) return false; ... } And: static bool can_vma_merge_before(struct vma_merge_struct *vmg) { pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); ... if (vmg->next->vm_pgoff == vmg->pgoff + pglen) return true; ... } Which implies vmg->pgoff == vmg->next->vm_pgoff - pglen. None of these values are changed between the check and prior assignment, so this was an entirely redundant assignment. [lorenzo: rephrase the change log] Signed-off-by: Wei Yang CC: Lorenzo Stoakes Reviewed-by: Lorenzo Stoakes --- v2: rephrase the change log per Lorenzo's suggestion. --- mm/vma.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 4737afcb064c..fb4f1863f88e 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -915,7 +915,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) unsigned long start = vmg->start; unsigned long end = vmg->end; pgoff_t pgoff = vmg->pgoff; - pgoff_t pglen = PHYS_PFN(end - start); bool can_merge_left, can_merge_right; mmap_assert_write_locked(vmg->mm); @@ -936,7 +935,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) if (can_merge_right) { vmg->end = next->vm_end; vmg->vma = next; - vmg->pgoff = next->vm_pgoff - pglen; } /* If we can merge with the previous VMA, adjust vmg accordingly. */