From mboxrd@z Thu Jan 1 00:00:00 1970 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 B037FC433EF for ; Sat, 21 May 2022 01:40:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FEF06B0072; Fri, 20 May 2022 21:40:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AD4C6B0073; Fri, 20 May 2022 21:40:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB64D6B0074; Fri, 20 May 2022 21:40:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D9E366B0072 for ; Fri, 20 May 2022 21:40:08 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9819A606D5 for ; Sat, 21 May 2022 01:40:08 +0000 (UTC) X-FDA: 79488044496.06.04777D7 Received: from mail3-166.sinamail.sina.com.cn (mail3-166.sinamail.sina.com.cn [202.108.3.166]) by imf03.hostedemail.com (Postfix) with SMTP id B3711200CB for ; Sat, 21 May 2022 01:39:55 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.57.134]) by sina.com (172.16.97.23) with ESMTP id 628842AE00037A22; Sat, 21 May 2022 09:38:56 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 24603854919387 From: Hillf Danton To: Yang Shi Cc: vbabka@suse.cz, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper Date: Sat, 21 May 2022 09:39:54 +0800 Message-Id: <20220521013954.2695-1-hdanton@sina.com> In-Reply-To: <20220520211605.51473-3-shy828301@gmail.com> References: <20220520211605.51473-1-shy828301@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: B3711200CB X-Stat-Signature: 3b3wwzo879d3ctqj1e589ea9dtk6r7wh X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.166 as permitted sender) smtp.mailfrom=hdanton@sina.com X-HE-Tag: 1653097195-590025 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: On Fri, 20 May 2022 14:16:00 -0700 Yang Shi wrote: > There are couple of places that check whether the vma size is ok for > THP or not, they are open coded and duplicate, introduce > transhuge_vma_size_ok() helper to do the job. > > Signed-off-by: Yang Shi > --- > include/linux/huge_mm.h | 17 +++++++++++++++++ > mm/huge_memory.c | 5 +---- > mm/khugepaged.c | 12 ++++++------ > 3 files changed, 24 insertions(+), 10 deletions(-) > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > index 648cb3ce7099..a8f61db47f2a 100644 > --- a/include/linux/huge_mm.h > +++ b/include/linux/huge_mm.h > @@ -116,6 +116,18 @@ extern struct kobj_attribute shmem_enabled_attr; > > extern unsigned long transparent_hugepage_flags; > > +/* > + * The vma size has to be large enough to hold an aligned HPAGE_PMD_SIZE area. > + */ > +static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) > +{ > + if (round_up(vma->vm_start, HPAGE_PMD_SIZE) < > + (vma->vm_end & HPAGE_PMD_MASK)) > + return true; > + > + return false; > +} > + > static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, > unsigned long addr) > { > @@ -345,6 +357,11 @@ static inline bool transparent_hugepage_active(struct vm_area_struct *vma) > return false; > } > > +static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) > +{ > + return false; > +} > + > static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, > unsigned long addr) > { > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 80e8b58b4f39..d633f97452c1 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -71,10 +71,7 @@ unsigned long huge_zero_pfn __read_mostly = ~0UL; > > bool transparent_hugepage_active(struct vm_area_struct *vma) > { > - /* The addr is used to check if the vma size fits */ > - unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE; > - > - if (!transhuge_vma_suitable(vma, addr)) > + if (!transhuge_vma_size_ok(vma)) > return false; Given the comment added in 4/7, this patch adds change in semantic. If that is intened, add some words in log message for it. > if (vma_is_anonymous(vma)) > return __transparent_hugepage_enabled(vma);