From patchwork Mon Feb 5 12:45:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13545467 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 B2070C4829B for ; Mon, 5 Feb 2024 12:46:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9C556B00A3; Mon, 5 Feb 2024 07:46:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD2A86B00A4; Mon, 5 Feb 2024 07:46:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99AA06B00A5; Mon, 5 Feb 2024 07:46:09 -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 8691E6B00A3 for ; Mon, 5 Feb 2024 07:46:09 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 612F1160155 for ; Mon, 5 Feb 2024 12:46:09 +0000 (UTC) X-FDA: 81757722858.20.48A6D4A Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf21.hostedemail.com (Postfix) with ESMTP id D97AA1C0023 for ; Mon, 5 Feb 2024 12:46:06 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 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=1707137167; 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=LFeLLnJaR3JtjOxpUpdms1bffkbapejcBiKMtBdfGb8=; b=CE04DXP4mvBq94FBRNBsBWwNk0IimWat5Wf3/fwL/j99bwSWtjWX7AcHdJAUSIqWR1QbOp QI1XkUxardl05/35dtLHQFUya6z19Ya2rG5EN7eL40BybpB+U9OrMYB1IOOOM9Cw6+xsfc 3qIMuTUVnkLOLMyGQnF89Mbr29QdY4M= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707137167; a=rsa-sha256; cv=none; b=OrKwqOx4T2GiK1rhbrYlAGbCKlUmqd5G58eZ+SoGDNAlh4S+iGxk8TUwBBd38kJbYQUdDw DOhTn7HKY+6XKsdit6ysvcnD0YG27Zn+fs+SU5hqgclx8b74/DWf2AO4hTa7QiXDz6oa4L F8OLwarn3+2i+Xxqo+bhRd+Ok3jN31g= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TT5gY14XFz1xn3N; Mon, 5 Feb 2024 20:44:57 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 95B841400C9; Mon, 5 Feb 2024 20:46:02 +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; Mon, 5 Feb 2024 20:46:02 +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 v5 3/5] net: introduce page_frag_cache_drain() Date: Mon, 5 Feb 2024 20:45:03 +0800 Message-ID: <20240205124506.57670-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240205124506.57670-1-linyunsheng@huawei.com> References: <20240205124506.57670-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D97AA1C0023 X-Stat-Signature: qschp6pon5m9yxj1d33cx3r4myxb58wu X-HE-Tag: 1707137166-301118 X-HE-Meta: U2FsdGVkX1+zo4R1FuS0ttdydp+unKhZ6A7lxmXeqxwI7GoHTshWG0s5rA84OY0gfWOezcgJhTQaiakLv3KitMtO+MN9AoQu9w/OIaaOH7B36TKfjKH1GoaAygPz2hSjIcNjOtkaj0jY0VJkIEoPbltul5DcnUsnAxCpM4Vua/B0nuWTKlzsfCCG5xAebt1dFwHl3u1sbj5/y5hU2/4DMmemFpszgbJWoaRufASisxQ2gmBg6dS4/GhkRO9BIxZmybHLggde8GZhFcrLIKydqU2LYg2/iycyzbvLPJA2lVw0zo8e+wFZC1m7tqPGU7CrKkPgHp9Yug7P2PwV2RdSXc4zm4qRiAMBghF2QdrhxGC59L3MhsRjsmkfqhIiGAwYmSDTiDPrrYIYW1L5kDl63Us5hAqzCAqiCiyVlNHQteA/1zKQPfuvVpU+2wTgsoCJT3vz72FTGx/xsxDqhLm1Yd9AKlu9wTGqTyFmWi8N19OEiggOM9crC7g5cyfWNYA4YSWV3MFvk90zguJ+bFCzFRUBYlGnUspUSOEov7axuijyB9T0SAaA1lQHl47qetBIkZMW0/hJ+hB3bIvICbUFkB5oK0Iho9ud+8IlpunYRY3Lqi2MpHnPF9567aciiX0ltc9KwYsSVZB1rzS+LrglowbsMIhsvvvlJur87CTnRxEG3OVkHB5d57U/cWXU6X+t7+DAetuX7jSnfE+lXmcYJCerTgjYOySZwq9Oc2LXnEAUKop8wGNwoKSZopD+nFpBCLqvBMjN0xBRsn0WDsGDrc2bhUhywgPB25oveWNFk5OhsvH7x8Px+RKTVqleC6iLG933B9marKtSCI3ey/53yMgC5BsvZQBE0TS+JO+jNymli1Ggwz9avkKcsoaCj/0Kvs1pLUO0XrYzAcfZo7+ZNsAPbTvpJEy5di2rNWq2RX6wS2u8EGg3hYUL/yaL8Cz2jfVXoqcaC+S1r3ZBbYV x7SBdP2W mLRpX9LTwzc1MTV30YXmz+azlZTfoQpGhhwU+LkRnK7bK0p/vZ02RPzT1anLRx0dCSOEbSTAgGY3OKpQtT4nMvTGaoasvmiLOe/WjBoG3ujTSB737r79LTOtdHdkmOVx2FLU2zWG1+zAAxaNpTv8aXcH6btn8rk3vV6N4ImnB6QNrGF3AWsZ+oC+3XGdQ1d2MCi2ApOcsPTYeXNUbJnd4/1M0RhWJKVSUM48aH+ZYiDoqeDw6MdZy+rXH5cOJGeXY0E9h52KAS62/zTs/tmv6PFkc/WclFHPE3RJm0YitWC+xaZButGUGN+eIzQWh+U+5s/ghc8UcG1SSLNLj+LeZC0enpX8M7VV2RgeM 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 db6d9ae7cd78..dec6458bb8d7 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1276,17 +1276,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 void gve_qpls_get_curr_alloc_cfg(struct gve_priv *priv, 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 d058d990532b..22e1fb9c9c0f 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 6a1e6bb80062..56224dc59f17 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1591,7 +1591,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); @@ -1615,8 +1614,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);