From: Chuck Lever <chuck.lever@oracle.com>
To: Yunsheng Lin <linyunsheng@huawei.com>
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Alexander Duyck" <alexander.duyck@gmail.com>,
"Alexander Duyck" <alexanderduyck@fb.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Eric Dumazet" <edumazet@google.com>,
"David Howells" <dhowells@redhat.com>,
"Marc Dionne" <marc.dionne@auristor.com>,
"Trond Myklebust" <trondmy@kernel.org>,
"Anna Schumaker" <anna@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>, "Neil Brown" <neilb@suse.de>,
"Olga Kornievskaia" <kolga@netapp.com>,
"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
kvm@vger.kernel.org, virtualization@lists.linux.dev,
linux-mm@kvack.org, linux-afs@lists.infradead.org,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH net-next v12 05/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly
Date: Wed, 31 Jul 2024 09:36:34 -0400 [thread overview]
Message-ID: <Zqo94stnPVJNvmc+@tissot.1015granger.net> (raw)
In-Reply-To: <20240731124505.2903877-6-linyunsheng@huawei.com>
On Wed, Jul 31, 2024 at 08:44:55PM +0800, Yunsheng Lin wrote:
> Use appropriate frag_page API instead of caller accessing
> 'page_frag_cache' directly.
>
> CC: Alexander Duyck <alexander.duyck@gmail.com>
> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
For the net/sunrpc/svcsock.c hunk:
Acked-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> drivers/vhost/net.c | 2 +-
> include/linux/page_frag_cache.h | 10 ++++++++++
> mm/page_frag_test.c | 2 +-
> net/core/skbuff.c | 6 +++---
> net/rxrpc/conn_object.c | 4 +---
> net/rxrpc/local_object.c | 4 +---
> net/sunrpc/svcsock.c | 6 ++----
> 7 files changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 6691fac01e0d..b2737dc0dc50 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -1325,7 +1325,7 @@ static int vhost_net_open(struct inode *inode, struct file *f)
> vqs[VHOST_NET_VQ_RX]);
>
> f->private_data = n;
> - n->pf_cache.va = NULL;
> + page_frag_cache_init(&n->pf_cache);
>
> return 0;
> }
> diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h
> index ef038a07925c..7c9125a9aed3 100644
> --- a/include/linux/page_frag_cache.h
> +++ b/include/linux/page_frag_cache.h
> @@ -7,6 +7,16 @@
> #include <linux/types.h>
> #include <linux/mm_types_task.h>
>
> +static inline void page_frag_cache_init(struct page_frag_cache *nc)
> +{
> + nc->va = NULL;
> +}
> +
> +static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *nc)
> +{
> + return !!nc->pfmemalloc;
> +}
> +
> void page_frag_cache_drain(struct page_frag_cache *nc);
> void __page_frag_cache_drain(struct page *page, unsigned int count);
> void *__page_frag_alloc_va_align(struct page_frag_cache *nc,
> diff --git a/mm/page_frag_test.c b/mm/page_frag_test.c
> index 9eaa3ab74b29..6df8d8865afe 100644
> --- a/mm/page_frag_test.c
> +++ b/mm/page_frag_test.c
> @@ -344,7 +344,7 @@ static int __init page_frag_test_init(void)
> u64 duration;
> int ret;
>
> - test_frag.va = NULL;
> + page_frag_cache_init(&test_frag);
> atomic_set(&nthreads, 2);
> init_completion(&wait);
>
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 4b8acd967793..76a473b1072d 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -749,14 +749,14 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
> if (in_hardirq() || irqs_disabled()) {
> nc = this_cpu_ptr(&netdev_alloc_cache);
> data = page_frag_alloc_va(nc, len, gfp_mask);
> - pfmemalloc = nc->pfmemalloc;
> + pfmemalloc = page_frag_cache_is_pfmemalloc(nc);
> } else {
> local_bh_disable();
> local_lock_nested_bh(&napi_alloc_cache.bh_lock);
>
> nc = this_cpu_ptr(&napi_alloc_cache.page);
> data = page_frag_alloc_va(nc, len, gfp_mask);
> - pfmemalloc = nc->pfmemalloc;
> + pfmemalloc = page_frag_cache_is_pfmemalloc(nc);
>
> local_unlock_nested_bh(&napi_alloc_cache.bh_lock);
> local_bh_enable();
> @@ -846,7 +846,7 @@ struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len)
> len = SKB_HEAD_ALIGN(len);
>
> data = page_frag_alloc_va(&nc->page, len, gfp_mask);
> - pfmemalloc = nc->page.pfmemalloc;
> + pfmemalloc = page_frag_cache_is_pfmemalloc(&nc->page);
> }
> local_unlock_nested_bh(&napi_alloc_cache.bh_lock);
>
> diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c
> index 1539d315afe7..694c4df7a1a3 100644
> --- a/net/rxrpc/conn_object.c
> +++ b/net/rxrpc/conn_object.c
> @@ -337,9 +337,7 @@ static void rxrpc_clean_up_connection(struct work_struct *work)
> */
> rxrpc_purge_queue(&conn->rx_queue);
>
> - if (conn->tx_data_alloc.va)
> - __page_frag_cache_drain(virt_to_page(conn->tx_data_alloc.va),
> - conn->tx_data_alloc.pagecnt_bias);
> + page_frag_cache_drain(&conn->tx_data_alloc);
> call_rcu(&conn->rcu, rxrpc_rcu_free_connection);
> }
>
> diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
> index 504453c688d7..a8cffe47cf01 100644
> --- a/net/rxrpc/local_object.c
> +++ b/net/rxrpc/local_object.c
> @@ -452,9 +452,7 @@ void rxrpc_destroy_local(struct rxrpc_local *local)
> #endif
> rxrpc_purge_queue(&local->rx_queue);
> rxrpc_purge_client_connections(local);
> - if (local->tx_alloc.va)
> - __page_frag_cache_drain(virt_to_page(local->tx_alloc.va),
> - local->tx_alloc.pagecnt_bias);
> + page_frag_cache_drain(&local->tx_alloc);
> }
>
> /*
> diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
> index 42d20412c1c3..4b1e87187614 100644
> --- a/net/sunrpc/svcsock.c
> +++ b/net/sunrpc/svcsock.c
> @@ -1609,7 +1609,6 @@ static void svc_tcp_sock_detach(struct svc_xprt *xprt)
> static void svc_sock_free(struct svc_xprt *xprt)
> {
> struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
> - struct page_frag_cache *pfc = &svsk->sk_frag_cache;
> struct socket *sock = svsk->sk_sock;
>
> trace_svcsock_free(svsk, sock);
> @@ -1619,8 +1618,7 @@ static void svc_sock_free(struct svc_xprt *xprt)
> sockfd_put(sock);
> else
> sock_release(sock);
> - if (pfc->va)
> - __page_frag_cache_drain(virt_to_head_page(pfc->va),
> - pfc->pagecnt_bias);
> +
> + page_frag_cache_drain(&svsk->sk_frag_cache);
> kfree(svsk);
> }
> --
> 2.33.0
>
--
Chuck Lever
next prev parent reply other threads:[~2024-07-31 13:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240731124505.2903877-1-linyunsheng@huawei.com>
2024-07-31 12:44 ` [PATCH net-next v12 01/14] mm: page_frag: add a test module for page_frag Yunsheng Lin
2024-07-31 18:29 ` Alexander Duyck
2024-08-01 12:58 ` Yunsheng Lin
2024-08-01 14:50 ` Alexander Duyck
2024-08-02 10:02 ` Yunsheng Lin
2024-08-02 16:42 ` Alexander Duyck
2024-07-31 12:44 ` [PATCH net-next v12 02/14] mm: move the page fragment allocator from page_alloc into its own file Yunsheng Lin
2024-07-31 12:44 ` [PATCH net-next v12 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Yunsheng Lin
2024-07-31 12:44 ` [PATCH net-next v12 04/14] mm: page_frag: add '_va' suffix to page_frag API Yunsheng Lin
2024-07-31 13:36 ` Chuck Lever
2024-07-31 18:13 ` Alexander Duyck
2024-08-01 13:01 ` Yunsheng Lin
2024-08-01 15:21 ` Alexander Duyck
2024-08-02 10:05 ` Yunsheng Lin
2024-08-02 17:00 ` Alexander Duyck
[not found] ` <2a29ce61-7136-4b9b-9940-504228b10cba@gmail.com>
2024-08-06 0:52 ` Alexander Duyck
2024-08-06 11:37 ` Yunsheng Lin
2024-08-04 6:44 ` Sagi Grimberg
2024-07-31 12:44 ` [PATCH net-next v12 05/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Yunsheng Lin
2024-07-31 13:36 ` Chuck Lever [this message]
2024-07-31 12:44 ` [PATCH net-next v12 07/14] mm: page_frag: reuse existing space for 'size' and 'pfmemalloc' Yunsheng Lin
2024-07-31 12:44 ` [PATCH net-next v12 08/14] mm: page_frag: some minor refactoring before adding new API Yunsheng Lin
2024-07-31 12:44 ` [PATCH net-next v12 09/14] mm: page_frag: use __alloc_pages() to replace alloc_pages_node() Yunsheng Lin
2024-07-31 12:45 ` [PATCH net-next v12 11/14] mm: page_frag: introduce prepare/probe/commit API Yunsheng Lin
2024-07-31 12:45 ` [PATCH net-next v12 13/14] mm: page_frag: update documentation for page_frag Yunsheng Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zqo94stnPVJNvmc+@tissot.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=Dai.Ngo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=alexanderduyck@fb.com \
--cc=anna@kernel.org \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=jlayton@kernel.org \
--cc=kolga@netapp.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linyunsheng@huawei.com \
--cc=marc.dionne@auristor.com \
--cc=mst@redhat.com \
--cc=neilb@suse.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox