From patchwork Tue Jan 23 10:42: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: 13527216 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 20B9DC47DDC for ; Tue, 23 Jan 2024 10:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB9816B0074; Tue, 23 Jan 2024 05:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A42D86B0080; Tue, 23 Jan 2024 05:44:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3166B0075; Tue, 23 Jan 2024 05:44:25 -0500 (EST) 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 740266B0080 for ; Tue, 23 Jan 2024 05:44:25 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0E36D40A48 for ; Tue, 23 Jan 2024 10:44:25 +0000 (UTC) X-FDA: 81710241690.26.8571B95 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf01.hostedemail.com (Postfix) with ESMTP id 6DA1940011 for ; Tue, 23 Jan 2024 10:44:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.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=1706006663; 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=BZWLD8kZydrbnEMhbWiN1ZsDya9JS9FS/nBFJqsWDUk=; b=SQ9xZ8GedjSKamnNRmNMTMuywaprTIm65YBPEu2PYEZiRoyjMlWafHNQFPl+1CrCxv9zhI mYsSqhFmpQbW9cJOVx71Shh9KM5GApZg9gLLDkxpH1Ol4AEM4akq0+49k2xtNHjdNn+C8e AktFFSbI+uKbYK60B7E7JXmHJuopz7Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.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=1706006663; a=rsa-sha256; cv=none; b=QdgEuotGPn36ikxai8v5lXGNQdFmKkvhBPxG08imFxmeYD0PrYbKncdq/gIEsxob744Fcd VIWUOeEcWoq/TpfxGVWfuZnRFQZQse+LLNQS3ypKOntOSGnK6YN9hY2pjW3831qzkd+HVv ZBDCsV5wzzOqJls/K/4SV/bDn4yvwDo= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TK3ZM3bX9z1gxbG; Tue, 23 Jan 2024 18:42:35 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id B54261400D9; Tue, 23 Jan 2024 18:44:03 +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; Tue, 23 Jan 2024 18:43:38 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Jason Wang , Alexander Duyck , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Eric Dumazet , Felix Fietkau , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Andrew Morton , , , , Subject: [PATCH net-next v3 3/5] net: introduce page_frag_cache_drain() Date: Tue, 23 Jan 2024 18:42:48 +0800 Message-ID: <20240123104250.9103-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240123104250.9103-1-linyunsheng@huawei.com> References: <20240123104250.9103-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6DA1940011 X-Stat-Signature: g549968a3u6kce5kjkpww3ckug49imt9 X-Rspam-User: X-HE-Tag: 1706006662-18461 X-HE-Meta: U2FsdGVkX1/t7P8YW6gOEK5/YpOBHUAP306xsZWZ7vCJpkNmU9XO+BCOaDrdCSqzLfMU7X9BHKreH9jyZ1CiWmSwBWHlK/LBiWBmrgcBZjc0HtDisNmw1Fypq80QYGcCZhREHjT9QwFeFa1jFgJoZF2sZwNGM9H3eDyVu6o6J1C6ADXeRnIw4Z19cyiwOzTSqD7/OT4aSj/8RXmHZOp+fUFHrqsn7MssOiu4WYcu4Ql9jbkboeXHllry4BWOvjElS1nvXLJjASjfExHR2VWsrynuhqUEBcsVP20XeYSaoWyhxqhnIWr2Gb5Z2+RrYu0BHX9AxOb8pEtC3lIp7sNaZuUj4uTYpmS+5vpKi9sHyRmkoYuU2DWiiixA2vV0Vi8UH9qh2uGDyUsWQX9vNxp5s8EdKpI73qmcg3Ggx9pVJpUcNVcVBLLgeE1KxomyuRnrfhZmUVb6vDvgJmHrXPsvjqs2Rw3ytFixT7VpX2lBj0oHAS6cfI9WCwIqnxnCcwnPCggk57jFgpHoifq99aU8RI/jhH2YHyjeHIPcvaHwZwKo/ySQeEGOhpS+cxQlEkqmWFMqlkpRYvx/m0N9uD9jJ2Xxf0FkssCh6kQjwi0W6UxsU8iQthUuJ1E2oTpphmMGuPDDAHstPxJALR9uC0l1wJIhmnAP9DdMO/CZ1wYd7fFesLsmiPFNaTiuAeSB7PApcyQ/xSA6eJ/PXSF9zigCkaReCbJ4jvy2GdZKGzW3z39I2gDC7AscOENqVWEa9/Yev/xZdgyutD0EKaohOejRgMtp6h26D6CLrWAp6r1XuVI/SwU1quzHaxaL5CLs++I8hqHYDnaGmtFJtrNfzQNB6Guan+RYqdJe0QHdxFHyQIaIp5rDPMuZxVCaIgnX2ZKObWPd18hftNUPMGsmhv342w2Nd4UYTEbph8xwIC8vls1B3c1i00LHqWTsewLtkUN1Tuoivvln1mFMuM0PXRe cfpNkXM6 KL02wUdUxert7nJbOefD/l9eWBoiZw/+q1XP/uE5yjG7+0RW01MUOI00Nk31uu5Ji4ofccicspMl5aYZu4iERA7KLJGpEGqAXIEie5mB34nHysSoRhR6sg2tf6n37bXwEm7uVz8WVvqyZMJQcmRokH0GgBDBtNmp2ndabhqKySiv5stEFcNWeeIibx7iOZWg1Gq6pks5fR7QnMuWpBufq91fW94uIltkpjdgF2Tx7rpFuL//4aFBAbGJjaLc4fUdm9fHZ0drz4TmcGjjWpVKB2w7DU6VvibTYh0/3TaOhRbDYnNtaC0Hs4Dus2+lSlIrsQhN/7+nPoxOe5AQYmXScuLt42A== 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 +--- include/linux/gfp.h | 1 + mm/page_alloc.c | 10 ++++++++++ 6 files changed, 17 insertions(+), 33 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/include/linux/gfp.h b/include/linux/gfp.h index 28aea17fa59b..6cef1c241180 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -311,6 +311,7 @@ extern void __free_pages(struct page *page, unsigned int order); extern void free_pages(unsigned long addr, unsigned int order); struct page_frag_cache; +void page_frag_cache_drain(struct page_frag_cache *nc); extern void __page_frag_cache_drain(struct page *page, unsigned int count); void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 636145c29f70..06aa1ebbd21c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4699,6 +4699,16 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, return page; } +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_cache_drain(struct page *page, unsigned int count) { VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);