Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7475498rwd; Tue, 20 Jun 2023 01:34:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zf5VMwwXucqIDA7QFPA4C5+hj0ITJBdKUG9+L4dg7I9wdAq13NOdjf2sIHO9AQt6nogIw X-Received: by 2002:a17:903:2443:b0:1b5:5ee1:1211 with SMTP id l3-20020a170903244300b001b55ee11211mr8737451pls.9.1687250098799; Tue, 20 Jun 2023 01:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687250098; cv=none; d=google.com; s=arc-20160816; b=FB/V3ROrwMhLaQGAKajGjQ8lEDabc935EFhxHYFMqTFtckvWYy0TVvKGCvcQ6kuXwA puyWXLRPtQq1p3PBYCkgKZyJTFXkB2CIu2hAecmVql6XXa3tIZOl5U6qgmGlf3v/Yt8Y zdZxIPZXzI8TGTZd0OsBzoP13WJwu4KvimE2jippqHJSXOWdk7N/38U957DGHoRNN+iO Tlr1McwlGem/wnOgiWsKVmQsdoOwprCKjtK+Lpb60c8U2nuxi6hT2EJamVJgXgqcfhv2 wSEYZhIkYzFgob2ZUdJrgn8vhYhe7V3khXhn/oh1bw53aemZeRWJNtpMaUayzqvK7DsW 7yvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=Q5R0zcB6mybnkU9NBbTtghvpq67JAa0crCVDjZ9SpHk=; b=OG6YfQrXX+LwY7i0qxtH2z3r6xmcccWxpQNu/ztkur5bVHDuE6V0cFi1maeYrtAz8F cHtHUOlBNgqULgiNHUTQuZ1lyAzsXdUoSd/tP9c0ypT3sC2VMjZvk/OxH5xnVwKAGGGX 2ugL74YY1pV4m1vPng+sv+VbYcqaE0yHJ+Au8+4OJLhkmzlXMQ7huh576itnwiNs8JkS 79X/xFOMWnzQAL/llpoZNuZ/Tr1lPpYmQ8sw3NDAEbtVBS8nmsDsbdkhsCgqc8nssQc0 W8sq7WshKBHJfmiLJkfTT9eqrpu6aNOounR7Uzuo8ewujirjGDd26TtG05x2gRel/Er+ ibdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2GY6tb59; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a170903214500b001afe7ef68b6si1332436ple.452.2023.06.20.01.34.36; Tue, 20 Jun 2023 01:34:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2GY6tb59; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbjFTHxt (ORCPT + 99 others); Tue, 20 Jun 2023 03:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbjFTHx2 (ORCPT ); Tue, 20 Jun 2023 03:53:28 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693CC19AE for ; Tue, 20 Jun 2023 00:53:10 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5707b429540so53753347b3.1 for ; Tue, 20 Jun 2023 00:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687247588; x=1689839588; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=Q5R0zcB6mybnkU9NBbTtghvpq67JAa0crCVDjZ9SpHk=; b=2GY6tb59UZYGOHu8Jpard49Ijl8S41fZ8HDgfi6a4gvFJ5750jQeYrmu9nVrvi1jW2 tp8ypG/banZ4ws6Js9iQQN9cGknEmtht9BWd32J2yMcrVqteXUvW9YR9uMMhKiTOhwCj DlNulmZyq+f8KzKXIgNcUSNUMmKGW1CGHEEgbEp/J7IxewrE//XtQewkerpcgsbwL40t WfRaz/SdO8RzSMtTrw2rYV18y0/dvvOSll1UA2/d8Zuh32W7Pnj2B4fhDdSSvEN+0aoF 9f1IZjfj8naj8IynmrWiGUnfEPBGZdaKRscDXhw1Sy1gWU3iNWnHKGQGUPwpRy5JQoX9 lMYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687247588; x=1689839588; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q5R0zcB6mybnkU9NBbTtghvpq67JAa0crCVDjZ9SpHk=; b=lOmEDasdW4/fOgBNdtj0689XasxNOQTfz6pqRIEaGH3A3Aayth0Kp0LGUAlSb0LBwj x0xDIYjR6H5PU3rcCfzDCGfHWgzglkqe7SabVn/qPNOjR2yxdgR2RrLNBd6gVsVAJ4cc lw/Us7QyBNLnBYJ/t3WLpMsQ/6nNfHYqAYBPGViPTfZazhThr7U6iBc1DjA945ktxieU qlcDMpFitrgDJlaBU46jRdf81Fz0wRh1DPDZtZ1ADbRUitgnVeX5aKCCPbVKorJWbOdV Abg2Hq90MABt/YqSbIARjb6CWQtJWZyG5ro+L9Z5T4YeF/VJ+iBqhyw2388nyOHGVNPC uPOA== X-Gm-Message-State: AC+VfDxlO+D1Y7NperHWrtDJcXFqg1ptIq8slCzwNyKPg+n0vXohxoTp GeD9AX0qi1qYfQMLtYnNTfUmwQ== X-Received: by 2002:a81:6c11:0:b0:56f:f83f:618 with SMTP id h17-20020a816c11000000b0056ff83f0618mr10840742ywc.19.1687247587950; Tue, 20 Jun 2023 00:53:07 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x11-20020a81630b000000b0056ffca5fb01sm370775ywb.117.2023.06.20.00.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 00:53:07 -0700 (PDT) Date: Tue, 20 Jun 2023 00:53:03 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Gerald Schaefer , Vasily Gorbik , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Russell King , "David S. Miller" , Michael Ellerman , "Aneesh Kumar K.V" , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , Alexander Gordeev , Jann Horn , Vishal Moola , Vlastimil Babka , linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 08/12] mm/pgtable: add pte_free_defer() for pgtable as page In-Reply-To: <54cb04f-3762-987f-8294-91dafd8ebfb0@google.com> Message-ID: <3e5961a2-26e5-d1ab-5c4c-527e273e3cc5@google.com> References: <54cb04f-3762-987f-8294-91dafd8ebfb0@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the generic pte_free_defer(), to call pte_free() via call_rcu(). pte_free_defer() will be called inside khugepaged's retract_page_tables() loop, where allocating extra memory cannot be relied upon. This version suits all those architectures which use an unfragmented page for one page table (none of whose pte_free()s use the mm arg which was passed to it). Signed-off-by: Hugh Dickins --- include/linux/mm_types.h | 4 ++++ include/linux/pgtable.h | 2 ++ mm/pgtable-generic.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 1667a1bdb8a8..09335fa28c41 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -144,6 +144,10 @@ struct page { struct { /* Page table pages */ unsigned long _pt_pad_1; /* compound_head */ pgtable_t pmd_huge_pte; /* protected by page->ptl */ + /* + * A PTE page table page might be freed by use of + * rcu_head: which overlays those two fields above. + */ unsigned long _pt_pad_2; /* mapping */ union { struct mm_struct *pt_mm; /* x86 pgd, s390 */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 525f1782b466..d18d3e963967 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -112,6 +112,8 @@ static inline void pte_unmap(pte_t *pte) } #endif +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable); + /* Find an entry in the second-level page table.. */ #ifndef pmd_offset static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address) diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c index 5e85a625ab30..ab3741064bb8 100644 --- a/mm/pgtable-generic.c +++ b/mm/pgtable-generic.c @@ -13,6 +13,7 @@ #include #include #include +#include #include /* @@ -230,6 +231,25 @@ pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address, return pmd; } #endif + +/* arch define pte_free_defer in asm/pgalloc.h for its own implementation */ +#ifndef pte_free_defer +static void pte_free_now(struct rcu_head *head) +{ + struct page *page; + + page = container_of(head, struct page, rcu_head); + pte_free(NULL /* mm not passed and not used */, (pgtable_t)page); +} + +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable) +{ + struct page *page; + + page = pgtable; + call_rcu(&page->rcu_head, pte_free_now); +} +#endif /* pte_free_defer */ #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #if defined(CONFIG_GUP_GET_PXX_LOW_HIGH) && \ -- 2.35.3