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 16423C433F5 for ; Mon, 23 May 2022 18:12:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A32816B0006; Mon, 23 May 2022 14:12:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BB7A6B0007; Mon, 23 May 2022 14:12:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85CB36B0008; Mon, 23 May 2022 14:12:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 73A926B0006 for ; Mon, 23 May 2022 14:12:33 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 45A6635121 for ; Mon, 23 May 2022 18:12:33 +0000 (UTC) X-FDA: 79497802986.09.DFBF6C7 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf30.hostedemail.com (Postfix) with ESMTP id EEB8D80028 for ; Mon, 23 May 2022 18:12:04 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id j21so14137160pga.13 for ; Mon, 23 May 2022 11:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KmemOOUEaDn+3pBgS68jUUDL7N3enFtsy+GPMY+Vi6U=; b=n2tQcL8/YL1f/GBjKWuCzRSTzfyyvoQBKFNBDB+xRgnFzWa4d7UTVk37vTevUvPZaH e5XQ+pAHnWvmnrApZzOvvjVtlikFGEhVHjPTCBblSSSRmhp3kA41OMO8ATckAMf7XMGm cdck697O08Ae7rISm8i6/vBOT1Glq6HSPjcexp4qUwbcqSJ6JQ55E9ttT74IRp6OFtFE 40+R6gm9X9eT3+xsv791DFr1ZBu+AVqv3QyO+BuGH3J1Qr8BMV88GnnWZR3aiUHxvsS8 VVPGWN3FZpzlOPxgKvgGP4B0XN8tNVyg9VCudGxUdS1HMyc4z9bJbOQMS154YkQqsCQP gw6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KmemOOUEaDn+3pBgS68jUUDL7N3enFtsy+GPMY+Vi6U=; b=T/UeD/Jz42Xs+61ZRc2opZlAZRE/Xx2tNqLop9L5tle15loRN8ggoqokp/XZeozVKf K0rfVN89WDAaC1MB5lDwL2ZWNos7U0zzItXrCcpJ9SuBGlSjlANWyYK+uGb65KQN9/r0 TbcJGJXomP7AIqhWeCSkeoGy38RZOT/wwyGMDrYh3NcwRVQeCl/Ua1dR7YVN4sF2jHi7 brJtnizfrSxV7VopLySMgHfd+Kal3tZUWllXmWC14fdQz3oEXk40jzXC8TEnAQKoPMUy Y05OViuaKdgUUJockCrgAR71aQ98gc1TZ5l4Ddz7X4UVT+3A415Sbtwz++8yJoyS+P7C CKmg== X-Gm-Message-State: AOAM5332I7xdZAhSb3v2V8mrXy9S6RXe0V+7l5SJh0Be89xjuts/FSbi VyoRtl/GT3m+Ti+A5KPoIA/Cvg3IeAMUWHzE+PE= X-Google-Smtp-Source: ABdhPJzBk+TiEQTYc5wMTDULGuOuR+VzwNW6gAFLt04HMW9UrLp26iJOSpNAUq+kU6cs7Ut54Kc3A8DGPEwpw0gryHg= X-Received: by 2002:a63:fc04:0:b0:3f6:4b2b:9d36 with SMTP id j4-20020a63fc04000000b003f64b2b9d36mr18715962pgi.206.1653329551659; Mon, 23 May 2022 11:12:31 -0700 (PDT) MIME-Version: 1.0 References: <20220520211605.51473-1-shy828301@gmail.com> <20220520211605.51473-3-shy828301@gmail.com> <20220521013954.2695-1-hdanton@sina.com> In-Reply-To: <20220521013954.2695-1-hdanton@sina.com> From: Yang Shi Date: Mon, 23 May 2022 11:12:18 -0700 Message-ID: Subject: Re: [PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper To: Hillf Danton Cc: Vlastimil Babka , "Kirill A. Shutemov" , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: EEB8D80028 X-Stat-Signature: m7wtdq74r3q77whcxshezmjn7eozce4z Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="n2tQcL8/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1653329524-849969 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, May 20, 2022 at 6:40 PM Hillf Danton wrote: > > 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. It should not change the semantic even with 4/7. The old comment says "The addr is used to check if the vma size fits", so the purpose of transhuge_vma_suitable() here is used to check if the vma size is ok or not. > > > if (vma_is_anonymous(vma)) > > return __transparent_hugepage_enabled(vma); >