* net: unix: Align send data_len up to PAGE_SIZE
@ 2014-05-12 14:52 Kirill Tkhai
2014-05-14 19:15 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Kirill Tkhai @ 2014-05-12 14:52 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet
Using whole of allocated pages reduces requested skb->data size.
This is just a more thriftily allocation.
netperf does not show difference with the current performance.
Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
---
net/unix/af_unix.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 749f80c..0830005 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1492,10 +1492,14 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
if (len > sk->sk_sndbuf - 32)
goto out;
- if (len > SKB_MAX_ALLOC)
+ if (len > SKB_MAX_ALLOC) {
data_len = min_t(size_t,
len - SKB_MAX_ALLOC,
MAX_SKB_FRAGS * PAGE_SIZE);
+ data_len = min_t(size_t,
+ len,
+ PAGE_ALIGN(data_len));
+ }
skb = sock_alloc_send_pskb(sk, len - data_len, data_len,
msg->msg_flags & MSG_DONTWAIT, &err,
@@ -1670,6 +1674,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
data_len = max_t(int, 0, size - SKB_MAX_HEAD(0));
+ data_len = min_t(size_t, size, PAGE_ALIGN(data_len));
+
skb = sock_alloc_send_pskb(sk, size - data_len, data_len,
msg->msg_flags & MSG_DONTWAIT, &err,
get_order(UNIX_SKB_FRAGS_SZ));
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: net: unix: Align send data_len up to PAGE_SIZE
2014-05-12 14:52 net: unix: Align send data_len up to PAGE_SIZE Kirill Tkhai
@ 2014-05-14 19:15 ` David Miller
2014-05-15 8:54 ` Kirill Tkhai
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-05-14 19:15 UTC (permalink / raw)
To: ktkhai; +Cc: netdev, edumazet
From: Kirill Tkhai <ktkhai@parallels.com>
Date: Mon, 12 May 2014 18:52:12 +0400
> data_len = min_t(size_t,
> len - SKB_MAX_ALLOC,
> MAX_SKB_FRAGS * PAGE_SIZE);
> + data_len = min_t(size_t,
> + len,
> + PAGE_ALIGN(data_len));
> + }
When I see:
x = min(y - N, z1);
x = min(y, z2);
I'm a bit suspicious. Why are you not subtracting the constant
factor out of the first variable in the second min() call?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: net: unix: Align send data_len up to PAGE_SIZE
2014-05-14 19:15 ` David Miller
@ 2014-05-15 8:54 ` Kirill Tkhai
2014-05-15 13:27 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Kirill Tkhai @ 2014-05-15 8:54 UTC (permalink / raw)
To: David Miller; +Cc: netdev, edumazet
В Ср, 14/05/2014 в 15:15 -0400, David Miller пишет:
> From: Kirill Tkhai <ktkhai@parallels.com>
> Date: Mon, 12 May 2014 18:52:12 +0400
>
> > data_len = min_t(size_t,
> > len - SKB_MAX_ALLOC,
> > MAX_SKB_FRAGS * PAGE_SIZE);
> > + data_len = min_t(size_t,
> > + len,
> > + PAGE_ALIGN(data_len));
> > + }
>
> When I see:
>
> x = min(y - N, z1);
> x = min(y, z2);
>
> I'm a bit suspicious. Why are you not subtracting the constant
> factor out of the first variable in the second min() call?
Because, in the most cases (len - SKB_MAX_ALLOC) < PAGE_ALIGN(data_len),
and the only payload of the patch is it tries to fix that :)
We use unused space of allocated page. For mem cache it's easier
to allocate
(len - PAGE_ALIGN(x)) than (len - x).
Here really should be
data_len = min_t(size_t,
len - SKB_MAX_ALLOC,
MAX_SKB_FRAGS * PAGE_SIZE);
+ data_len = PAGE_ALIGN(data_len));
I added the second min, because I was afraid somebody plays with
SKB_MAX_ALLOC size in debug purposes. Not sure now.
Ok, yes, simple PAGE_ALIGN is much better :)
+ data_len = PAGE_ALIGN(data_len));
And I assumed it's OK to allocate skbs with zero header size like this:
sock_alloc_send_pskb(sk, 0, data_len)
Please say, if it's wrong.
Thanks!
Kirill
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: net: unix: Align send data_len up to PAGE_SIZE
2014-05-15 8:54 ` Kirill Tkhai
@ 2014-05-15 13:27 ` Eric Dumazet
2014-05-15 14:27 ` Kirill Tkhai
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-05-15 13:27 UTC (permalink / raw)
To: Kirill Tkhai; +Cc: David Miller, netdev, edumazet
On Thu, 2014-05-15 at 12:54 +0400, Kirill Tkhai wrote:
>
> And I assumed it's OK to allocate skbs with zero header size like this:
>
> sock_alloc_send_pskb(sk, 0, data_len)
>
> Please say, if it's wrong.
>
Its OK
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: net: unix: Align send data_len up to PAGE_SIZE
2014-05-15 13:27 ` Eric Dumazet
@ 2014-05-15 14:27 ` Kirill Tkhai
2014-05-15 15:41 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Kirill Tkhai @ 2014-05-15 14:27 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, netdev, edumazet
В Чт, 15/05/2014 в 06:27 -0700, Eric Dumazet пишет:
> On Thu, 2014-05-15 at 12:54 +0400, Kirill Tkhai wrote:
>
> >
> > And I assumed it's OK to allocate skbs with zero header size like this:
> >
> > sock_alloc_send_pskb(sk, 0, data_len)
> >
> > Please say, if it's wrong.
> >
>
> Its OK
>
Thanks for the reply. So, new version is below.
[PATCH]net: unix: Align send data_len up to PAGE_SIZE
Using whole of allocated pages reduces requested skb->data size.
This is just a little more thriftily allocation.
netperf does not show difference with the current performance.
Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
---
net/unix/af_unix.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 749f80c..65d67c2 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1492,10 +1492,12 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
if (len > sk->sk_sndbuf - 32)
goto out;
- if (len > SKB_MAX_ALLOC)
+ if (len > SKB_MAX_ALLOC) {
data_len = min_t(size_t,
len - SKB_MAX_ALLOC,
MAX_SKB_FRAGS * PAGE_SIZE);
+ data_len = PAGE_ALIGN(data_len);
+ }
skb = sock_alloc_send_pskb(sk, len - data_len, data_len,
msg->msg_flags & MSG_DONTWAIT, &err,
@@ -1670,6 +1672,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
data_len = max_t(int, 0, size - SKB_MAX_HEAD(0));
+ data_len = min_t(size_t, size, PAGE_ALIGN(data_len));
+
skb = sock_alloc_send_pskb(sk, size - data_len, data_len,
msg->msg_flags & MSG_DONTWAIT, &err,
get_order(UNIX_SKB_FRAGS_SZ));
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: net: unix: Align send data_len up to PAGE_SIZE
2014-05-15 14:27 ` Kirill Tkhai
@ 2014-05-15 15:41 ` Eric Dumazet
0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2014-05-15 15:41 UTC (permalink / raw)
To: Kirill Tkhai; +Cc: David Miller, netdev, edumazet
On Thu, 2014-05-15 at 18:27 +0400, Kirill Tkhai wrote:
> В Чт, 15/05/2014 в 06:27 -0700, Eric Dumazet пишет:
> > On Thu, 2014-05-15 at 12:54 +0400, Kirill Tkhai wrote:
> >
> > >
> > > And I assumed it's OK to allocate skbs with zero header size like this:
> > >
> > > sock_alloc_send_pskb(sk, 0, data_len)
> > >
> > > Please say, if it's wrong.
> > >
> >
> > Its OK
> >
>
> Thanks for the reply. So, new version is below.
>
> [PATCH]net: unix: Align send data_len up to PAGE_SIZE
>
> Using whole of allocated pages reduces requested skb->data size.
> This is just a little more thriftily allocation.
>
> netperf does not show difference with the current performance.
>
> Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
> ---
> net/unix/af_unix.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 749f80c..65d67c2 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -1492,10 +1492,12 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
> if (len > sk->sk_sndbuf - 32)
> goto out;
>
> - if (len > SKB_MAX_ALLOC)
> + if (len > SKB_MAX_ALLOC) {
> data_len = min_t(size_t,
> len - SKB_MAX_ALLOC,
> MAX_SKB_FRAGS * PAGE_SIZE);
> + data_len = PAGE_ALIGN(data_len);
I would add a BUILD_BUG_ON(SKB_MAX_ALLOC < PAGE_SIZE); just to make sure
nobody ever tries to
#define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 0))
Also please send a fresh message, do not append a new patch like you
did : http://patchwork.ozlabs.org/patch/349243/
Title should be
[PATCH net-next v3] net: unix: ....
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-05-15 15:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-12 14:52 net: unix: Align send data_len up to PAGE_SIZE Kirill Tkhai
2014-05-14 19:15 ` David Miller
2014-05-15 8:54 ` Kirill Tkhai
2014-05-15 13:27 ` Eric Dumazet
2014-05-15 14:27 ` Kirill Tkhai
2014-05-15 15:41 ` Eric Dumazet
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).