Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1571806iol; Fri, 10 Jun 2022 10:05:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfLpu/ikY/b9CcS3N9UYUNu3/ALupxdLeCoTPrmpeyl5scUUloemkBcdnZ3kU2ZyfDFn/U X-Received: by 2002:a63:ea09:0:b0:3fd:3c6a:47c2 with SMTP id c9-20020a63ea09000000b003fd3c6a47c2mr32449188pgi.242.1654880706637; Fri, 10 Jun 2022 10:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654880706; cv=none; d=google.com; s=arc-20160816; b=XblYyWnDU0OUf4yyhLPPMAisbGHd4rSBKkp2gc+sqeJ5z0Xtbo/BLeFDS1FeQ9enso dhG/RMs5FhF3T+ejprA9vGKx8ceWuty90F7xEYmjLuOY6biMj8dfGUei6IpNdS34uRm9 L7ql4xpmTkkUU9CTf17TTF5xkidonTz3MHRayQ55cCPOnr4z3PgV0kvzaQ7TlM3Xj81I nwpQ5vKG/1H+vdisj2bvivfIhjnsYB3gdDmJB4me1s+k9SPq9uTJ+lfzuSp9v+htFN9G p8Um1j8/dkWuiUXq1W9VRyhsGhNlQ6enHmUy8hVhhOtKGNh2Lna+ZmoG9S8B87CtYxy/ PTZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8vFyBrdxSbkI+mfhKuuYNpkHpuCxKZS4GtlQHUPNgHw=; b=ehOw7gGEAIKPhUK6+HhKCbRAm49civEDTxcp121uHS176MASlLf0qhzGZseyPiBPGN M5Djo1Gfk4fnKZzlFjkITzySw/JJaU5Lg/kIceSHW7uC106ZPUMuS72awzntxY9AH/21 1tuSjaxBlkcq44U1ngd6cDi5AULIfkiDiwP+kJ2SJQeFJGDzpWKX4I6vFgCGumHdwbBW 1VekcniegRshfurg6HIMXihXWjwCttVoTFZBBHyZCfOKICxPS/pYYcQB2bqBJz2hNLOI Pf2O1PQjfbWOw/h4Tr52DNbP2QtHMLPrPhDpWuh9C9z4FJdzkBLzmVgDk9FWo0Pj3Qe1 7JYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KMiA0J2I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w2-20020a170902e88200b0015f179cded2si39639444plg.118.2022.06.10.10.04.51; Fri, 10 Jun 2022 10:05:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KMiA0J2I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346290AbiFJQsc (ORCPT + 99 others); Fri, 10 Jun 2022 12:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349844AbiFJQsI (ORCPT ); Fri, 10 Jun 2022 12:48:08 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262B4B2EB6 for ; Fri, 10 Jun 2022 09:48:07 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id x4so15746213pfj.10 for ; Fri, 10 Jun 2022 09:48:07 -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=8vFyBrdxSbkI+mfhKuuYNpkHpuCxKZS4GtlQHUPNgHw=; b=KMiA0J2I/vzgsnbe9ot1ANdEAoLdqlcKhBXmL++rYc3bBaizGMuqjJ19IQ/+G2sUis kkY8drJvJC0FpP69oNtGTR+hbX/ZxE47a3/wmuTUzB3W4T2z3Ud4t4aZKZcWN9KnXj1f 04AN1IOWAxPxMXbRzC5dfe8LR8axbXznLnC3vpQ0Q9uMAsd8mEeiDFbl8d7/Srdv01I1 MQQQJ30dm8nK/kGGONxOLJ+9Dx48+QyFsg3ckpHg0JfXhw3YiCT44kGWOoISjgE06fDH pSPzu8sHlpfIlMlS+mECMTy7Lfk9rfTUPd4FFucKwLqVxe5WU49dsBXtG6H+VdtKC+FL QVqQ== 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=8vFyBrdxSbkI+mfhKuuYNpkHpuCxKZS4GtlQHUPNgHw=; b=3bTByzJb+QMQDNhjen4e3Cqemjc7DvoF7VqDz+28FETb3BeDi/0alw/Qb/svsa2AYp ihx7FzNA1ycNnrb45CYzPI4u0blcmKQrw5PN8vsJpv2OXjr27AfNHzRkdG3ijUUseHk+ Xbx6ssu8xjU5lfSReq+6L1pr0Yvj+wjDVYSreHyV1JWXdR0eEhQwVoL6OdYJCh6OUHZX tr915Ttvh6pvOXcr54ZGCvJ26lKALsqoIlf/Y1QLK+Wk+/iyd1xvOiLo0eBq+QJsGzVJ 4FhGdRGOc9YSpNspQVefI+f2qXBZuTQ0PhWPRvWNSdOklH/nYXd6BkpTqfRcondKgBdW dCJQ== X-Gm-Message-State: AOAM530WcWlC3GcwKEGGyFfNdTge0ft38uOA1yx+3uMEKCuHigIZHlrk tLOfDrcHNOuimC2/aVTrMyMea4tdGrkAX2KB1uo= X-Received: by 2002:a05:6a02:184:b0:3fc:3b43:e5da with SMTP id bj4-20020a056a02018400b003fc3b43e5damr39448807pgb.587.1654879686708; Fri, 10 Jun 2022 09:48:06 -0700 (PDT) MIME-Version: 1.0 References: <20220606214414.736109-1-shy828301@gmail.com> <20220606214414.736109-3-shy828301@gmail.com> <8ba0f470-af80-1087-4361-eacbcbc52d90@huawei.com> In-Reply-To: <8ba0f470-af80-1087-4361-eacbcbc52d90@huawei.com> From: Yang Shi Date: Fri, 10 Jun 2022 09:47:54 -0700 Message-ID: Subject: Re: [v3 PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper To: Miaohe Lin Cc: Linux MM , Linux Kernel Mailing List , Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 10, 2022 at 12:20 AM Miaohe Lin wrote: > > On 2022/6/7 5:44, 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 48182c8fe151..36ada544e494 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)) > > There is also pgoff check for file page in transhuge_vma_suitable. Is it ignored > deliberately? This has been discussed in the previous threads. The following removal of transparent_hugepage_active() will restore the behavior. > > > + if (!transhuge_vma_size_ok(vma)) > > return false; > > if (vma_is_anonymous(vma)) > > return __transparent_hugepage_enabled(vma); > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > index 84b9cf4b9be9..d0f8020164fc 100644 > > --- a/mm/khugepaged.c > > +++ b/mm/khugepaged.c > > @@ -454,6 +454,9 @@ bool hugepage_vma_check(struct vm_area_struct *vma, > > vma->vm_pgoff, HPAGE_PMD_NR)) > > return false; > > > > + if (!transhuge_vma_size_ok(vma)) > > + return false; > > + > > /* Enabled via shmem mount options or sysfs settings. */ > > if (shmem_file(vma->vm_file)) > > return shmem_huge_enabled(vma); > > @@ -512,9 +515,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, > > unsigned long vm_flags) > > { > > if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && > > - khugepaged_enabled() && > > - (((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) < > > - (vma->vm_end & HPAGE_PMD_MASK))) { > > + khugepaged_enabled()) { > > if (hugepage_vma_check(vma, vm_flags)) > > __khugepaged_enter(vma->vm_mm); > > } > > After this change, khugepaged_enter_vma is identical to khugepaged_enter. Should one of > them be removed? Thanks for catching this. Although the later patch will make them slightly different (khugepaged_enter() won't check hugepage flag anymore), but the only user of khugepaged_enter() is page fault, and it seems not worth keeping both. Will remove khugepaged_enter() in the next version. > > Thanks! > > > @@ -2142,10 +2143,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > > progress++; > > continue; > > } > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > > + > > + hstart = round_up(vma->vm_start, HPAGE_PMD_SIZE); > > hend = vma->vm_end & HPAGE_PMD_MASK; > > - if (hstart >= hend) > > - goto skip; > > if (khugepaged_scan.address > hend) > > goto skip; > > if (khugepaged_scan.address < hstart) > > >