From patchwork Wed May 24 15:33:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254196 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 254C2C77B7A for ; Wed, 24 May 2023 15:33:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA53D90000F; Wed, 24 May 2023 11:33:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A55BF900007; Wed, 24 May 2023 11:33:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF6390000F; Wed, 24 May 2023 11:33:30 -0400 (EDT) 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 7D9C5900007 for ; Wed, 24 May 2023 11:33:30 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5EF0C1A0236 for ; Wed, 24 May 2023 15:33:30 +0000 (UTC) X-FDA: 80825542980.28.FAD2E83 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 8ECD4180015 for ; Wed, 24 May 2023 15:33:27 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ipcX4hbU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684942407; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5Xt/kb1I9tBW/zHVjBQrREyGjijOb+tpZUMT6BFY+/c=; b=Tt3Sa6W2UMPdwXQ+5RDRGYbtIp24oaD7WS9xZpiwKaoJfW0Pit2571mbCNfPxbXIFj3TSK xuWS1rvTUdeVCrr3km5oCknjBbrGG0UxiYAU1NsQ+Zmu2xzcoH2DTA26nmVtvnZOHINTQM +H2mX+dpPkvpK2WOLfT5bR2+D1+0n8g= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ipcX4hbU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684942407; a=rsa-sha256; cv=none; b=TvtEc/7HJvS/RriTklYPS0cDIit5K05O25Rv5voKHCbMBYkg4+LVTVwdOOb6r3wDnZLhNh lbwAxu9YjDI7hVOP0sHGpiC+FMOPt/r4srCaPED93yuxlaPlon2UP6wyxUupGK+l7JwGSv QPK4GwDrpTpTP1+UOhrLNFCbLkujM3g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684942406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Xt/kb1I9tBW/zHVjBQrREyGjijOb+tpZUMT6BFY+/c=; b=ipcX4hbUtTGcvOpbBoKovNUg+AyRGe5NZ78quQ8zxsJNhOWBbWAy4Q0970Qckc6mMQ0v4f 8tCM/3+Tk7+GmnHVVGibHplldE14h5Dqi7T10mriarBOOxgSpVjrg8EC2XAYZ5WQ8TDM40 YcZwfzNpwVgzKTy9mS7BiJ6cUgTnWoA= 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-147-h5Ilq50YMBixAqm1S8Ipag-1; Wed, 24 May 2023 11:33:24 -0400 X-MC-Unique: h5Ilq50YMBixAqm1S8Ipag-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52D53280BC8A; Wed, 24 May 2023 15:33:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24FB920296C8; Wed, 24 May 2023 15:33:18 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jeroen de Borst , Catherine Sullivan , Shailend Chand , 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 , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-nvme@lists.infradead.org Subject: [PATCH net-next 02/12] mm: Provide a page_frag_cache allocator cleanup function Date: Wed, 24 May 2023 16:33:01 +0100 Message-Id: <20230524153311.3625329-3-dhowells@redhat.com> In-Reply-To: <20230524153311.3625329-1-dhowells@redhat.com> References: <20230524153311.3625329-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8ECD4180015 X-Stat-Signature: pxwfwpukrp3dyynespbrx3xq6b4qr49e X-Rspam-User: X-HE-Tag: 1684942407-477521 X-HE-Meta: U2FsdGVkX19TCFYraRZtzxGxPQ6XJf07DkvcC8HVYOQq4LWN4Rh0LPfbGhM6E0Xr6IaXotWfu4y9MnrMOe9VgduexwaRzcNSYjx/+GWy5z9a8pwEhZvmYccJxTbJkVcbhOjJ4Wpetz0jCc3/cRgbPuudR6VuvVF+j0FkaIdQIp6a71Q82V5kfBeTJtuLDsfJEJcSOaC9Bc7cyjgVl4W68VGm1aLRSeNjvi11oUHJDd9CsSvD+DD3EFcZyhLwDjWKQyysZCStbO5NWPmXJcapafCA+rCowE629//iGiZEqCrG1Wc6OxjHSTJY/9vHOl0ljKidZJYCPS9dCFLkAKRWscocOryA5G6BXYJH7trr9BNZuC8tObDnnvpwVl82yMa+FrXLZEzmVz/m2B3ikl0EVJi09dcGZ6tPX9iCfRKSNbadW8rkbjYtZ/BF6UayGBT/6Am6se8yg6nglcIf6UF4g+hXvOqo/jtjljmArhT0X68pjJXuOeF7qlGxLUgbudgTtz74uV+svuLnLfE4uavhjwIbjircKjxbLZqDFPGv2wKAAKb/HT8dVhGR4Bv6BdAiA0uCqwNRNcMRqDcKWfsJsRKoGh4xZGCHr6cdY8eNcyUJTBOvGCzQ0ZQ15kMi3lCznzuilC8G5SjYM3ZdD44xJuiGvAHYCUrcDGe6nQDW2RTc2Rak2U44TUvCyBXbkmjzaXEaCauW80Nt0+eoZBMl/XazuPGiCo+58xJQCT1LWxLYtJnyj6qOSodQAfhSoV85kB9aE4xXXzZrHzaJi/5M2cNnQ+0S+37M0fS+o21Ci5+LK+40MFMephV87MM9R8oa+EuARZra8aEDlQJGpZPE0pkW1acWJxFVybLmDH1toRiNT5aEOWdCthXKtLWv1bSIfd6ZuAQ/yiNngsUHAr62iETky4IjdsISwXuCB865aZwqTb3MtdbYm3/pLavLrgAlMQFiI4QDqEhpdyv8SIv oZfAHTZt fBN1qlYNgkrXxub1pvcfXYgkfL7WhyMn/8a35jKpmkXkvt4Oi6/7y2idSbO+137CUfz9/8Cu0LkQjhMfV/SddbplnfqcV1DXshFCvSFs2UjFJPgpY2Yc+EmbiRWdRQTxSyksOWpdUU0N5Fz9yuCGkvxaIqXH5+55az7DeSLSzq0ezSdrQ0zmJDHnzkIsc0mJovYwO/AdqbX629oZQx+VFNpB6VW80mktZQzos06OC1aet6sWt+Tda3ri0JER1hbodAFOmsgsue94BRQWJXkG/DoZLxm23xy6GwzZ2ng04bRct+n8qqKqHwGw037DVO4nEHKDyzjAjR4gdFEdyyLocodNna7M1PwgtQ43aci2ZFLD2xGwN7aJPQ4MtFLe9TnMJ+EFutCFL3pv9T/ztaShFcHu0Bn2DpXrQy4wIhk5rckdMm4dG9e4cCFjFoIsou8bAqkYNHLWBEbDok8M7jrxU2DzAsd79XxpIKXOAN8saOV0dfzOP9JAQ6oY6eVv256lKcCDVDFB6LuLEu7pQXMhgwFusfIDvA0onJH6+sfhczecYLOrIQuuYOa62N8Y/y+fIGZUmqmi8fMGW8bYhcrUihQ6GzZL7KEylnRQnRbrovhonbtPliVu2G8OThMjQIDQ1YBBV1Eo9qbxYrNIfoxuItd4yJgyMXgVBVL6M88J015ZhQdrdsLdWXV4o1DdoUJCIk5o9kBZF3sTFswlwuo7cbGooR5W7DyhBzxjGuJ0tfLyGhQos/P+rPgLYbNpX7wcTNrC/F8XGwIFIRYWUGM9KVTRsDRIGvbFZ7Yd2jKD8Jrf10QH+E3VoCHoSSK49X9kG96iCtqQA1qTy3jmaXWGI7DMmjWgh3mOmwWBcvC7zpDLmNDumT5lpimGOMhk/NqCSoelX0qjc+FMMLCk= 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: Provide a function to clean up a page_frag_cache allocator rather than doing it manually each time. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Jeroen de Borst cc: Catherine Sullivan cc: Shailend Chand cc: Felix Fietkau cc: John Crispin cc: Sean Wang cc: Mark Lee cc: Lorenzo Bianconi cc: Matthias Brugger cc: AngeloGioacchino Del Regno cc: Keith Busch cc: Jens Axboe cc: Christoph Hellwig cc: Sagi Grimberg cc: Chaitanya Kulkarni cc: Andrew Morton cc: Matthew Wilcox cc: netdev@vger.kernel.org cc: linux-arm-kernel@lists.infradead.org cc: linux-mediatek@lists.infradead.org cc: linux-nvme@lists.infradead.org cc: linux-mm@kvack.org --- drivers/net/ethernet/google/gve/gve_main.c | 11 ++--------- drivers/net/ethernet/mediatek/mtk_wed_wo.c | 17 ++--------------- drivers/nvme/host/tcp.c | 8 +------- drivers/nvme/target/tcp.c | 5 +---- include/linux/gfp.h | 2 ++ mm/page_frag_alloc.c | 17 +++++++++++++++++ 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 8fb70db63b8b..55feab29bed9 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1251,17 +1251,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_clear(&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 69fba29055e9..d90fea2c7d04 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_clear(&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_clear(&q->cache); } static void diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index bf0230442d57..dcc35f6bff8c 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1315,7 +1315,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; @@ -1326,12 +1325,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_clear(&queue->pf_cache); noreclaim_flag = memalloc_noreclaim_save(); sock_release(queue->sock); memalloc_noreclaim_restore(noreclaim_flag); diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index ed98df72c76b..984e6ce85dcd 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1464,7 +1464,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); @@ -1486,9 +1485,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_clear(&queue->pf_cache); kfree(queue); } diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ed8cb537c6a7..03504beb51e4 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -314,6 +314,8 @@ static inline void *page_frag_alloc(struct page_frag_cache *nc, return page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); } +void page_frag_cache_clear(struct page_frag_cache *nc); + extern void page_frag_free(void *addr); #define __free_page(page) __free_pages((page), 0) diff --git a/mm/page_frag_alloc.c b/mm/page_frag_alloc.c index bee95824ef8f..e02b81d68dc4 100644 --- a/mm/page_frag_alloc.c +++ b/mm/page_frag_alloc.c @@ -46,6 +46,23 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); +/** + * page_frag_cache_clear - Clear out a page fragment cache + * @nc: The cache to clear + * + * Discard any pages still cached in a page fragment cache. + */ +void page_frag_cache_clear(struct page_frag_cache *nc) +{ + if (nc->va) { + struct page *page = virt_to_head_page(nc->va); + + __page_frag_cache_drain(page, nc->pagecnt_bias); + nc->va = NULL; + } +} +EXPORT_SYMBOL(page_frag_cache_clear); + void *page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask)