From patchwork Tue Mar 8 21:34:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12774396 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 21CB7C433F5 for ; Tue, 8 Mar 2022 21:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEF718D000A; Tue, 8 Mar 2022 16:35:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9FFC8D0001; Tue, 8 Mar 2022 16:35:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DF4B8D000A; Tue, 8 Mar 2022 16:35:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 791548D0001 for ; Tue, 8 Mar 2022 16:35:01 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 357DC181F24B6 for ; Tue, 8 Mar 2022 21:35:01 +0000 (UTC) X-FDA: 79222524402.23.2D7206C Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf20.hostedemail.com (Postfix) with ESMTP id BB60D1C000D for ; Tue, 8 Mar 2022 21:35:00 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id w3-20020a17090ac98300b001b8b914e91aso316121pjt.0 for ; Tue, 08 Mar 2022 13:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4pNIXGv6rdz5q19s1rZxDBE8jFO83zbbktYFtEBML7A=; b=hwUz3yBBt0CsKEFMkdWyy+g406vvQ3b3vW3F48F9KGjs49XfcYo/2yaWHj/lLV4Dzz MzxYJa98/JatD8CAs8u8rkjrQTNvw0BzmBVt+1OR2m6R7vxVnkndBpneR2tX8V8B65Es qWPJZSjFzHBWk+5utEjCbWDclsm82xLNHMjDHULS6mrS+am7kQPCoIaQyrQO8HIq1OBd uscaWsG5uZmlbu+/yLpgW6wLJ93cgdFVaCs9nArB+ThI5a0ld1LjCxc5S/yrVzGeeuve iYHbtZvw8Pgy5cZUyMreNdqxbJWWcPtMSOy0bMsgrdzCLF81i84cZK8fkdULUGeEEK1V 2W7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4pNIXGv6rdz5q19s1rZxDBE8jFO83zbbktYFtEBML7A=; b=1esjK/kVsr753qZSuDOFi+AEyUIs55iYbjUBXyge7p7ZqFta1LQZOv9fzKkWJXAR50 ezFO1m4ArJD2R9z9Z1C2um2C+JzY2sK6Hb6hBLZ28zfnktzOXdRblDmh/LPDLqsgmX1y a4+5NtzArG36bt85XXH7pnfraaCz5oUv9H3C061Nxc6gyXsLXnaUiVCxdT60BBl0GGTZ ub5mtZvui5qmNYk/wCg8Y0CaHc1U0IkxziSRLY16b+fhiRHRf/YAHBDz0sWsb7LpcltN rLXW1dKNFlpVOcFOAFCjJ5eQm9kL4kUe2ZWwdXQ+mE3eB58iCFDtoZHieZTx2KxEEZd9 Au8w== X-Gm-Message-State: AOAM532x94o3fWcE18V4MIuh3Q/F3fy3ePetTTzE9kfckHj6rYUtA+cZ xTkLLx549xg2LWCUT6e0MdKGconv+crc X-Google-Smtp-Source: ABdhPJzCFgsJPnBjeOpEKdxdcVbDseeXH0IJj/6nUs+NKdlyZUSn29QuaEGUW+OQEB/cxzScg3Yh4AqXCXWq X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:cf12:b0:14f:e0c2:1515 with SMTP id i18-20020a170902cf1200b0014fe0c21515mr19740035plg.4.1646775299810; Tue, 08 Mar 2022 13:34:59 -0800 (PST) Date: Tue, 8 Mar 2022 13:34:10 -0800 In-Reply-To: <20220308213417.1407042-1-zokeefe@google.com> Message-Id: <20220308213417.1407042-8-zokeefe@google.com> Mime-Version: 1.0 References: <20220308213417.1407042-1-zokeefe@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [RFC PATCH 07/14] mm/khugepaged: add vm_flags_ignore to hugepage_vma_revalidate_pmd_count() From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Michal Hocko , Pasha Tatashin , SeongJae Park , Song Liu , Vlastimil Babka , Zi Yan , linux-mm@kvack.org Cc: 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 , Yang Shi , "Zach O'Keefe" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BB60D1C000D X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hwUz3yBB; spf=pass (imf20.hostedemail.com: domain of 3A8wnYgcKCFIJ84yyzy08805y.w86527EH-664Fuw4.8B0@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3A8wnYgcKCFIJ84yyzy08805y.w86527EH-664Fuw4.8B0@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 7nzzxy1dtf348ofeug38e53g74upicaf X-HE-Tag: 1646775300-251040 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: In madvise collapse context, we optionally want to be able to ignore advice from MADV_NOHUGEPAGE-marked regions. 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 */