From patchwork Wed Jan 3 09:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13509826 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 B2C86C47074 for ; Wed, 3 Jan 2024 09:57:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42DF48D0063; Wed, 3 Jan 2024 04:57:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DE088D0061; Wed, 3 Jan 2024 04:57:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27E2C8D0063; Wed, 3 Jan 2024 04:57:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0FCF38D0061 for ; Wed, 3 Jan 2024 04:57:46 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D101F80232 for ; Wed, 3 Jan 2024 09:57:45 +0000 (UTC) X-FDA: 81637548090.17.3062820 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf23.hostedemail.com (Postfix) with ESMTP id 636DC14001A for ; Wed, 3 Jan 2024 09:57:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704275864; 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; bh=CPfRm0RxHNeiMA1fbdeDjZpspbrje3JC2BDkcjIVSZs=; b=F648/WDm4VShWor//yv/MtK7I6M3uqSLMqtEQoBX1HfYnCCqViGoOq4EfstK4Kgw8wIFBI sTzXSAoAEKumQdG9YvjUOeze+eFyFR5BDIJ5sR4nSf+7RpzvWnYZ4EpdxpDwOaZqf32ZaN cshjPVT7vMFFY+02cLDJzJp9KDwrxzI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704275864; a=rsa-sha256; cv=none; b=UaryiSpJAJwjvyPHFdhdjVVw6F+KE6Khrn3RAwDxDP8fnz66m03GNXOSRrfmeObd0LGHNJ sJ5q+RaAruAKFM2tn2ZpsMxAaYlXt2XH5F7Gv8ni0pDeyniAGZCG84n9H8QK0m8xMA/mwt ZO38SMUiSNma6pxYTV9kPPKXc3+YmCY= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4T4lR93hNjz1FHNv; Wed, 3 Jan 2024 17:53:41 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 5586B1404F1; Wed, 3 Jan 2024 17:57:40 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 3 Jan 2024 17:57:27 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Jason Wang , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Eric Dumazet , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , "Michael S. Tsirkin" , Andrew Morton , , , , , , Subject: [PATCH net-next 5/6] net: introduce page_frag_cache_drain() Date: Wed, 3 Jan 2024 17:56:48 +0800 Message-ID: <20240103095650.25769-6-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240103095650.25769-1-linyunsheng@huawei.com> References: <20240103095650.25769-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 636DC14001A X-Stat-Signature: ikdfe8m8jdu1tu1p5bu4e1ta6afy1htz X-HE-Tag: 1704275862-201229 X-HE-Meta: U2FsdGVkX1/By843HghkpG0VzV3mO8X9RPDV2H3eLpKUypFWwddfmHVP2X8xJZVyP+43M2VEH6XpyB+4dPiI/Lbd3ksc5+zZZada83dTZh91sGOEPgqa/e7ztXbdnm3k3QmWmjA/CHer/vBIwpMRe8CLXGEAu21Q6JFDxeqNzmOGb3cEk1jT3Cu9tiMqqYfEvrex3UgvuH+98M78eL23ZtL77QxqyDTBZ0P50EHFcXTWo7G3QJ5e0HN9sxe2DXpsxiAlSU+g/diF+lcyP7oeYbI/NGcYBxb9Vl4n0txm0yQ4Lq+DIlGbAuMenLVfv9Ym/g1WjPA6E/LY1TBz4d8tTI0wUbCeJ4tRkvEs4a74lDnh/2lmfUopPOJguI5KyC0qCySnXO+mhadJyTYeEtSnxVpp2EJkDsunAhMZo+t2mG5uWVGExIQ/1Cy+7kMeHNS1ycpsWWnVOTX0q6DI1f1yiCgl7nA5GMBJzh4jMGf5DUjaI09huTUE9xQGIznn3g3QC4vBpxjDxOiDGEu07bmqnC92j2H3/6MWWOH2hwpM/hVXYJGn3Uaihs5+OD4Kbd8hDX8rvPkx3NnoSdHY8C60SX7RP9rDzSSi45N2obu9gfCUKL7kJVh4Kzgmam5Hr5bJYj9SZ11KTDhaja2S/y2VMtrlLOs9UNLWVj8nx9khvnclgn1Cq8sSg6cz0WQUvCMtH0PxBsz4Mvw31kB3QKYEuCgvnC3c9ggXC1xl15lewN0c1O48AiFtpfvQgfJvtKe290aofoLKnvMCESztyqm2S4OO4twmk9jR16GDy9BOl3qSc65D9+em3YKYazCjw1jYo++aWlz3VyLcUoAh/REzDjeoKWoTsvHNi7tOAjZEZSeoH9RbVRHm7p2zVeI1H1dlDs2Wuqt93QNVxAMUDk4a7qg/D5xFviaorHu+/V21MvXYnYBZKnI+GKHYTRSxLx0FpogEcovzUbveqLQp833 5r//+rY0 fU6DJz1yLh3XrosKql1uZmqCkUMO8Z24cMjE7VA8ujfdoeutYVnVIHaNIkAcNF09oM5HmM93tPiuySiYfcuxIrdRDe9+MCDAo9FOLhfJer6pRtanVejwyscPlUIcfqxOZa8sC5llNDF+Tl0uY5i2BSUGgi96kq5nu7PHpPLYRfWN4k/35W4IONJO3rfL4rf+U/hw5Mzy80VhtpDTMgucxKWcs/skIZRg3bO6S/F1haKGI3xV2SmvVhBS6ocH8Q+HOuuWIouqgqHyzBBwsjCN4Rw0rAuJllEvT45j2 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: List-Subscribe: List-Unsubscribe: When draining a page_frag_cache, most user are doing the similar steps, so introduce an API to avoid code duplication. Signed-off-by: Yunsheng Lin Acked-by: Jason Wang Reviewed-by: Alexander Duyck --- drivers/net/ethernet/google/gve/gve_main.c | 11 ++--------- drivers/net/ethernet/mediatek/mtk_wed_wo.c | 17 ++--------------- drivers/nvme/host/tcp.c | 7 +------ drivers/nvme/target/tcp.c | 4 +--- drivers/vhost/net.c | 4 +--- include/linux/gfp.h | 2 ++ mm/page_alloc.c | 10 ++++++++++ 7 files changed, 19 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 619bf63ec935..d976190b0f4d 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1278,17 +1278,10 @@ static void gve_unreg_xdp_info(struct gve_priv *priv) static void gve_drain_page_cache(struct gve_priv *priv) { - struct page_frag_cache *nc; int i; - for (i = 0; i < priv->rx_cfg.num_queues; i++) { - nc = &priv->rx[i].page_cache; - if (nc->va) { - __page_frag_cache_drain(virt_to_page(nc->va), - nc->pagecnt_bias); - nc->va = NULL; - } - } + for (i = 0; i < priv->rx_cfg.num_queues; i++) + page_frag_cache_drain(&priv->rx[i].page_cache); } static int gve_open(struct net_device *dev) diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c index d58b07e7e123..7063c78bd35f 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c @@ -286,7 +286,6 @@ mtk_wed_wo_queue_free(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) static void mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) { - struct page *page; int i; for (i = 0; i < q->n_desc; i++) { @@ -301,19 +300,12 @@ mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) entry->buf = NULL; } - if (!q->cache.va) - return; - - page = virt_to_page(q->cache.va); - __page_frag_cache_drain(page, q->cache.pagecnt_bias); - memset(&q->cache, 0, sizeof(q->cache)); + page_frag_cache_drain(&q->cache); } static void mtk_wed_wo_queue_rx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) { - struct page *page; - for (;;) { void *buf = mtk_wed_wo_dequeue(wo, q, NULL, true); @@ -323,12 +315,7 @@ mtk_wed_wo_queue_rx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) skb_free_frag(buf); } - if (!q->cache.va) - return; - - page = virt_to_page(q->cache.va); - __page_frag_cache_drain(page, q->cache.pagecnt_bias); - memset(&q->cache, 0, sizeof(q->cache)); + page_frag_cache_drain(&q->cache); } static void diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 08805f027810..c80037a78066 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1344,7 +1344,6 @@ static int nvme_tcp_alloc_async_req(struct nvme_tcp_ctrl *ctrl) static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid) { - struct page *page; struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); struct nvme_tcp_queue *queue = &ctrl->queues[qid]; unsigned int noreclaim_flag; @@ -1355,11 +1354,7 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid) if (queue->hdr_digest || queue->data_digest) nvme_tcp_free_crypto(queue); - if (queue->pf_cache.va) { - page = virt_to_head_page(queue->pf_cache.va); - __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); - queue->pf_cache.va = NULL; - } + page_frag_cache_drain(&queue->pf_cache); noreclaim_flag = memalloc_noreclaim_save(); /* ->sock will be released by fput() */ diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 4cc27856aa8f..11237557cfc5 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1576,7 +1576,6 @@ static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue) static void nvmet_tcp_release_queue_work(struct work_struct *w) { - struct page *page; struct nvmet_tcp_queue *queue = container_of(w, struct nvmet_tcp_queue, release_work); @@ -1600,8 +1599,7 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w) if (queue->hdr_digest || queue->data_digest) nvmet_tcp_free_crypto(queue); ida_free(&nvmet_tcp_queue_ida, queue->idx); - page = virt_to_head_page(queue->pf_cache.va); - __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); + page_frag_cache_drain(&queue->pf_cache); kfree(queue); } diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 805e11d598e4..4b2fcb228a0a 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1386,9 +1386,7 @@ static int vhost_net_release(struct inode *inode, struct file *f) kfree(n->vqs[VHOST_NET_VQ_RX].rxq.queue); kfree(n->vqs[VHOST_NET_VQ_TX].xdp); kfree(n->dev.vqs); - if (n->pf_cache.va) - __page_frag_cache_drain(virt_to_head_page(n->pf_cache.va), - n->pf_cache.pagecnt_bias); + page_frag_cache_drain(&n->pf_cache); kvfree(n); return 0; } diff --git a/include/linux/gfp.h b/include/linux/gfp.h index bbd75976541e..03ba079655d3 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -316,6 +316,8 @@ extern void *page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align); +void page_frag_cache_drain(struct page_frag_cache *nc); + static inline void *page_frag_alloc(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 083e0c38fb62..5a0e68edcb05 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4716,6 +4716,16 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); +void page_frag_cache_drain(struct page_frag_cache *nc) +{ + if (!nc->va) + return; + + __page_frag_cache_drain(virt_to_head_page(nc->va), nc->pagecnt_bias); + nc->va = NULL; +} +EXPORT_SYMBOL(page_frag_cache_drain); + void *page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align)