Skip to content

Commit 98ba0bd

Browse files
wdebruijdavem330
authored andcommitted
sock: allocate skbs from optmem
Add sock_omalloc and sock_ofree to be able to allocate control skbs, for instance for looping errors onto sk_error_queue. The transmit budget (sk_wmem_alloc) is involved in transmit skb shaping, most notably in TCP Small Queues. Using this budget for control packets would impact transmission. Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 84b7187 commit 98ba0bd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/net/sock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
15311531
gfp_t priority);
15321532
void __sock_wfree(struct sk_buff *skb);
15331533
void sock_wfree(struct sk_buff *skb);
1534+
struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size,
1535+
gfp_t priority);
15341536
void skb_orphan_partial(struct sk_buff *skb);
15351537
void sock_rfree(struct sk_buff *skb);
15361538
void sock_efree(struct sk_buff *skb);

net/core/sock.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,33 @@ struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
19231923
}
19241924
EXPORT_SYMBOL(sock_wmalloc);
19251925

1926+
static void sock_ofree(struct sk_buff *skb)
1927+
{
1928+
struct sock *sk = skb->sk;
1929+
1930+
atomic_sub(skb->truesize, &sk->sk_omem_alloc);
1931+
}
1932+
1933+
struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size,
1934+
gfp_t priority)
1935+
{
1936+
struct sk_buff *skb;
1937+
1938+
/* small safe race: SKB_TRUESIZE may differ from final skb->truesize */
1939+
if (atomic_read(&sk->sk_omem_alloc) + SKB_TRUESIZE(size) >
1940+
sysctl_optmem_max)
1941+
return NULL;
1942+
1943+
skb = alloc_skb(size, priority);
1944+
if (!skb)
1945+
return NULL;
1946+
1947+
atomic_add(skb->truesize, &sk->sk_omem_alloc);
1948+
skb->sk = sk;
1949+
skb->destructor = sock_ofree;
1950+
return skb;
1951+
}
1952+
19261953
/*
19271954
* Allocate a memory block from the socket's option memory buffer.
19281955
*/

0 commit comments

Comments
 (0)