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 AE262C43334 for ; Fri, 10 Jun 2022 16:38:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 276BD8D00C8; Fri, 10 Jun 2022 12:38:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2268B8D00C1; Fri, 10 Jun 2022 12:38:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EF118D00C8; Fri, 10 Jun 2022 12:38:23 -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 F38CF8D00C1 for ; Fri, 10 Jun 2022 12:38:22 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id C720C120379 for ; Fri, 10 Jun 2022 16:38:22 +0000 (UTC) X-FDA: 79562884044.15.C43C7CD Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf24.hostedemail.com (Postfix) with ESMTP id 5891618006B for ; Fri, 10 Jun 2022 16:38:22 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id gd1so24467534pjb.2 for ; Fri, 10 Jun 2022 09:38:22 -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=dpTRX66gSZYkc1etlSX8TA/uq6NReqtWWcPkMVe7cOE=; b=BqN2FQMgN2l9mnU0AVl5BXVzTTuplUoAMIAqQg0lHQb0YPdPU14ytfIhlZG8CMZ2Tm PT5/R6AEqMEHAQqaKQ1wUHF7G1SBgCB/PtNj1HtjC4kPP5WidWXJJgDVtlEsAio3G18g Wpyl6pErg7HUAheqEIg+YOluBVa5pRpxClTsHEZ9e5W1uHWbypQ8RbDyaSU48IsGI9HJ Pq7KmFW8orMamR7hTJCZcfMcy7Ce3JsA6ayQPaz+RPTTx00/NFJOdqxC75bAdl6mkvN9 7xoc82eXNLXkWrtV0PgBTuaMo/8D9c2yTeoNnwsNziK6dTxt0cXixWo3xbM6ZlrQM4nZ zQIQ== 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=dpTRX66gSZYkc1etlSX8TA/uq6NReqtWWcPkMVe7cOE=; b=0/54ng9GfmqZs0FSzJT65DY4sNPMD/znClut9w4R8gXoPK0haZAoFmxSwknJ5+2Ke0 /cFeQQ5I/20U+8R1zdhfvU/wT4i6+nqzX1SyMZbv1QVaYd+Vun4Cgnmf4LQx+F9IIhxA Vt7fjrL0V0KOBh4pWNp8jDkpTL5pOh92QK/X+iApAdX+q8NNsVImykEFP8ErMPgo52Lh /O7USo8p7SvTb0G6QpL7ewZkJJfeC459VbAzNv5t0tUmfboFIf3ErljPmjgiy9LHWkvn PQ0y8nsGTNHkmNhp7icEIflp1/c8n8cfb2ENY0HM1ufpxqfuPIWn5Q9uiCI6Y4lTHc2x bUqw== X-Gm-Message-State: AOAM530tbyrURQGpq9wd8Pzh15cU6JPjt08P8da8K4Rpyn6P0yuHdL3g VzV0BegVDCOJoRoOBtb5pfyHUzAJ9C5JFF3zKoY= X-Google-Smtp-Source: ABdhPJx+5iZXS9OXXK7nPDz0MieRvvl1XTaGp9Lqx/jFLol9ZxAtlwC8L7CHMrMVYtF85fgTF0dw9G1+8SA7HTz4Hc0= X-Received: by 2002:a17:903:32c4:b0:167:6e6f:204b with SMTP id i4-20020a17090332c400b001676e6f204bmr31417815plr.117.1654879101310; Fri, 10 Jun 2022 09:38:21 -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 09:38:09 -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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654879102; a=rsa-sha256; cv=none; b=3Yc3jd+uwPcihI7R8hVJVGlBwR8SJUw/vHkcitN5yxDm9YPARhAtSFUpkH7TDijdALTPPT QRmbD7AIvbvi1YAyQ35/4cFSxmgl52w716nMkqbPp6nz4elNlG0a6AaBLRURV2SaB3AWo9 4cl6jmZv+B2vkhe/u+5SbGVcLLZZhy8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BqN2FQMg; spf=pass (imf24.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654879102; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dpTRX66gSZYkc1etlSX8TA/uq6NReqtWWcPkMVe7cOE=; b=1lOX1OZBHA1eZmVgDOKVZqwrCODGrB7navDV7QpYWuXy8MPHiC0xJjv8xXv/IN+NTTRApO Txe9Gr9k3oig6qUdAECED5JU42KRDkI4xkmyn12pNRzsUwInsxXkqIO/aLw3F3rLE3FtII t9zgSijXqOhjBUg5kMgRD57EWztuM3k= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5891618006B X-Stat-Signature: pgi15u9q58nuphhrxpoqjumy1kiuou1b X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BqN2FQMg; spf=pass (imf24.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1654879102-844462 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 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. > > 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 > > > > > > > >