From: Eric Dumazet <eric.dumazet@gmail.com>
To: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: Possible bugfix for AF_UNIX, SOCK_SEQPACKET sockets
Date: Wed, 15 Feb 2012 13:42:07 +0100 [thread overview]
Message-ID: <1329309727.2437.13.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> (raw)
In-Reply-To: <CAFJW8X_1CNxe0PhxyaBjYSu0xNw0ymyDVFmsA0C5XsHK9F2D8Q@mail.gmail.com>
Le mercredi 15 février 2012 à 11:43 +0100, Piergiorgio Beruto a écrit :
> Yes, there's nothing that "doesn't work", it's a matter of performance
> (I am working on strong embedded so I'm quite concerned about both
> memory usage and "speed").
>
> The problem is that when the socket queue is filled with short sized
> packets, dequeue operation would allocate a lot of "big" chunks of
> memory, progressively smaller (first one the size of the queue, second
> one = queue size - first packet size and so on).
>
> Besides the waste of memory, you get less perfromance as malloc()
> would use the heap or mmap() depending on the size of the chunk
> (usually 64 bytes) and the use of mmap is more memory efficient but
> quite slower.
I see
> Ok, that's why I asked :) But if you agree with my objection regarding
> performance, what about adding a brand new (linux only) ioctl which
> implements the other behaviour? So the code would look something like
> this:
>
> case SIOCINQ:
> case SIOCPSZ: //// new packet size ioctl
> {
> struct sk_buff *skb;
>
> if (sk->sk_state == TCP_LISTEN) {
> err = -EINVAL;
> break;
> }
>
> spin_lock(&sk->sk_receive_queue.lock);
> if ((sk->sk_type == SOCK_STREAM ||
> sk->sk_type == SOCK_SEQPACKET) &&
> ioctl_code != SIOCPSZ) { //// have SIOCPSZ
> behave as for datagram sockets
> skb_queue_walk(&sk->sk_receive_queue, skb)
> amount += skb->len;
> } else {
> skb = skb_peek(&sk->sk_receive_queue);
> if (skb)
> amount = skb->len;
> }
> spin_unlock(&sk->sk_receive_queue.lock);
> err = put_user(amount, (int __user *)arg);
> break;
> }
ioctl() are deprecated, and such a change has ramification (for example
on strace tool)
You could use a recvmsg( ... MSG_PEEK|MSG_TRUNC) to get size of next
packet (passing a small buffer)
Ah... it seems af_unix doesnt handle MSG_TRUNC semantic as
UDP/RAW/NETLINK sockets do.
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 85d3bb7..70d9414 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1824,7 +1824,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
if (UNIXCB(skb).fp)
siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
}
- err = size;
+ err = (flags & MSG_TRUNC) ? skb->len : size;
scm_recv(sock, msg, siocb->scm, flags);
next prev parent reply other threads:[~2012-02-15 12:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 22:05 Possible bugfix for AF_UNIX, SOCK_SEQPACKET sockets Piergiorgio Beruto
2012-02-15 6:25 ` Eric Dumazet
2012-02-15 10:43 ` Piergiorgio Beruto
2012-02-15 12:42 ` Eric Dumazet [this message]
2012-02-15 17:36 ` Piergiorgio Beruto
2012-02-15 18:16 ` Eric Dumazet
2012-02-15 19:55 ` David Miller
2012-02-18 21:23 ` Piergiorgio Beruto
2012-02-22 9:24 ` [PATCH net-next] af_unix: MSG_TRUNC support for dgram sockets Eric Dumazet
2012-02-22 19:50 ` David Miller
2012-12-20 16:50 ` Michael Kerrisk (man-pages)
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=1329309727.2437.13.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=piergiorgio.beruto@gmail.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