From patchwork Wed Jul 20 14:06:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12924029 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 CD8FFC433EF for ; Wed, 20 Jul 2022 14:06:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB1D86B0075; Wed, 20 Jul 2022 10:06:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D609E6B0078; Wed, 20 Jul 2022 10:06:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C013E6B007B; Wed, 20 Jul 2022 10:06:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A72FE6B0075 for ; Wed, 20 Jul 2022 10:06:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8200E160570 for ; Wed, 20 Jul 2022 14:06:25 +0000 (UTC) X-FDA: 79707653130.20.EB6FABC Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 0C4044009A for ; Wed, 20 Jul 2022 14:06:24 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id q12-20020a632a0c000000b00419b66851e8so8248608pgq.3 for ; Wed, 20 Jul 2022 07:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7NJSO06s3TRWUOwwWKGEkKcgu74469OKtlVGQrWK7PU=; b=lihTN5FIZmm4BKH9BW6zoLNDSypmXTI4lx2hMxm4pmCPYvViIOStDc9VYW2ctlkHzk baXAgJ6fJvws8YtpoQpl5l+2qLPcPwIyU3UJqG1KKYFuViVXMrdGx21hBe0+BXWqE/BL NfYpFXRmCD9rKSju+yVFpY+RhqPA9n0UG/ta1HPKWHDrT7yD8lxyXeam/LZw/8cr+bTT cL9JwIZj26vybK7WW9R/Z8kwO80aXIwYHkWpEP10iMljbVJdB1qTmUK7LOouyn8cgFFN SbmfkhBilIoTKcB8RYVed0N0bn1Gbl9FoeeAXBRq3o90+9NnuDx5LDmhj0sTg3/8Q6Pa GzxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7NJSO06s3TRWUOwwWKGEkKcgu74469OKtlVGQrWK7PU=; b=tFYnUAhhsJb7Nbq8jTDEFDjiBNSUug7JcHPrZpU7beBEyyL7b27LpPaClQQRRo+N4K Nx3YZEP3DM2vseNY7NbdCjduIf+Oj2+BdTkMici+bS0Rr0wUG8UGpPY2IT+SORT9dlbz W/zLUC+IZ/kPrlHu6eX8hVzmFypOsy6uI1NEoRqdPfpTnHH47AJsnMeW0QE+kTkfXH8k iv9AeDTz42rfRVqtFZKvPv7FFGhhV1wXR1vcQ2mcw1gioxTCkflRLbPA1OklsZ8AYBq1 I+2pcsEOqQf6bbYs6O6pI7VDigim4VvXytjGnp1uIzipoO6AHFqyiMhk7MFAdFPMvcXe 4ECQ== X-Gm-Message-State: AJIora81beytuQO8ZaxPwbhiGM+Ox/3MIUZa3jsVFD+vXTjzjlsGqw5Q kpx18aFMykEURCf1V2j1/iC3ec85USXa X-Google-Smtp-Source: AGRyM1sAiGqSywWL4I1MBvo8Kmqz6aP+4UdYwbHe5/QZXCJHTBV7tn+UKtPve20i2aFgq52Z8z9uEPrabnep X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:da8e:b0:16c:56d7:e00e with SMTP id j14-20020a170902da8e00b0016c56d7e00emr39720943plx.91.1658325983976; Wed, 20 Jul 2022 07:06:23 -0700 (PDT) Date: Wed, 20 Jul 2022 07:06:02 -0700 In-Reply-To: <20220720140603.1958773-1-zokeefe@google.com> Message-Id: <20220720140603.1958773-4-zokeefe@google.com> Mime-Version: 1.0 References: <20220720140603.1958773-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH mm-unstable 3/4] mm/khugepaged: delay computation of hpage boundaries until use From: "Zach O'Keefe" To: Andrew Morton Cc: linux-mm@kvack.org, Hugh Dickins , Yang Shi , Miaohe Lin , "Zach O'Keefe" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658325985; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7NJSO06s3TRWUOwwWKGEkKcgu74469OKtlVGQrWK7PU=; b=qBawD4lA7WUHcrvwowi/CI2bj7fHGKGr0nbI7pHXcJGLbM0vcdDLglhojP6qfkf7T8i3EZ oFDjSHhBVMY+ij6av0IKGb9EPkmwKle2zgpikJWqFqjysRxEimJMcceSlnO+qraagt75NV ZlXykL5O8cVES6poUAwWFiP3Qm2cD/k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658325985; a=rsa-sha256; cv=none; b=xqo+1JAxJVYnnUQ7Jnadhlx7jLFm6Y6hJgCx9nBMIKvOTcEKSXLa8QZXYUzKpJV09iN9os Zd9774cB1Gqy2wvfa6IyOhJ1rkdH71ze3tYSkPg3e2SW0QFCM/kI+j0AvqxGBNNC3SHxdL JIRouEAjY0AL/pAVzP6FnC5yJ8NtWdk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lihTN5FI; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 33wvYYgcKCHQrgcWWXWYggYdW.Ugedafmp-eecnSUc.gjY@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33wvYYgcKCHQrgcWWXWYggYdW.Ugedafmp-eecnSUc.gjY@flex--zokeefe.bounces.google.com X-Rspamd-Queue-Id: 0C4044009A Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lihTN5FI; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 33wvYYgcKCHQrgcWWXWYggYdW.Ugedafmp-eecnSUc.gjY@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33wvYYgcKCHQrgcWWXWYggYdW.Ugedafmp-eecnSUc.gjY@flex--zokeefe.bounces.google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: pjg86xoqn5pamisz6p8gx9k5ukteirun X-HE-Tag: 1658325984-742226 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Only compute hstart/hend once we've passed all checks that would cause early return in madvise_collapse(). Fixes: c9d968ffd9ba ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse") Signed-off-by: Zach O'Keefe Reviewed-by: Yang Shi Acked-by: David Rientjes --- mm/khugepaged.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 290422577172..70e9d9950415 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2417,9 +2417,6 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, if (!vma->anon_vma || !vma_is_anonymous(vma)) return -EINVAL; - hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; - hend = end & HPAGE_PMD_MASK; - if (!hugepage_vma_check(vma, vma->vm_flags, false, false, false)) return -EINVAL; @@ -2432,6 +2429,9 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, mmgrab(mm); lru_add_drain_all(); + hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; + hend = end & HPAGE_PMD_MASK; + for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) { int result = SCAN_FAIL;