netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] socket sk_sndmsg_page waste
@ 2011-12-06  6:53 Eric Dumazet
  2011-12-06 16:15 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2011-12-06  6:53 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

TCP can steer one page of memory per socket to cook outgoing frames.

This means a machine handling long living sockets can consume a lot of
ram.

1.000.000 tcp sockets : up to 4GB of allocated memory, if some writes
had been done on these sockets.

It would make sense to use a per thread page as a pool, instead of a per
socket pool, and remove sk_sndmsg_page/off fields.

Problem with this strategy is impact outside of net tree, and a cost at
thread creation/destruction.

[ But this could be used in fs/pipe.c or fs/splice.c code..., so that
small writes() dont allocate a full page but try to reuse the "per
task_struct" page ]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] socket sk_sndmsg_page waste
  2011-12-06  6:53 [RFC] socket sk_sndmsg_page waste Eric Dumazet
@ 2011-12-06 16:15 ` Eric Dumazet
  2011-12-06 19:01   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2011-12-06 16:15 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Le mardi 06 décembre 2011 à 07:53 +0100, Eric Dumazet a écrit :
> TCP can steer one page of memory per socket to cook outgoing frames.
> 
> This means a machine handling long living sockets can consume a lot of
> ram.
> 
> 1.000.000 tcp sockets : up to 4GB of allocated memory, if some writes
> had been done on these sockets.
> 
> It would make sense to use a per thread page as a pool, instead of a per
> socket pool, and remove sk_sndmsg_page/off fields.
> 
> Problem with this strategy is impact outside of net tree, and a cost at
> thread creation/destruction.
> 
> [ But this could be used in fs/pipe.c or fs/splice.c code..., so that
> small writes() dont allocate a full page but try to reuse the "per
> task_struct" page ]
> 
> 

Another idea would be to use a percpu variable, to get proper NUMA
affinity as well, and no extra cost at thread create/delete time.

Only 'problem' is we can sleep (pagefault) in
skb_copy_to_page_nocache(), so special care must be taken (disabling
preemption wont prevent another thread on same cpu can use the same
page)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] socket sk_sndmsg_page waste
  2011-12-06 16:15 ` Eric Dumazet
@ 2011-12-06 19:01   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2011-12-06 19:01 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 06 Dec 2011 17:15:17 +0100

> Le mardi 06 décembre 2011 à 07:53 +0100, Eric Dumazet a écrit :
>> TCP can steer one page of memory per socket to cook outgoing frames.
>> 
>> This means a machine handling long living sockets can consume a lot of
>> ram.
>> 
>> 1.000.000 tcp sockets : up to 4GB of allocated memory, if some writes
>> had been done on these sockets.
>> 
>> It would make sense to use a per thread page as a pool, instead of a per
>> socket pool, and remove sk_sndmsg_page/off fields.
>> 
>> Problem with this strategy is impact outside of net tree, and a cost at
>> thread creation/destruction.
>> 
>> [ But this could be used in fs/pipe.c or fs/splice.c code..., so that
>> small writes() dont allocate a full page but try to reuse the "per
>> task_struct" page ]
>> 
>> 
> 
> Another idea would be to use a percpu variable, to get proper NUMA
> affinity as well, and no extra cost at thread create/delete time.
> 
> Only 'problem' is we can sleep (pagefault) in
> skb_copy_to_page_nocache(), so special care must be taken (disabling
> preemption wont prevent another thread on same cpu can use the same
> page)

I think you're going to end up adding overhead to implement this properly,
first you'll make it per-thread but then you'll want a per-cpu array
per-thread to get NUMA affinities et al. right.

Also, keeping the page per-socket gives a certain piece of mind, that
leaking socket data from one connection to another accidently is that
much less likely.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-06 19:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-06  6:53 [RFC] socket sk_sndmsg_page waste Eric Dumazet
2011-12-06 16:15 ` Eric Dumazet
2011-12-06 19:01   ` David Miller

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).