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 C8594C43334 for ; Fri, 10 Jun 2022 22:04:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EDC68D00E8; Fri, 10 Jun 2022 18:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49EBA8D00E2; Fri, 10 Jun 2022 18:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33E2B8D00E8; Fri, 10 Jun 2022 18:04:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 239DE8D00E2 for ; Fri, 10 Jun 2022 18:04:07 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F38B235DD6 for ; Fri, 10 Jun 2022 22:04:06 +0000 (UTC) X-FDA: 79563704892.21.8FE0372 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf01.hostedemail.com (Postfix) with ESMTP id 84CA640086 for ; Fri, 10 Jun 2022 22:04:06 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id t3-20020a17090a510300b001ea87ef9a3dso598675pjh.4 for ; Fri, 10 Jun 2022 15:04:06 -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=/rGGdkS7QIkZ/YCjLiLrVaJUh/NYGf+CirgaHxRAw1o=; b=bx0/jpmm8PwMlHjxJtJzWg1ppwMuBsDHCEaaLOM8ybI967KGbvPJa/caI3MUEQIzBm /ceuFce/3lGa2eY0688qj1ACzdER9XJ6+pw8sZGwa+1qd+7Plu7oNF5FerOq+3QkEOy6 wsBlBiRIf/qpoBYeN96GS45AntsJTbZanKztZZ8MXSQJaTie6YdpTqlVVTMrMu9z+8C1 e/LHMdznxOcsaZuTj45gvPTxir9HxG17harU+KN4CsklbShthHkPH+tIQI4fnCQbGwHg +DclOcQqguTf79ELAgN0vgZc1BDnuYuobpX9Mr4ZJje1yiqkCK6S2gaEzCYsvprgYhJ6 pdnA== 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=/rGGdkS7QIkZ/YCjLiLrVaJUh/NYGf+CirgaHxRAw1o=; b=SwvWfnlO4h7c7kWhMS2uGwsEeJJw2q7/lf7qiwyeT4Mj1s8s7Wd6zRRhOXH0zCYOlT GFHGbIxKZFRIcwikSP0N2A3gBNq9rAcGBZK/MdLkTfdzPkPfhe3TnAqokTY4UV/ZpJDD FJwfFb8rHYzzYQITO2ujuCV3tXt0SEK+46k7MMpZUPbXeyHWgDa95mZd0Msc14y02Us7 Xj5XyqGhSGtWkWZZ9RiYqONeQ5Sang6JIXmuaQRCp5PPdxBSJwT1pdYz9mVM9tk+DMK+ pmWm6edzkWFi8+9Qexitx4wLU8iUOvQZD5jNSHyNcn738gHj57cKY54doLSh3PSljBAr 1eRw== X-Gm-Message-State: AOAM531cMhEcWC3VY+pXZ/AppcD1w0H2D5rx7pwqawjTSdtEYEwoEjV/ 66kgzCyVB0anqQWDopLmAE9Ks4GncvHMnoiVBbM= X-Google-Smtp-Source: ABdhPJwfb0XwCdX/7UY7AbXIY2nJKHZ9uPELcxWmuyWrsGuTEEOLeMFehW8z4Q0bEWaNcq3HCwhxixZLBrk52oW1Qxo= X-Received: by 2002:a17:90a:de15:b0:1df:63dd:9cfc with SMTP id m21-20020a17090ade1500b001df63dd9cfcmr1848430pjv.200.1654898645517; Fri, 10 Jun 2022 15:04:05 -0700 (PDT) MIME-Version: 1.0 References: <20220606214414.736109-1-shy828301@gmail.com> <20220606214414.736109-5-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Fri, 10 Jun 2022 15:03:53 -0700 Message-ID: Subject: Re: [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654898646; 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=/rGGdkS7QIkZ/YCjLiLrVaJUh/NYGf+CirgaHxRAw1o=; b=J42n0XbFvDKsUtxiFl5F9pmYR9tUISsV9fdkFTQbXIIPA1/IU5IzdlJNNXNuQ/GRIdZdnE yS15vd6GBHLF8uxPQEQ5MW3orpfdUSUKlSmIVBPye6Pmw0y2DM41foAHpG1IjASoPrbWki ioVpklzhZza0zX2y4+1/dABc8CXVdgQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654898646; a=rsa-sha256; cv=none; b=BubGq25eMmArs/G4J7n/TcsysySFJjlEYlt12jdV8jzRrrZPP61j8WikbEyY3bCvsunnPr xLrFQwCatziz43s740tJotTopW8ovSXUH134sNlu6t2LyHPF58+lPak2inDfcHqQSNJEFm oRV+Z6Z16gULpzBeZ1sJACseUR6KtdA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="bx0/jpmm"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="bx0/jpmm"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: 4wryt6o9fygstjfpm65itu38oi8wfto9 X-Rspamd-Queue-Id: 84CA640086 X-HE-Tag: 1654898646-890179 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, Jun 10, 2022 at 9:59 AM Yang Shi wrote: > > On Thu, Jun 9, 2022 at 6:52 PM Zach O'Keefe wrote: > > > > On Mon, Jun 6, 2022 at 2:44 PM Yang Shi wrote: > > > > > > The hugepage_vma_revalidate() needs to check if the address is still in > > > the aligned HPAGE_PMD_SIZE area of the vma when reacquiring mmap_lock, > > > but it was open-coded, use transhuge_vma_suitable() to do the job. And > > > add proper comments for transhuge_vma_suitable(). > > > > > > Signed-off-by: Yang Shi > > > --- > > > include/linux/huge_mm.h | 6 ++++++ > > > mm/khugepaged.c | 5 +---- > > > 2 files changed, 7 insertions(+), 4 deletions(-) > > > > > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > > > index a8f61db47f2a..79d5919beb83 100644 > > > --- a/include/linux/huge_mm.h > > > +++ b/include/linux/huge_mm.h > > > @@ -128,6 +128,12 @@ static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) > > > return false; > > > } > > > > > > +/* > > > + * Do the below checks: > > > + * - For non-anon vma, check if the vm_pgoff is HPAGE_PMD_NR aligned. > > > + * - For all vmas, check if the haddr is in an aligned HPAGE_PMD_SIZE > > > + * area. > > > + */ > > > > AFAIK we aren't checking if vm_pgoff is HPAGE_PMD_NR aligned, but > > rather that linear_page_index(vma, round_up(vma->vm_start, > > HPAGE_PMD_SIZE)) is HPAGE_PMD_NR aligned within vma->vm_file. I was > > Yeah, you are right. > > > pretty confused about this (hopefully I have it right now - if not - > > case and point :) ), so it might be a good opportunity to add some > > extra commentary to help future travelers understand why this > > constraint exists. > > I'm not fully sure I understand this 100%. I think this is related to > how page cache is structured. I will try to add more comments. How's about "The underlying THP is always properly aligned in page cache, but it may be across the boundary of VMA if the VMA is misaligned, so the THP can't be PMD mapped for this case." > > > > > Also I wonder while we're at it if we can rename this to > > transhuge_addr_aligned() or transhuge_addr_suitable() or something. > > I think it is still actually used to check vma. > > > > > Otherwise I think the change is a nice cleanup. > > > > > static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, > > > unsigned long addr) > > > { > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > > index 7a5d1c1a1833..ca1754d3a827 100644 > > > --- a/mm/khugepaged.c > > > +++ b/mm/khugepaged.c > > > @@ -951,7 +951,6 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > > > struct vm_area_struct **vmap) > > > { > > > struct vm_area_struct *vma; > > > - unsigned long hstart, hend; > > > > > > if (unlikely(khugepaged_test_exit(mm))) > > > return SCAN_ANY_PROCESS; > > > @@ -960,9 +959,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > > > if (!vma) > > > return SCAN_VMA_NULL; > > > > > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > > > - hend = vma->vm_end & HPAGE_PMD_MASK; > > > - if (address < hstart || address + HPAGE_PMD_SIZE > hend) > > > + if (!transhuge_vma_suitable(vma, address)) > > > return SCAN_ADDRESS_RANGE; > > > if (!hugepage_vma_check(vma, vma->vm_flags)) > > > return SCAN_VMA_CHECK; > > > -- > > > 2.26.3 > > > > > >