From patchwork Fri Dec 1 12:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13475707 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 56A78C4167B for ; Fri, 1 Dec 2023 12:02:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8F008D0073; Fri, 1 Dec 2023 07:02:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E40358D0001; Fri, 1 Dec 2023 07:02:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D079D8D0073; Fri, 1 Dec 2023 07:02:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0C1F8D0001 for ; Fri, 1 Dec 2023 07:02:40 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9B59FA04A7 for ; Fri, 1 Dec 2023 12:02:40 +0000 (UTC) X-FDA: 81518112480.14.0BFF871 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id DE986A001E for ; Fri, 1 Dec 2023 12:02:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701432156; 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=86QPUxD7fzPZOrhagjgMOSlG5abPnKt4lm0KTc4m3Xo=; b=5w42Vx3ze012WTGRb1bI0gNUXTIjDZ0+ImcpLdNfnoQYJbBIHzqYfnUydPkt+P8Z54IJrS Bays7K/2r0qmnpxQG2DZMCcJRZ1z8Me24CiVY8uuMga79SnyawVklT1ijzt1dX0e1qydCv yWQ30aXURuvIP89ZmDgOWiT7G+8MZMA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701432156; a=rsa-sha256; cv=none; b=ZqtHJ/urY4IZrW4HfmD3T1UlQh6NZqkY0Ye4v5BMF45Hu47lT/Ys3vveTW1UNk18m3zJBP SgIWAlCGffVNh3XAPpJnckB8Gev3nvf2YFq9fOLqMZH72Fc8tQHobonTMMxq7z6BVG4coe uLXR0MNcjILzDekDY4AT5s5BBtDgtKc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4ShWmn704Gz1P91G; Fri, 1 Dec 2023 19:58:49 +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; Fri, 1 Dec 2023 20:02:30 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , 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" , Jason Wang , Andrew Morton , , , , , , Subject: [PATCH RFC 5/6] net: introduce page_frag_cache_drain() Date: Fri, 1 Dec 2023 20:02:06 +0800 Message-ID: <20231201120208.15080-6-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231201120208.15080-1-linyunsheng@huawei.com> References: <20231201120208.15080-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: DE986A001E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7sw7kaobu6qxt7x8dj6erx61efhyf38e X-HE-Tag: 1701432155-703842 X-HE-Meta: U2FsdGVkX19PKPi/ITM3y0Q6HJ8KYu6gP4gQCBtOJk1ZdNeXHCLREiWOy22ENz2WKXIXiqcYPD5ehUiAgZMF7eEti9ZrYJNvll0c3ULMPDMZK7ebMnxDaPIbA6ZNK9bYm0DqwFruS/IRn9r2ZBqB2O44X70MrZYM7uh+s4XvHOheNrMvhK6ug0o891nOyZrIrOJvvkoPercfhg42u0vNdva5ClHM9fgi/qvFrqOlu16BsqEMOBb9A9O55nDOmHFlXTCI/kI1KT72MF8pdGCIvctqKjIVl1G98MQB5zBfr7HqEz33rXfgSr3IbtH6TDSjSMTVXgi8GTysB/fbNUhqxC++ie4fOu9yROI2AQNo0Pl6eup9TkhqJzzT8o3MrmXX5HdP9O73W4JJJMWBpp74shRDx2+5Z+DnTlane6pFbWpZDpkXXLuKGMPw7xa13G+PZK+JgiRPhh590rnhVDstR/Nl/jFQfyVl0pPjnhWDPd5NubywLJc2GpCEViTxdJQzPc9UykLL02pqbmFXdwPlEd6e9H6lBPjKMgJKt3Yjsm+X0f3lQVYOfrg+90a9/GQ5lUGoknzzG/DJuFdTUgVa1h4mqd1stsXjB3f951zshiqhk65iIWD9TBk4J1Uh+uIbZVRzvOUkDzTAK4zPvEz1ZhwNxBv8owhOAIK1IP+7Wdi+OarEq6jjVh+QskhpIpkLfLb5h6Cd3HiOjNfqJR/XKBTEP+D9DJBONBNnlyszNWgXS5aSV3zCcgC4NsHXyqiBGSDDg68c6+3xPRVr45adpJLeQVIPGRZucjklrfdl03uEIk5XTRmmXucGKsC8wzipMoEnzl42N/4A9j8+GhA5Oec3s5Sl+OqK7u09w5HIATxzi9/98WFluvT3tWNF4ZR2DVZDpO4dmLnssH2RnKDRbz5wcxpEzcJcV77SWwhxZwD1f4NfaaGI3xEV6YKiLu5IIIebEfN02b3F2I55LTg XE4VT2b4 MIVzkXznRvUbQs/ZPPOK+vSQUYjT5RS7S2xH3rhWhoeJN0G7BagQWHg/zgmnsAmAoTqZoNEtLjiKhF97fy+It3+sNoEZhWkTLXzBTcfo5t2NSli8JD1VfhOUoYfqkd8BckRjWRFA7a8Vfsr30zwjH35+QhfmPcuVOGJXwLWhEOWXG/14Lnn085aeTvzawF9QwNXMTM/H6uE26EXcHPBkpgtVS9142Sv3k46F3heANL3oK40wNSMV+nxWJEg5Zdu01SsvZVzXn4WrM+ok= 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 --- 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 7ffbd4fca881..df0a3ceaf59b 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++) { @@ -298,19 +297,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); @@ -320,12 +312,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 89661a9cf850..8d4f4a06f9d9 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1338,7 +1338,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; @@ -1349,11 +1348,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 92b74d0b8686..f9a553d70a61 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)