From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Michal Sojka <sojkam1@fel.cvut.cz>, linux-can@vger.kernel.org
Cc: yegorslists@googlemail.com
Subject: Re: [PATCH RFC 2/2] net: Make minimum SO_SNDBUF size dependent on the protocol family
Date: Fri, 17 Jan 2014 10:08:00 +0100 [thread overview]
Message-ID: <52D8F2F0.3080305@pengutronix.de> (raw)
In-Reply-To: <1389902301-24505-2-git-send-email-sojkam1@fel.cvut.cz>
[-- Attachment #1: Type: text/plain, Size: 3777 bytes --]
On 01/16/2014 08:58 PM, Michal Sojka wrote:
> For CAN bus it is desired to have the size of the socket send queue
> much smaller than for Ethernet-based protocols. This patch makes the
> limit for setsockopt(SO_SNDBUF) values smaller for PF_CAN sockets.
Why don't you introduce another define, that's only used in
sock_setsockopt, so you don't have to change any tcp hot path related
functions?
Marc
> Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
> ---
> include/net/sock.h | 11 +++++++++--
> include/net/tcp.h | 2 +-
> net/can/raw.c | 1 +
> net/core/sock.c | 2 +-
> 4 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 808cbc2..54d26e6 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -969,6 +969,7 @@ struct proto {
> int *sysctl_rmem;
> int max_header;
> bool no_autobind;
> + int min_sndbuf;
>
> struct kmem_cache *slab;
> unsigned int obj_size;
> @@ -2072,14 +2073,20 @@ static inline void sk_wake_async(struct sock *sk, int how, int band)
> */
> #define TCP_SKB_MIN_TRUESIZE (2048 + SKB_DATA_ALIGN(sizeof(struct sk_buff)))
>
> -#define SOCK_MIN_SNDBUF (TCP_SKB_MIN_TRUESIZE * 2)
> +#define SOCK_MIN_SNDBUF(sk) ((sk)->sk_prot->min_sndbuf ? \
> + (sk)->sk_prot->min_sndbuf : \
> + (TCP_SKB_MIN_TRUESIZE * 2))
> #define SOCK_MIN_RCVBUF TCP_SKB_MIN_TRUESIZE
>
> static inline void sk_stream_moderate_sndbuf(struct sock *sk)
> {
> if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) {
> sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1);
> - sk->sk_sndbuf = max_t(u32, sk->sk_sndbuf, SOCK_MIN_SNDBUF);
> + /* This seems to be called quite often and mainly for
> + * TCP. Should we stick with the constant instead of
> + * changing it to double dereference to not hurt
> + * performance? */
> + sk->sk_sndbuf = max_t(u32, sk->sk_sndbuf, SOCK_MIN_SNDBUF(sk));
> }
> }
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index b1aa324..814cef5 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -306,7 +306,7 @@ static inline bool between(__u32 seq1, __u32 seq2, __u32 seq3)
>
> static inline bool tcp_out_of_memory(struct sock *sk)
> {
> - if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
> + if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF(sk) &&
> sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2))
> return true;
> return false;
> diff --git a/net/can/raw.c b/net/can/raw.c
> index 4ad0bb2..b58f53f 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -818,6 +818,7 @@ static struct proto raw_proto __read_mostly = {
> .owner = THIS_MODULE,
> .obj_size = sizeof(struct raw_sock),
> .init = raw_init,
> + .min_sndbuf = SKB_TRUESIZE(sizeof(struct can_frame) + sizeof(struct can_skb_priv)),
> };
>
> static const struct can_proto raw_can_proto = {
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 0b39e7a..3f0d8a0 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -681,7 +681,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
> val = min_t(u32, val, sysctl_wmem_max);
> set_sndbuf:
> sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
> - sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF);
> + sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF(sk));
> /* Wake up sending tasks if we upped the value. */
> sk->sk_write_space(sk);
> break;
>
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]
next prev parent reply other threads:[~2014-01-17 9:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-16 19:58 [PATCH RFC 1/2] can: Limit default size of CAN_RAW socket send queue Michal Sojka
2014-01-16 19:58 ` [PATCH RFC 2/2] net: Make minimum SO_SNDBUF size dependent on the protocol family Michal Sojka
2014-01-17 9:08 ` Marc Kleine-Budde [this message]
2014-01-17 9:13 ` [PATCH RFC 1/2] can: Limit default size of CAN_RAW socket send queue Marc Kleine-Budde
2014-01-17 12:11 ` Michal Sojka
2014-01-17 15:31 ` Michal Sojka
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=52D8F2F0.3080305@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=sojkam1@fel.cvut.cz \
--cc=yegorslists@googlemail.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