From patchwork Thu Jun 2 18:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12868045 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 21172C43334 for ; Thu, 2 Jun 2022 18:22:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CD516B0078; Thu, 2 Jun 2022 14:22:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32CC36B007B; Thu, 2 Jun 2022 14:22:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C9696B007D; Thu, 2 Jun 2022 14:22:11 -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 01A2B6B0078 for ; Thu, 2 Jun 2022 14:22:10 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id B77F4613E6 for ; Thu, 2 Jun 2022 18:22:10 +0000 (UTC) X-FDA: 79534115220.29.2234805 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf30.hostedemail.com (Postfix) with ESMTP id C234A80060 for ; Thu, 2 Jun 2022 18:21:34 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id c196so5438667pfb.1 for ; Thu, 02 Jun 2022 11:22:10 -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=IpMzaIeFOsyZY5RirkJatHmncMuZPPqDAIcHJBZPIVp7G09X1sx9pTdtZ7RdyauoYu CXIXH82Up2DBdc5z5bS621MpSvaQAGhEYPODX5fWKNzCB4RQkpwyu2MPYjFnd6ml7115 Nwn/88YW4mU+XngygZGDRSvug40didfLWbcdd349F5mSLAuviIyjwBV6PRONP4z47m0x FPA/CgZSc2y/sQh3LXmJ9s9TVq2jz2mvYgIZe77eWdrLNR2mbFcu5BYQ9WCsR1D/zQfL 5PPDk7dZs5AT4EQhjDnYpA8iC6vJaBbnXsV2xL/9ZDOr3dh5+4P3HEM8j12kvAV/h3wN 5ysA== 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=fAayFfC6aJwMnkaD1ATzEa5zt2yVdFMVIFPFhgCFfGAy5RjdwzvEXV7ed+ftelNxSf 63W+liLOQxvhJOCthvMavDaHW/VVhpZlPsykzfDSn3FME7r8dgn2gpYozgRmwfPFnfjr dNP73cl9DPvqukh30KLYNbMcH4D+LFNVt4tQIZf315Zle0200kdxAZIY6SEF4ZyW25wc l59b08MzPhaD+DN99Bv9S/h4xM4ng0Ylw1mJEUCb0XDY7zQ+4TqzkhvXjOzS6YPDDDb1 cVhYbJwCftg+YvWQ4vFhY7y2+ZDJk54eHTtGyzZ63oFi+6uhprIvufp/5QAEwdd0iwJk kBLg== X-Gm-Message-State: AOAM533xm55Ww/EMyMtyEfVqskvR+Iwu36XkbAfZFwx6TPuJ2/aqWocz lcyV5QmGzVzpE9spmHPfHzk= X-Google-Smtp-Source: ABdhPJyLtH0blR5AqKJCr/dkM/hu+mh+rj2O4bSVPpE5tGGO/EHu3X2wtkjB9koaOEl7+HMO4L+bWQ== X-Received: by 2002:a05:6a00:179e:b0:518:9e1d:1cbd with SMTP id s30-20020a056a00179e00b005189e1d1cbdmr54800149pfg.12.1654194129509; Thu, 02 Jun 2022 11:22:09 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id t10-20020a1709027fca00b0015f2d549b46sm3866779plb.237.2022.06.02.11.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 11:22:08 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code Date: Thu, 2 Jun 2022 11:21:56 -0700 Message-Id: <20220602182159.248387-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220602182159.248387-1-shy828301@gmail.com> References: <20220602182159.248387-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: zccydj9d5pk746canhcbugxhs7fzrets X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IpMzaIeF; spf=pass (imf30.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C234A80060 X-HE-Tag: 1654194094-449109 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;