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 95D8BC433EF for ; Wed, 9 Mar 2022 23:18:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0DBE8D0002; Wed, 9 Mar 2022 18:18:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBCC28D0001; Wed, 9 Mar 2022 18:18:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAD548D0002; Wed, 9 Mar 2022 18:18:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id CDB028D0001 for ; Wed, 9 Mar 2022 18:18:01 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 86C5E181D2FC9 for ; Wed, 9 Mar 2022 23:18:01 +0000 (UTC) X-FDA: 79226412762.20.6D40B32 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf05.hostedemail.com (Postfix) with ESMTP id 1BF99100012 for ; Wed, 9 Mar 2022 23:18:00 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id n18so620859plg.5 for ; Wed, 09 Mar 2022 15:18:00 -0800 (PST) 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=0HWMMaO8ZVxDmVXR4Te+4a4RkuyxpRmOrWpzvILwbQ8=; b=Dc3G/vwusqD/Sh/snFQzVYfSoQjWVwErfIYckKMnXGIqO+No/jnvyGt8qgOSauAAAy HxEpDPUGPeKZDIrF6rO2D5qFYMblFJPUBvvdaoNxwc7vwJsnhIOFwF1h2Sp6xFdZr3GK zS9sS6+Ex3muLr7xuGX8UOjyXvO/LypOGCT2IsIr7haYPC/gKmlrgb1wc21DPUIVJLIJ YfawkJi0N2IUlWRxRvPrG6JVX/6U2Xk2m/Qx5BDRIxyrAErIvkzBWTYzptjQPyzQkzcq +UL031m5KDbP4z+dTVtfHAAfrihEnzscpTjKlw8Zeba635zO2g/9AoTbdX/Xw+GoTnXu ET2w== 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=0HWMMaO8ZVxDmVXR4Te+4a4RkuyxpRmOrWpzvILwbQ8=; b=RCRgLnVdDgK5jNwVu6dl7gqdarHYSZv8PDlP6ecHdba56q7Vw9J7sMdGT8pv4X0FdE A0DtJEhf+vzTCxMlIkDgUhn+vvHcW1t5DbF3EAq2kHAyagS1jbw5k/tycNnAINJN7x1u shTGZ3Awj/uac07vxo9YALpA6QLy2V1D4vi4Lz4Rba6eSB0xZQgtxEB9KzHp2qFgeTe5 5ZEmCQw5mDvJQs2JscHCf/k5ZPFkxdxe0w26kPOWX7yYyOCZBDmWO7FbzubrWhIi3dtX KJwZj0f7RKJ67PQIEKdKFl+IfbTH9/3IzoqtzWc6yLf0kF6gqio3Oy2g/cTbgntp+TKE F0uQ== X-Gm-Message-State: AOAM5321WlS/lGcifIV4tZPo9qGfeXUcGJq57C5GKY87y3Yggq7EUA/d DQU/RsYXz2gXYAK+QpdGqiX8m5XMDvAisQtKJ/Y= X-Google-Smtp-Source: ABdhPJwgN9XFiK3QsTOOacJbtRpnZ3X46jUi3Z8ybmYHly4w/DbxVnOMSMp9NJZNloT20p8VFx4vqnRq6gKIH+ZG1fw= X-Received: by 2002:a17:90b:4595:b0:1be:db22:8327 with SMTP id hd21-20020a17090b459500b001bedb228327mr12938295pjb.99.1646867880191; Wed, 09 Mar 2022 15:18:00 -0800 (PST) MIME-Version: 1.0 References: <20220308213417.1407042-1-zokeefe@google.com> <20220308213417.1407042-8-zokeefe@google.com> In-Reply-To: <20220308213417.1407042-8-zokeefe@google.com> From: Yang Shi Date: Wed, 9 Mar 2022 15:17:48 -0800 Message-ID: Subject: Re: [RFC PATCH 07/14] mm/khugepaged: add vm_flags_ignore to hugepage_vma_revalidate_pmd_count() To: "Zach O'Keefe" Cc: Alex Shi , David Hildenbrand , David Rientjes , Michal Hocko , Pasha Tatashin , SeongJae Park , Song Liu , Vlastimil Babka , Zi Yan , Linux MM , Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matthew Wilcox , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Peter Xu , Richard Henderson , Thomas Bogendoerfer Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1BF99100012 X-Stat-Signature: yucpz8giqmy69gicpgszmzobszzpiwae Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Dc3G/vwu"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1646867880-16833 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 Tue, Mar 8, 2022 at 1:35 PM Zach O'Keefe wrote: > > In madvise collapse context, we optionally want to be able to ignore > advice from MADV_NOHUGEPAGE-marked regions. Could you please elaborate why this usecase is valid? Typically MADV_NOHUGEPAGE is set when the users really don't want to have THP for this area. So it doesn't make too much sense to ignore it IMHO. > > Add a vm_flags_ignore argument to hugepage_vma_revalidate_pmd_count() > which can be used to ignore vm flags used when considering thp > eligibility. > > Signed-off-by: Zach O'Keefe > --- > mm/khugepaged.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 1d20be47bcea..ecbd3fc41c80 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -964,10 +964,14 @@ khugepaged_alloc_page(struct page **hpage, gfp_t gfp, int node) > #endif > > /* > - * Revalidate a vma's eligibility to collapse nr hugepages. > + * Revalidate a vma's eligibility to collapse nr hugepages. vm_flags_ignore > + * can be used to ignore certain vma_flags that would otherwise be checked - > + * the principal example being VM_NOHUGEPAGE which is ignored in madvise > + * collapse context. > */ > static int hugepage_vma_revalidate_pmd_count(struct mm_struct *mm, > unsigned long address, int nr, > + unsigned long vm_flags_ignore, > struct vm_area_struct **vmap) > { > struct vm_area_struct *vma; > @@ -986,7 +990,7 @@ static int hugepage_vma_revalidate_pmd_count(struct mm_struct *mm, > hend = vma->vm_end & HPAGE_PMD_MASK; > if (address < hstart || (address + nr * HPAGE_PMD_SIZE) > hend) > return SCAN_ADDRESS_RANGE; > - if (!hugepage_vma_check(vma, vma->vm_flags)) > + if (!hugepage_vma_check(vma, vma->vm_flags & ~vm_flags_ignore)) > return SCAN_VMA_CHECK; > /* Anon VMA expected */ > if (!vma->anon_vma || vma->vm_ops) > @@ -1000,9 +1004,11 @@ static int hugepage_vma_revalidate_pmd_count(struct mm_struct *mm, > */ > > static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > + unsigned long vm_flags_ignore, > struct vm_area_struct **vmap) > { > - return hugepage_vma_revalidate_pmd_count(mm, address, 1, vmap); > + return hugepage_vma_revalidate_pmd_count(mm, address, 1, > + vm_flags_ignore, vmap); > } > > /* > @@ -1043,7 +1049,7 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, > /* do_swap_page returns VM_FAULT_RETRY with released mmap_lock */ > if (ret & VM_FAULT_RETRY) { > mmap_read_lock(mm); > - if (hugepage_vma_revalidate(mm, haddr, &vma)) { > + if (hugepage_vma_revalidate(mm, haddr, VM_NONE, &vma)) { > /* vma is no longer available, don't continue to swapin */ > trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, 0); > return false; > @@ -1200,7 +1206,7 @@ static void collapse_huge_page(struct mm_struct *mm, > count_memcg_page_event(new_page, THP_COLLAPSE_ALLOC); > > mmap_read_lock(mm); > - result = hugepage_vma_revalidate(mm, address, &vma); > + result = hugepage_vma_revalidate(mm, address, VM_NONE, &vma); > if (result) { > mmap_read_unlock(mm); > goto out_nolock; > @@ -1232,7 +1238,7 @@ static void collapse_huge_page(struct mm_struct *mm, > */ > mmap_write_lock(mm); > > - result = hugepage_vma_revalidate(mm, address, &vma); > + result = hugepage_vma_revalidate(mm, address, VM_NONE, &vma); > if (result) > goto out_up_write; > /* check if the pmd is still valid */ > -- > 2.35.1.616.g0bdcbb4464-goog >