From patchwork Mon Jun 6 21:44:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12871108 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 19F31C43334 for ; Mon, 6 Jun 2022 21:44:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3D506B007B; Mon, 6 Jun 2022 17:44:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CECBC6B007D; Mon, 6 Jun 2022 17:44:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDBF18D0001; Mon, 6 Jun 2022 17:44:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AEB626B007B for ; Mon, 6 Jun 2022 17:44:30 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7933420B80 for ; Mon, 6 Jun 2022 21:44:30 +0000 (UTC) X-FDA: 79549140300.18.CDDC6D8 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 336958002B for ; Mon, 6 Jun 2022 21:43:47 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id b135so13746445pfb.12 for ; Mon, 06 Jun 2022 14:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ij7n7UZO/IK0zKEVoAHKDokBQE/6XWgjwPeS6gPTqcc=; b=mXJ/hahxbI7vbEPKM3HNI31LOwv12MOVMykwZIF/4WcDnhIo7yCNxtwhCyA+9ateh8 /dsaYwTgy+aYi1g7b3kCczzNJ+WEAy6PcjMcJ5J0IiDz9N71++VS+nAfh/2zpRkZHRfa vYvtioaXpeUvymXxTzMCRSVMrRPyXiSIYuL1uN7AZNHMXqfLKTCTvXDqHwZWqahHfM2L WCDWc/QOyZDpHyCDtkPuRhYal0AaWB8/j7KaKcBGmN9/a5lpVSIJnaHwWII2HPckBuW7 rl6/VYaSW5bRJ2ZinxJHxIyok/ClC8cfp/QXquPk6mOoO7jd8h/jlQpaGDZwA+AlTVPK vFDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ij7n7UZO/IK0zKEVoAHKDokBQE/6XWgjwPeS6gPTqcc=; b=uhPORWCsdcgUtm3Oh8Ny696IEVhjg0M91uKcyKMi5e2lTEsX54HQ3WK89lB/1StdqO NOgAmA5aTu2+ozLXCwYKyUzvxguM3eNf42CrqTCQdhQ9IzhcrCMOvg428ro+uCIAg8rm 1zCyQoxYHl664NCxnOkZhRI1zmSvMtoWKc2M7FemB5HFN3ntHsHqdYk7xHS2xDtJ4Q3d Suha7ULRwfeHuKDhOT9QM/sFE8o4apt+KvnDXaIhCfTHJKpfGKBjH84Sj5pth7u8NUZU f2eh85rkUd0km3UxYySQpJKzTDL5/ZL6LV8FYaiJftaxnzlpSsd0futEMKmHQuQQ+RXe 8KpA== X-Gm-Message-State: AOAM53052igJBSOziEjRCS7tkSZNpy2uICQswD5iBgBAdFuDlzLWGSv/ 5QRL/K1ICT+1+R1U08c+/18= X-Google-Smtp-Source: ABdhPJzMLSIncjP6QHixKNI/DAPcwxVzDs8Kf+dHw2xn4cBNcjVPbSTe/tA+bImKxTtxSNxqvHYUlA== X-Received: by 2002:a65:4907:0:b0:3fd:bc3e:fb0a with SMTP id p7-20020a654907000000b003fdbc3efb0amr6869220pgs.123.1654551865142; Mon, 06 Jun 2022 14:44:25 -0700 (PDT) Received: from localhost.biz ([8.25.197.27]) by smtp.gmail.com with ESMTPSA id a4-20020a170903100400b0016397da033csm10881675plb.62.2022.06.06.14.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 14:44:24 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code Date: Mon, 6 Jun 2022 14:44:11 -0700 Message-Id: <20220606214414.736109-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220606214414.736109-1-shy828301@gmail.com> References: <20220606214414.736109-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: aehat14npackcqd6qwaxnd1ekhngyfws Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="mXJ/hahx"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 336958002B X-HE-Tag: 1654551827-787565 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: The hugepage_vma_revalidate() needs to check if the address is still in the aligned HPAGE_PMD_SIZE area of the vma when reacquiring mmap_lock, but it was open-coded, use transhuge_vma_suitable() to do the job. And add proper comments for transhuge_vma_suitable(). Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 6 ++++++ mm/khugepaged.c | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index a8f61db47f2a..79d5919beb83 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -128,6 +128,12 @@ static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) return false; } +/* + * Do the below checks: + * - For non-anon vma, check if the vm_pgoff is HPAGE_PMD_NR aligned. + * - For all vmas, check if the haddr is in an aligned HPAGE_PMD_SIZE + * area. + */ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, unsigned long addr) { diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 7a5d1c1a1833..ca1754d3a827 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -951,7 +951,6 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, struct vm_area_struct **vmap) { struct vm_area_struct *vma; - unsigned long hstart, hend; if (unlikely(khugepaged_test_exit(mm))) return SCAN_ANY_PROCESS; @@ -960,9 +959,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, if (!vma) return SCAN_VMA_NULL; - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; - hend = vma->vm_end & HPAGE_PMD_MASK; - if (address < hstart || address + HPAGE_PMD_SIZE > hend) + if (!transhuge_vma_suitable(vma, address)) return SCAN_ADDRESS_RANGE; if (!hugepage_vma_check(vma, vma->vm_flags)) return SCAN_VMA_CHECK;