From patchwork Tue Apr 25 17:15:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 13223547 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 2236AC77B78 for ; Tue, 25 Apr 2023 17:15:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B15F36B0095; Tue, 25 Apr 2023 13:15:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC6236B0096; Tue, 25 Apr 2023 13:15:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E576B0098; Tue, 25 Apr 2023 13:15:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 820636B0095 for ; Tue, 25 Apr 2023 13:15:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B30B120115 for ; Tue, 25 Apr 2023 17:15:50 +0000 (UTC) X-FDA: 80720565660.18.2E05F6F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 228771C0020 for ; Tue, 25 Apr 2023 17:15:47 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VooI1ROS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of brouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=brouer@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682442948; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QIaVUQ2kkkd1foj1zcvHm82kEONSqPRsWu1f6N9g/Wg=; b=No1441SgHzmhPnvOZTlAPmYTEDIb35r+swzUbxRHJcJCQmuvKUp2Fr4Jps4kIGwmlDUN03 E2CPT/tuM4/hOhpFg90WoF9agFEAWgP85MzJ4VNP+S28yQ9ig/Lhw351N4pBCLir57MK3n 8ka/wSmOEGQpiEeGB+n/CMXXStUSEyY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VooI1ROS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of brouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=brouer@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682442948; a=rsa-sha256; cv=none; b=EW3z7/E27fd4iSAiUX3Bw0Fytvsuq8t68ju5XgWMw2wspLQexp8AK+pZk0IsunQbXSsNP+ rTAn7IRS8/j+UdcBqYBb9X2FFgegdZ2G1U1964bcnaEI8KaAYUyrbw2hGsjlfIYR+i7gwi lKBj1C9L86PW0igH4BpmHyNJ+OWvI6I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682442947; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QIaVUQ2kkkd1foj1zcvHm82kEONSqPRsWu1f6N9g/Wg=; b=VooI1ROSiahgdvZhS3qoF2+87X6EmQEflLHLG5gWPNlDsfB9UH8tGYvXoWsYNIO1XoVhr3 NhFW/U70Y1++sN/iQ5hZo5crthoUIXucMJM0x6rcvvzM0r1CO3r/uBPPJo30Scs5i+X8uH Z+TWW4DyEJMwdW/1GTqzzI1GMmayNNc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-XDdFthw9O1qxyONoG3QHmw-1; Tue, 25 Apr 2023 13:15:45 -0400 X-MC-Unique: XDdFthw9O1qxyONoG3QHmw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F09EB381D4C6; Tue, 25 Apr 2023 17:15:44 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5CF840C2064; Tue, 25 Apr 2023 17:15:44 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id D70F7307372E8; Tue, 25 Apr 2023 19:15:43 +0200 (CEST) Subject: [PATCH RFC net-next/mm V1 2/3] page_pool: Use static_key for shutdown phase From: Jesper Dangaard Brouer To: Ilias Apalodimas , netdev@vger.kernel.org, Eric Dumazet , linux-mm@kvack.org, Mel Gorman Cc: Jesper Dangaard Brouer , lorenzo@kernel.org, =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , linyunsheng@huawei.com, bpf@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni , Andrew Morton , willy@infradead.org Date: Tue, 25 Apr 2023 19:15:43 +0200 Message-ID: <168244294384.1741095.6037010854411310099.stgit@firesoul> In-Reply-To: <168244288038.1741095.1092368365531131826.stgit@firesoul> References: <168244288038.1741095.1092368365531131826.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 X-Sc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xMHcczW8J4qljUpz1UM1Q//SHBlPQqs+qACcGZgLouKGbvhm7WTqH CG7x/fvU MJvF8YCykm0LljxQUiUIaITxQliZamEaj1ypNjyhQFBP8mf42IEYZpc5NAcSL/0r0KUUbH4sOjo51DaM17aS8j8A/7qk500sXy0nLebjRTSPhCNpbFkuVnAcAsq9NnaBK5WZcnKsLgpefat0ereHMo+oVpRcFXSwNyz13lLrclHKehKJDhxZcqau8KTmpsvf8TMKKDACJVkK5kzEaABMBPuip0G4ZCrNRsfCEaToFU3DjUNJBm27lSaAUrCUPOpizS+PjUvnSHYn8NG+cpW2HY+JEdDtyeoV/MLtookGWNfKTcOBVKzXZbI7VEFIyG+X8afCL 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: Performance is very important for page pool (PP). This add the use of static_key APIs for regaining a single instruction, which makes the new PP shutdown scheme zero impact. We are uncertain if this is 100% correct, because static_key APIs uses a mutex lock and it is uncertain if all contexts that can return pages can support this. We could spawn a workqueue (like we just removed) to workaround this issue. Seeking input if this is worth the complexity. Signed-off-by: Jesper Dangaard Brouer --- net/core/page_pool.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index ce7e8dda6403..3821d8874b15 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -25,6 +25,8 @@ #define BIAS_MAX LONG_MAX +DEFINE_STATIC_KEY_FALSE(pp_shutdown_phase); + #ifdef CONFIG_PAGE_POOL_STATS /* alloc_stat_inc is intended to be used in softirq context */ #define alloc_stat_inc(pool, __stat) (pool->alloc_stats.__stat++) @@ -378,7 +380,8 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, int i, nr_pages; /* API usage BUG: PP in shutdown phase, cannot alloc new pages */ - if (WARN_ON(pool->p.flags & PP_FLAG_SHUTDOWN)) + if (static_key_enabled(&pp_shutdown_phase) && + WARN_ON(pool->p.flags & PP_FLAG_SHUTDOWN)) return NULL; /* Don't support bulk alloc for high-order pages */ @@ -609,7 +612,7 @@ void page_pool_put_defragged_page(struct page_pool *pool, struct page *page, recycle_stat_inc(pool, ring_full); page_pool_return_page(pool, page); } - if (pool->p.flags & PP_FLAG_SHUTDOWN) + if (static_branch_unlikely(&pp_shutdown_phase)) page_pool_shutdown_attempt(pool); } EXPORT_SYMBOL(page_pool_put_defragged_page); @@ -659,7 +662,7 @@ void page_pool_put_page_bulk(struct page_pool *pool, void **data, page_pool_return_page(pool, data[i]); out: - if (pool->p.flags & PP_FLAG_SHUTDOWN) + if (static_branch_unlikely(&pp_shutdown_phase)) page_pool_shutdown_attempt(pool); } EXPORT_SYMBOL(page_pool_put_page_bulk); @@ -817,7 +820,15 @@ static int page_pool_release(struct page_pool *pool) noinline static void page_pool_shutdown_attempt(struct page_pool *pool) { - page_pool_release(pool); + int inflight; + + if (!(pool->p.flags & PP_FLAG_SHUTDOWN)) + return; + + inflight = page_pool_release(pool); + + if (static_key_enabled(&pp_shutdown_phase) && !inflight) + static_branch_dec(&pp_shutdown_phase); } void page_pool_use_xdp_mem(struct page_pool *pool, void (*disconnect)(void *), @@ -861,6 +872,7 @@ void page_pool_destroy(struct page_pool *pool) * Enter into shutdown phase, and retry release to handle races. */ pool->p.flags |= PP_FLAG_SHUTDOWN; + static_branch_inc(&pp_shutdown_phase); page_pool_shutdown_attempt(pool); } EXPORT_SYMBOL(page_pool_destroy);