Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1785973iol; Fri, 10 Jun 2022 15:12:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmnEQYh8QPjKJ3aumSgNCSWk3XDyVxENV75ZTffyz9nPjdmQtklxa3vzccIIT1bkVikzpW X-Received: by 2002:a05:6402:40c6:b0:42f:9ff8:62f8 with SMTP id z6-20020a05640240c600b0042f9ff862f8mr42781108edb.95.1654899122770; Fri, 10 Jun 2022 15:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654899122; cv=none; d=google.com; s=arc-20160816; b=Pur+Pnak5vuOJkbVhuImA8viO7KS8vFbB0o9taMsHBdtOqsYQWwrDp8bYLxe1BX3pL 0yJKU9cmwtIb5/GjnzRK/O29ATvhXJbHuWYeeQNMpa6BYNJ8OzyNCPe0D3Y6Sm80THOj bGnXnj7euOTs/Y7Ff43P8IP8T6iZpCoj6Vfo2QIbs6vqAGUR9JuTZqA5CSxKBymHhX4T nqC3FHyNWSiInOLKtFErhUScWxJ5bwWLe5Qq9hvqMNv6B7MUE6FNeeBOQH7GksH3s7hk DdFZeNsU4qvs3H+oUhVIJdgvzaW+AQNSXDpyDtpqoDIIzDSuGgb9NrTItgx+RPZOh4IT nGBw== 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=hcHzsQVZ+PTFSV9X4stAy+tj1JmFLmJSZcQbEdxANTg=; b=wzH8eyDvb3CxTKrSrnkFVsFem5Gf20nLRjyMDR6IvzQ2pW0ydtsQfAdMFrTXqnG29c egltJthvMjmSZR/1Y9Jx0PwxCFxET98waQnm1+CIKlbj+qqjBYZGYNEgwAPgO49j4RH7 gwGeDN9fifuVI71qX54Mz49LFMXMrG2LsRw27UKtdx+u9S5lAbKe1XhQ84Xm09ugIHZe OHsX3My15RqjcoLTSZF1LPksY+i7ASP3OdwOQr+SO+GEzKGahGPgssuRu1yiEQhH9wbZ x0S3FUS0inoj3UBKQFzHpiaGvEX0jLUlHDCEo8rQJ9DKlFP9FYgYTAG9Q8IN/NNihGX9 pIqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ArwMa9bZ; 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 x6-20020a05640226c600b00425bb1f4712si474299edd.103.2022.06.10.15.11.09; Fri, 10 Jun 2022 15:12:02 -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=ArwMa9bZ; 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 S1348626AbiFJVYt (ORCPT + 99 others); Fri, 10 Jun 2022 17:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244326AbiFJVYs (ORCPT ); Fri, 10 Jun 2022 17:24:48 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B6981E4BDC for ; Fri, 10 Jun 2022 14:24:47 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id t2so279457pld.4 for ; Fri, 10 Jun 2022 14:24:47 -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=hcHzsQVZ+PTFSV9X4stAy+tj1JmFLmJSZcQbEdxANTg=; b=ArwMa9bZf+r8xebzbmSfcJnbMlpoqRyzcSgvj7aIl8Q4FjIUw7aXaf38oXRlRSn7nR Jz898ErOjc0pJrCZEZMVBKGoR3C1AdzLDeXHhUZh86b24KW7czKHTssyDKE8LjkoujJU gaZxcgqe82On1qlRiuM4PNX+9W2XHJ/eIi3YMMoliaWGZXaLn8b6x4IhHMDyo+esBaNM l9XuoowBf0U8oJM+I0zVZGYfezI0mMNz3uT6LemGDhOZwVWLNVbH3Mm/cQs8kHcGJXtm V/HLKcHwguRzsTFMvHpaT4XobPXwc57PkkUzh8A88+pMeLItBkhOueNsP/exglZXyPQS IDeg== 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=hcHzsQVZ+PTFSV9X4stAy+tj1JmFLmJSZcQbEdxANTg=; b=6+o5kQZWEPRblNKz5U3ZCIjuVIk8pJR1h8ZXQVRjHLliQEuMvoKDv+1VqFNjWW/rpd Hxiilq3VdNc4Qm0z8mTwX967m6RmY50GQVhvTBkDu9MAiqaMiJ6JRWRSaU+bBxD/gDHi AJtbxuRIG370s0QX7bPMXerkar0CCXqtTk+Ct1uDg0xwQdo3AZ2bPDgUBW8pvIv0Eo1f t88kZOR+06FmImb/Viv3EcOzKl8qeQoEhUhhyy0PsUTSkCXlgs5BZoQJf4Y7HeLDRPet 82JEm9UpXSeMfOj8YnAKPNgmIwW9uUNKVSJqDk1Ig/ZVgw70vJtn1GA6hTnN8KVK3HLZ zAjw== X-Gm-Message-State: AOAM533H0qux4EwjaWtDSIY50ZZXkIn7e5vKFRm1ewb3p95tRSFmKP1l 4E23b6bKg/CHqaVxCO9AMTgyc7YVXlkhTOlrokM= X-Received: by 2002:a17:90a:de15:b0:1df:63dd:9cfc with SMTP id m21-20020a17090ade1500b001df63dd9cfcmr1703274pjv.200.1654896286440; Fri, 10 Jun 2022 14:24:46 -0700 (PDT) MIME-Version: 1.0 References: <20220606214414.736109-1-shy828301@gmail.com> <20220606214414.736109-3-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Fri, 10 Jun 2022 14:24:34 -0700 Message-ID: Subject: Re: [v3 PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper To: "Zach O'Keefe" Cc: Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , Andrew Morton , Linux MM , Linux Kernel Mailing List 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 9:38 AM Yang Shi wrote: > > On Thu, Jun 9, 2022 at 5:52 PM Zach O'Keefe wrote: > > > > On Thu, Jun 9, 2022 at 5:08 PM Yang Shi wrote: > > > > > > On Thu, Jun 9, 2022 at 3:21 PM Zach O'Keefe wrote: > > > > > > > > On Mon, Jun 6, 2022 at 2:44 PM 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; > > > > > +} > > > > > > > > First time coming across round_up() - thanks for that - but for > > > > symmetry, maybe also use round_down() for the end? No strong opinion - > > > > just a suggestion given I've just discovered it. > > > > > > Yeah, round_down is fine too. > > > > > > > > > > > > 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)) > > > > > + if (!transhuge_vma_size_ok(vma)) > > > > > return false; > > > > > if (vma_is_anonymous(vma)) > > > > > return __transparent_hugepage_enabled(vma); > > > > > > > > Do we need a check for vma->vm_pgoff alignment here, after > > > > !vma_is_anonymous(), and now that we don't call > > > > transhuge_vma_suitable()? > > > > > > Actually I was thinking about this too. But the THPeligible bit shown > > > by smaps is a little bit ambiguous for file vma. The document says: > > > "THPeligible" indicates whether the mapping is eligible for allocating > > > THP pages - 1 if true, 0 otherwise. > > > > > > Even though it doesn't fulfill the alignment, it is still possible to > > > get THP allocated, but just can't be PMD mapped. So the old behavior > > > of THPeligible for file vma seems problematic, or at least doesn't > > > match the document. > > > > I think the term "THP" is used ambiguously. Often, but not always, in > > the code, folks will go out of their way to specify "hugepage-sized" > > page vs "pmd-mapped hugepage" - but at least from my experience, > > external documentation doesn't. Given that THP as a concept doesn't > > make much sense without the possibility of pmd-mapping, I think > > "THPeligible here means "pmd mappable". For example, AnonHugePages in > > smaps means pmd-mapped anon hugepages. > > Yeah, depends on the expectation. The funny thing is I was the last one who touched the THPeligible. It seems the document needs to be updated too to make "pmd mappable" more explicitly. > > > > > That all said - the following patches will delete > > transparent_hugepage_active() anyways. > > Yes, how I could forget this :-( The following removal of > transparent_hugepage_active() will restore the old behavior. > > > > > > I should elaborate this in the commit log. > > > > > > > > > > > > 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); > > > > > } > > > > > @@ -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) > > > > > > > > Likewise, could do round_down() here (just a suggestion) > > > > > > Fine to me. > > > > > > > > > > > > -- > > > > > 2.26.3 > > > > > > > > > >