From: Paolo Abeni <pabeni@redhat.com>
To: Benjamin Coddington <bcodding@redhat.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>
Cc: "Guillaume Nault" <gnault@redhat.com>,
"Philipp Reisner" <philipp.reisner@linbit.com>,
"Lars Ellenberg" <lars.ellenberg@linbit.com>,
"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>,
"Jens Axboe" <axboe@kernel.dk>,
"Josef Bacik" <josef@toxicpanda.com>,
"Keith Busch" <kbusch@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Sagi Grimberg" <sagi@grimberg.me>,
"Lee Duncan" <lduncan@suse.com>,
"Chris Leech" <cleech@redhat.com>,
"Mike Christie" <michael.christie@oracle.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Valentina Manea" <valentina.manea.m@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"David Howells" <dhowells@redhat.com>,
"Marc Dionne" <marc.dionne@auristor.com>,
"Steve French" <sfrench@samba.org>,
"Christine Caulfield" <ccaulfie@redhat.com>,
"David Teigland" <teigland@redhat.com>,
"Mark Fasheh" <mark@fasheh.com>,
"Joel Becker" <jlbec@evilplan.org>,
"Joseph Qi" <joseph.qi@linux.alibaba.com>,
"Eric Van Hensbergen" <ericvh@gmail.com>,
"Latchesar Ionkov" <lucho@ionkov.net>,
"Dominique Martinet" <asmadeus@codewreck.org>,
"Ilya Dryomov" <idryomov@gmail.com>,
"Xiubo Li" <xiubli@redhat.com>,
"Chuck Lever" <chuck.lever@oracle.com>,
"Jeff Layton" <jlayton@kernel.org>,
"Trond Myklebust" <trond.myklebust@hammerspace.com>,
"Anna Schumaker" <anna@kernel.org>,
"Steffen Klassert" <steffen.klassert@secunet.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
netdev@vger.kernel.org
Subject: Re: [PATCH net v3 1/3] net: Introduce sk_use_task_frag in struct sock.
Date: Thu, 15 Dec 2022 13:08:15 +0100 [thread overview]
Message-ID: <877d0130f434ac6f8066711cb6cdca09c7767843.camel@redhat.com> (raw)
In-Reply-To: <1a369325ac2d4a604a074428f58fa72a6065e197.1670929442.git.bcodding@redhat.com>
On Tue, 2022-12-13 at 06:10 -0500, Benjamin Coddington wrote:
> From: Guillaume Nault <gnault@redhat.com>
>
> Sockets that can be used while recursing into memory reclaim, like
> those used by network block devices and file systems, mustn't use
> current->task_frag: if the current process is already using it, then
> the inner memory reclaim call would corrupt the task_frag structure.
>
> To avoid this, sk_page_frag() uses ->sk_allocation to detect sockets
> that mustn't use current->task_frag, assuming that those used during
> memory reclaim had their allocation constraints reflected in
> ->sk_allocation.
>
> This unfortunately doesn't cover all cases: in an attempt to remove all
> usage of GFP_NOFS and GFP_NOIO, sunrpc stopped setting these flags in
> ->sk_allocation, and used memalloc_nofs critical sections instead.
> This breaks the sk_page_frag() heuristic since the allocation
> constraints are now stored in current->flags, which sk_page_frag()
> can't read without risking triggering a cache miss and slowing down
> TCP's fast path.
>
> This patch creates a new field in struct sock, named sk_use_task_frag,
> which sockets with memory reclaim constraints can set to false if they
> can't safely use current->task_frag. In such cases, sk_page_frag() now
> always returns the socket's page_frag (->sk_frag). The first user is
> sunrpc, which needs to avoid using current->task_frag but can keep
> ->sk_allocation set to GFP_KERNEL otherwise.
>
> Eventually, it might be possible to simplify sk_page_frag() by only
> testing ->sk_use_task_frag and avoid relying on the ->sk_allocation
> heuristic entirely (assuming other sockets will set ->sk_use_task_frag
> according to their constraints in the future).
>
> The new ->sk_use_task_frag field is placed in a hole in struct sock and
> belongs to a cache line shared with ->sk_shutdown. Therefore it should
> be hot and shouldn't have negative performance impacts on TCP's fast
> path (sk_shutdown is tested just before the while() loop in
> tcp_sendmsg_locked()).
>
> Link: https://lore.kernel.org/netdev/b4d8cb09c913d3e34f853736f3f5628abfd7f4b6.1656699567.git.gnault@redhat.com/
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
> ---
> include/net/sock.h | 11 +++++++++--
> net/core/sock.c | 1 +
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index e0517ecc6531..44380c6dc6c4 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -318,6 +318,9 @@ struct sk_filter;
> * @sk_stamp: time stamp of last packet received
> * @sk_stamp_seq: lock for accessing sk_stamp on 32 bit architectures only
> * @sk_tsflags: SO_TIMESTAMPING flags
> + * @sk_use_task_frag: allow sk_page_frag() to use current->task_frag.
> + * Sockets that can be used under memory reclaim should
> + * set this to false.
> * @sk_bind_phc: SO_TIMESTAMPING bind PHC index of PTP virtual clock
> * for timestamping
> * @sk_tskey: counter to disambiguate concurrent tstamp requests
> @@ -505,6 +508,7 @@ struct sock {
> #endif
> u16 sk_tsflags;
> u8 sk_shutdown;
> + bool sk_use_task_frag;
> atomic_t sk_tskey;
> atomic_t sk_zckey;
I'm sorry, but after the post PR -net -> net-next merge, this does not
apply cleanly any-more, you need to rebase it once more.
Note that commit b534dc46c8ae ("net_tstamp: add
SOF_TIMESTAMPING_OPT_ID_TCP") moved the surronding fields a bit but
there is still one byte hole after sk_txtime_unused, before sk_socket.
Thanks!
Paolo
next prev parent reply other threads:[~2022-12-15 12:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-13 11:10 [PATCH net v3 0/3] Stop corrupting socket's task_frag Benjamin Coddington
2022-12-13 11:10 ` [PATCH net v3 1/3] net: Introduce sk_use_task_frag in struct sock Benjamin Coddington
2022-12-15 12:08 ` Paolo Abeni [this message]
2022-12-13 11:10 ` [PATCH net v3 2/3] Treewide: Stop corrupting socket's task_frag Benjamin Coddington
2022-12-13 11:10 ` [PATCH net v3 3/3] net: simplify sk_page_frag Benjamin Coddington
2022-12-15 12:12 ` [PATCH net v3 2/3] Treewide: Stop corrupting socket's task_frag David Howells
2022-12-15 13:59 ` Guillaume Nault
2022-12-15 14:36 ` David Howells
2022-12-15 15:37 ` Guillaume Nault
-- strict thread matches above, loose matches on Subject: below --
2022-12-10 4:11 [PATCH net v2 1/3] net: Introduce sk_use_task_frag in struct sock Jakub Kicinski
2022-12-11 11:20 ` [PATCH net v3 " Benjamin Coddington
2022-12-12 23:14 ` Jakub Kicinski
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=877d0130f434ac6f8066711cb6cdca09c7767843.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=anna@kernel.org \
--cc=asmadeus@codewreck.org \
--cc=axboe@kernel.dk \
--cc=bcodding@redhat.com \
--cc=ccaulfie@redhat.com \
--cc=christoph.boehmwalder@linbit.com \
--cc=chuck.lever@oracle.com \
--cc=cleech@redhat.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=ericvh@gmail.com \
--cc=gnault@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=herbert@gondor.apana.org.au \
--cc=idryomov@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=jlayton@kernel.org \
--cc=jlbec@evilplan.org \
--cc=josef@toxicpanda.com \
--cc=joseph.qi@linux.alibaba.com \
--cc=kbusch@kernel.org \
--cc=kuba@kernel.org \
--cc=lars.ellenberg@linbit.com \
--cc=lduncan@suse.com \
--cc=lucho@ionkov.net \
--cc=marc.dionne@auristor.com \
--cc=mark@fasheh.com \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=netdev@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
--cc=sagi@grimberg.me \
--cc=sfrench@samba.org \
--cc=shuah@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=teigland@redhat.com \
--cc=trond.myklebust@hammerspace.com \
--cc=valentina.manea.m@gmail.com \
--cc=xiubli@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).