From patchwork Mon May 29 06:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13258173 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 076A5C7EE23 for ; Mon, 29 May 2023 06:23:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94C9C900003; Mon, 29 May 2023 02:23:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D60F900002; Mon, 29 May 2023 02:23:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74FC4900003; Mon, 29 May 2023 02:23:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5D78B900002 for ; Mon, 29 May 2023 02:23:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 25E4E8021D for ; Mon, 29 May 2023 06:23:54 +0000 (UTC) X-FDA: 80842301988.09.9476F75 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf21.hostedemail.com (Postfix) with ESMTP id 4DBC71C000D for ; Mon, 29 May 2023 06:23:52 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mUjO4pWK; spf=pass (imf21.hostedemail.com: domain of hughd@google.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685341432; 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=2gSRrpVaV+v6oTVvWHOeguB0KnrQ/fwH26LJ25rfvoA=; b=coechnjWCEFWjdqwrEbXOnpCwzwjLKyjqf+0C+xPEPMs1+bG7OJHc+3HgFlnBJqcsan4QS cNm5wnqmHDGsjW1dyDuAbIK6gB3afvMtW90yVVO6iN/4REOWJm/fuRFkhFNCf04CQrwktu dyvUlTaRsb/3Y+Z+POuV9t2RDGLYBMs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685341432; a=rsa-sha256; cv=none; b=clsWe9eEN3K3NmAhSUBDAbCyQFGGE/PfU6GhuAA8dPq2sqU7Ojx5GWIc7B2LUcq2bWpJ80 35TD1S2w3LKTnJpdelXJOXB98LK0szovY9M1PVJGePT3TUUZjfgvuM6rvK/0Bt9a1Xoo5J lgsxI2uvWBiM+SOTdbDG/l9EsbumIw8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mUjO4pWK; spf=pass (imf21.hostedemail.com: domain of hughd@google.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-ba81f71dfefso4296191276.0 for ; Sun, 28 May 2023 23:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685341431; x=1687933431; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=2gSRrpVaV+v6oTVvWHOeguB0KnrQ/fwH26LJ25rfvoA=; b=mUjO4pWKJgDDKZpKrtcPe8FWu0b2JY0+TgvW1MX4OtSul/CzSbQKQ3pqCcMlWFJNGp gWOyHbCB9BXc3wVa0KzB77Yil0KZvLHMQCnsIsQVZ9fFzAnqckLLbO2LnWVC3QgXUA2m AKj7k1CX2prs/vdJ8Dux8TrJisS6znNjC1Vtrv/PsdyCPjLHWieMNw6R9XprNyEWjRCZ 4j0MNun5Zv7iQwiFWh+o2sHynbvf1kUMSyoEE1HC9cxss3LWR7d6E9drnyGo/GZyrbJL X1vYzNNY1HAUAQnzj74UQMsBrtflmgqlc89omMQkyN/nWA1df9Rcpj56XseLcz9CDb7K rRHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685341431; x=1687933431; 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=2gSRrpVaV+v6oTVvWHOeguB0KnrQ/fwH26LJ25rfvoA=; b=iXjWaukU4g5c6fG3R5LandFcTElcJlYek4BPKHaDehu+LurAjSSS01KUkEdCE6pBot xx16QsSmUutr9LhIGsEMDFv7V9MaU4yuc77Vqos/j6PHkXqT6qnRr+r7bSiZM7iPOCg3 DMgPenRmtNOOHfEo967egy3g2sm1rSrdcvTMGNCFSZLCbl+zyHkwCYCscQFgcVT+O6p+ QoCAgyfZ7W5KwVIfu5GUH/kIzlGH7dKbZvJle7oa3vKFLjTs07IrNW+VmPGCT+RfBFzA BpsNre1sAepRJvLv578gbNAQdVQ4DgcMNaae/R4q/1Yoent9DPPq2unsQHF+yLDN4Dvp f/gA== X-Gm-Message-State: AC+VfDwqwqPcG8fXZef4OiG9ZLwiiOqKvvMFApcRcO+nY6ud4kGuIEEg lqpMdrRfgG0G6dDBxzc+fM2JdQ== X-Google-Smtp-Source: ACHHUZ5CcwvoGgzDzBbk+Lv5ieVtVZp8uUiYjI1VJBrm/lel9oSDffzWyg8Wn1mT8OaCxHwZBaPMhA== X-Received: by 2002:a25:aae2:0:b0:bab:fdb3:7b56 with SMTP id t89-20020a25aae2000000b00babfdb37b56mr13795477ybi.24.1685341431250; Sun, 28 May 2023 23:23:51 -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 j73-20020a25d24c000000b00bb064767a4esm503449ybg.38.2023.05.28.23.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 May 2023 23:23:50 -0700 (PDT) Date: Sun, 28 May 2023 23:23:47 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: 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 , 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 , 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 08/12] mm/pgtable: add pte_free_defer() for pgtable as page In-Reply-To: <35e983f5-7ed3-b310-d949-9ae8b130cdab@google.com> Message-ID: <739964d-c535-4db4-90ec-2166285b4d47@google.com> References: <35e983f5-7ed3-b310-d949-9ae8b130cdab@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4DBC71C000D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: o51a55inf8rrkw5wcc3antaddipau3r5 X-HE-Tag: 1685341432-604033 X-HE-Meta: U2FsdGVkX19ZCcQrsfde98kBn4NYQNRfLNHCAD9leGlxJStdk6qEZu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Pem3E/7XyrNDjK3gX23/2B9QPtoZS+ueY1bkDN1GgozPuz5HOSt6ZAj10E7GSdCuPRyAI8tSm0MyvMUEQWJl8goOCdiqOcjD1KFDMCVaFaZNdbWVXtUALBZSYLa26FZSv8pWMmsj+vQbN8y4yjQVQtjet5A97OvXqnJzlCxTY/b3FRzTIkACQwr5DGOqOjRR1cNKxf5NgEZQY62JbTYZw1BOyO8qWPehgUTHxrLPLUY6EMCz0Qq6gAcUBco3noN2c9PlqyhOXf8cjU/1WCTtfgbjupbPijXYNNwfFrDTCK795hQdWgJPiSTeLRRiWq/WmVI9WMaat1nIYBlTCl94pg== 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: 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/pgtable.h | 2 ++ mm/pgtable-generic.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 8b0fc7fdc46f..62a8732d92f0 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 d28b63386cef..471697dcb244 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) && \