From patchwork Wed Jul 12 04:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13309562 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 73E67EB64D9 for ; Wed, 12 Jul 2023 04:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A3896B0072; Wed, 12 Jul 2023 00:36:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12A7C6B0075; Wed, 12 Jul 2023 00:36:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0D176B0078; Wed, 12 Jul 2023 00:36:07 -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 E3FB86B0072 for ; Wed, 12 Jul 2023 00:36:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B28BAB045A for ; Wed, 12 Jul 2023 04:36:07 +0000 (UTC) X-FDA: 81001697574.16.1B54B3F Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by imf15.hostedemail.com (Postfix) with ESMTP id E6178A000F for ; Wed, 12 Jul 2023 04:36:05 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=FFbzGiP1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of hughd@google.com designates 209.85.128.177 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689136566; a=rsa-sha256; cv=none; b=riLNjgMzD2N+Ny89X/0WLKkaWYnIQLb0B13FgtvgOacD8bVMVoNnDRHIl2F/pMj9fx1zRo 9PCXhMsaPZJMSfQI8TUJXIpJM0V2zwa2+87ZGMqWG3YsC9hXPSoYJHVmps1GWEpT0b+oFJ QyFvVRS/fpWIQ+3ji6oziC8Rk2McIXk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=FFbzGiP1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of hughd@google.com designates 209.85.128.177 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689136565; 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=rNkuOnMiPA5uKMNmzDSZhkkEhVwG+08I0Sc1INz+wy8=; b=oOB3r9Ehrmh7yq0kV/p3mpnXnb4tsWnjNZ4Lfd19dYM33+212rNTZ2oT3EJFXjN+oom2dq 6tkun11v0mykXSOM/unXHp7SXxt1BWSndBWjaGR7in6KweyICdtS7SnJFsGPv4D1WaXKwr ReIFp8eErfrk8VsUamNKoX53U+7b8XU= Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-5701eaf0d04so72803007b3.2 for ; Tue, 11 Jul 2023 21:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689136565; x=1691728565; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=rNkuOnMiPA5uKMNmzDSZhkkEhVwG+08I0Sc1INz+wy8=; b=FFbzGiP1Hn/cx8QOOnqnR11nIjqgT83mtNZkbCUQnSq5LrblamhVfpvB+UeJbyZW1s y4J6XTFnK8fA2dLUAHHtBip6qAhzoi/1hVVGt2YPDhBzcNtIdNEwDD9zadVtdk/xueRH ZKLjXaeVhHWhvtWyuu/YKxYZxvMKkRUX8OZHqVf6Z3jPZZZJRTzTUXJQXMXyRqkMOflu Wsa6cYIz8XLnnJEBGqzhXR/oYVqaIyb5OBPuZhbuAADdjSajptwPQTErMBx4XyNaSU8b s7pjxVInyPyp25nFk59wK/5ndqw3B7p/EJhYwYVyO8aZGxHmDzIQpJw9VHF7rxxbYyvE Gp3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689136565; x=1691728565; 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=rNkuOnMiPA5uKMNmzDSZhkkEhVwG+08I0Sc1INz+wy8=; b=hkDz9iYbJUoY/1ts+tVqiWYDeFcDXnsZWsOeEK5NKqngY/JlmdysWyVwl8eaP6eVM/ 4f+xN++rC6N9JRvhiVDnBEOPlrrHkmvJEQ7oA9Q7Z8F5pn7Oqhq2GLcuxmKlZsTSBpTy rmE+Xd90YsC8W2k6sswFd3apwqiKSsmB3eqWg6C912QfRalvRME/vOjRpyNqy1+Xh5ZB GMw25py7wn7e/Wv6R8BMFJZf+w4j8zLyFHKAGN4FuKfG+FYgjFOJtMYcjdoyIlds26rS t0uJosONnk0khEY3t9e2Ro7XOK2xIGUIOroEbXAwovAqvxtoOQa+WoM4qv8MjQqPD6fA ypBA== X-Gm-Message-State: ABy/qLYwLlHtffugLC3axs4raqOli7pQplT4JTJiKZ0VMfgb7xRtOd6w JSr2ga6saAwRNwLq2+YqoQdQsw== X-Google-Smtp-Source: APBJJlFtIJlcayIhMEpj3vHnt3xsOXLGUeoHM39mGyyz8wsLsKOn5HDkQrRum1Ly6OBtEql+IV2D3A== X-Received: by 2002:a0d:e88d:0:b0:577:606c:284b with SMTP id r135-20020a0de88d000000b00577606c284bmr15146586ywe.16.1689136564850; Tue, 11 Jul 2023 21:36:04 -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 m124-20020a817182000000b0056d0709e0besm968571ywc.129.2023.07.11.21.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 21:36:04 -0700 (PDT) Date: Tue, 11 Jul 2023 21:35:59 -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 , 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 , Gerald Schaefer , Vasily Gorbik , Jann Horn , Vishal Moola , Vlastimil Babka , Zi Yan , 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 v3 05/13] powerpc: add pte_free_defer() for pgtables sharing page In-Reply-To: <7cd843a9-aa80-14f-5eb2-33427363c20@google.com> Message-ID: <6e3ca5f1-334d-4b14-b92d-fc8e99914fcb@google.com> References: <7cd843a9-aa80-14f-5eb2-33427363c20@google.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E6178A000F X-Stat-Signature: m3g5jgr4c1wztna59x9hchkau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LqOpsM6mMqFnFgwWYSkCMi9Sy1Q064tGjIv5DFAN0jFiTI958uXwiNclRsmvvtpazyaqvKVZesHY+CJi1KoerdV0iLCctZWmVS2bRNADi0nleiQ1ozH0crvlPZkPWzhduZlLmxr7b9v4HPrd7RZV8/4gLlOExa7c5w/jvThGMuOLDbq4Fp0nqv8X5H6JWrreYHVXtWLcyjqbsPqwjhsvqw2PdDOXEGiYgSUJTxWhFJLSHLXksZxMkRsxO3lYulgznrNYQQ3HqpG58QyhZB2VVFCXKoAxa612+Ot/VnGu7D55jKbQvNfdpVohvDYDxvgw7jPQnE1J+mo8Grn6QDTwwkZPsD79aPd2zVmdAQeTYW/VBPSXBY7S9mpKjzR7C6w32F/BD49M9MxvM9/ts9FyqmTeIoy/luX7bwumiOmv67qIJs7VIl2+hmqnoHeiiZFrynSECW0JW2i9jT7VzqdIwC9HB7+oyGqBk3A3WyyHKizEE2Qf8wYauBHNtYMXDF7egeLgltHOLlY6Hg== 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 powerpc-specific pte_free_defer(), to free table page 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 precedes the generic version to avoid build breakage from incompatible pgtable_t. This is awkward because the struct page contains only one rcu_head, but that page may be shared between PTE_FRAG_NR pagetables, each wanting to use the rcu_head at the same time. But powerpc never reuses a fragment once it has been freed: so mark the page Active in pte_free_defer(), before calling pte_fragment_free() directly; and there call_rcu() to pte_free_now() when last fragment is freed and the page is PageActive. Suggested-by: Jason Gunthorpe Signed-off-by: Hugh Dickins --- arch/powerpc/include/asm/pgalloc.h | 4 ++++ arch/powerpc/mm/pgtable-frag.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/pgalloc.h b/arch/powerpc/include/asm/pgalloc.h index 3360cad78ace..3a971e2a8c73 100644 --- a/arch/powerpc/include/asm/pgalloc.h +++ b/arch/powerpc/include/asm/pgalloc.h @@ -45,6 +45,10 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage) pte_fragment_free((unsigned long *)ptepage, 0); } +/* arch use pte_free_defer() implementation in arch/powerpc/mm/pgtable-frag.c */ +#define pte_free_defer pte_free_defer +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable); + /* * Functions that deal with pagetables that could be at any level of * the table need to be passed an "index_size" so they know how to diff --git a/arch/powerpc/mm/pgtable-frag.c b/arch/powerpc/mm/pgtable-frag.c index 20652daa1d7e..0c6b68130025 100644 --- a/arch/powerpc/mm/pgtable-frag.c +++ b/arch/powerpc/mm/pgtable-frag.c @@ -106,6 +106,15 @@ pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel) return __alloc_for_ptecache(mm, kernel); } +static void pte_free_now(struct rcu_head *head) +{ + struct page *page; + + page = container_of(head, struct page, rcu_head); + pgtable_pte_page_dtor(page); + __free_page(page); +} + void pte_fragment_free(unsigned long *table, int kernel) { struct page *page = virt_to_page(table); @@ -115,8 +124,22 @@ void pte_fragment_free(unsigned long *table, int kernel) BUG_ON(atomic_read(&page->pt_frag_refcount) <= 0); if (atomic_dec_and_test(&page->pt_frag_refcount)) { - if (!kernel) - pgtable_pte_page_dtor(page); - __free_page(page); + if (kernel) + __free_page(page); + else if (TestClearPageActive(page)) + call_rcu(&page->rcu_head, pte_free_now); + else + pte_free_now(&page->rcu_head); } } + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable) +{ + struct page *page; + + page = virt_to_page(pgtable); + SetPageActive(page); + pte_fragment_free((unsigned long *)pgtable, 0); +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */