From patchwork Tue Mar 8 21:34:04 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: 12774390 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 512E0C433EF for ; Tue, 8 Mar 2022 21:34:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD9878D0003; Tue, 8 Mar 2022 16:34:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D378C8D0001; Tue, 8 Mar 2022 16:34:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB1938D0003; Tue, 8 Mar 2022 16:34:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id A95BC8D0001 for ; Tue, 8 Mar 2022 16:34:48 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5E52A95C99 for ; Tue, 8 Mar 2022 21:34:48 +0000 (UTC) X-FDA: 79222523856.20.F4F9CA1 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf21.hostedemail.com (Postfix) with ESMTP id EFC201C000A for ; Tue, 8 Mar 2022 21:34:47 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id c10-20020a170902d48a00b00151cf8ca3c7so163048plg.0 for ; Tue, 08 Mar 2022 13:34:47 -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=ve0m0yCLuMUl2tRX0tiaUyBdaoAzAOTE2DnxWbiiZhI=; b=aeb1HQTcxeemspgEKALnNTXQmEaP6/oVdrCeYJZC1LSAhUs3DoGNiiCSISQaqZV0li wEUu/eks1LwVGgW9K/Dt1N4J5C3tO3uenus+ZWZFhD2KVCEtH7/Sar5/bHI1SDVRdK4E BG4mDdTBdBIXYcxhIEEuvUq9MSUQkiCr9VZFTBan68KCSURLMarqDcs3crt7I8Ld85Lf sGLCX7BMt2u1F0LL9O5YFPLIm+OqTprzk6oabYCoFNlgqRk9Mihyx1GsqItN/qcMRyh8 xfN/nTINxQ1Jk/gAgUGsbZ6qLeza5MTm0VrYPCUpQPwoPEFF/28QBLFy29kOM4KSO1tV 41pQ== 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=ve0m0yCLuMUl2tRX0tiaUyBdaoAzAOTE2DnxWbiiZhI=; b=sgdsLCDdlEE8qJWLJi3dOt+YIuAR8EY8Er/0H/xfWRbF/FQDoHiriSixPON5xBDaqB TS4p1VL1gp7qRKh/mImIjXdySlYyLVd6mXVQd/UBRSLdnldpYoME0DSkTwiRgId97f6+ VU1q9NOqVU1umKgTGsuDdQw9RgSIod5JICMYhZEKk+St7SotAaSpdZVP6oyR+z8Q5lii B6LrnWrbmBnYS8C+1EQVCk2lAeiz2ffzJu8ledhMaUpD98Ax6leH7X4rj+pT56ps6V8X mHlfiLwNzdiLaaq8X74Y4khDCl1tY2C7vQ/TY5uC4L1lYoT01CXBMRmzz/xDcdz0ou7g O1zg== X-Gm-Message-State: AOAM532N0EZaKI6fqYNSOsWUXX49xsf8HgUiVJbNu+oaEoYLVN5eatmB Go9UOPszAE8p0EpEJnTlyroCTStwCkl2 X-Google-Smtp-Source: ABdhPJxv5H76Biwwemt4gouPtwTqXeI5LOPN3ZsAaCgJV2L+Y8z0AZ85IwYGvvwR+9Mh1We+aGTSflpLhTMr X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90b:4ad2:b0:1bf:d47:8077 with SMTP id mh18-20020a17090b4ad200b001bf0d478077mr6808811pjb.85.1646775287033; Tue, 08 Mar 2022 13:34:47 -0800 (PST) Date: Tue, 8 Mar 2022 13:34:04 -0800 In-Reply-To: <20220308213417.1407042-1-zokeefe@google.com> Message-Id: <20220308213417.1407042-2-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 01/14] mm/rmap: add mm_find_pmd_raw helper 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-Queue-Id: EFC201C000A X-Stat-Signature: 5uxe5bjff9ba6yb8imq864ndfm5b9dbh X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aeb1HQTc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 398snYgcKCEY7wsmmnmowwotm.kwutqv25-uus3iks.wzo@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=398snYgcKCEY7wsmmnmowwotm.kwutqv25-uus3iks.wzo@flex--zokeefe.bounces.google.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646775287-111492 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: Later in the series, we want to find a pmd and take different actions, depending on if the pmd maps a thp or not. Currently, mm_find_pmd() returns NULL if a valid pmd maps a thp, and so we can't use it directly. Split mm_find_pmd() into 2 parts: mm_find_pmd_raw(), which returns a raw pmd pointer, and the logic that filters out non-present none, or huge pmds. mm_find_pmd_raw() can then be reused later in the series. Signed-off-by: Zach O'Keefe --- mm/internal.h | 1 + mm/rmap.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 86277d90a5e2..aaea25bb9096 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -166,6 +166,7 @@ extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason /* * in mm/rmap.c: */ +pmd_t *mm_find_pmd_raw(struct mm_struct *mm, unsigned long address); extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address); /* diff --git a/mm/rmap.c b/mm/rmap.c index 70375c331083..0ae99affcb27 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -758,13 +758,12 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma) return vma_address(page, vma); } -pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) +pmd_t *mm_find_pmd_raw(struct mm_struct *mm, unsigned long address) { pgd_t *pgd; p4d_t *p4d; pud_t *pud; pmd_t *pmd = NULL; - pmd_t pmde; pgd = pgd_offset(mm, address); if (!pgd_present(*pgd)) @@ -779,6 +778,18 @@ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) goto out; pmd = pmd_offset(pud, address); +out: + return pmd; +} + +pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) +{ + pmd_t pmde; + pmd_t *pmd; + + pmd = mm_find_pmd_raw(mm, address); + if (!pmd) + goto out; /* * Some THP functions use the sequence pmdp_huge_clear_flush(), set_pmd_at() * without holding anon_vma lock for write. So when looking for a