Skip to content

Commit ede61ca

Browse files
edumazetdavem330
authored andcommitted
tcp: add tcp_rx_skb_cache sysctl
Instead of relying on rps_needed, it is safer to use a separate static key, since we do not want to enable TCP rx_skb_cache by default. This feature can cause huge increase of memory usage on hosts with millions of sockets. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a8e11e5 commit ede61ca

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Documentation/networking/ip-sysctl.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ tcp_challenge_ack_limit - INTEGER
772772
in RFC 5961 (Improving TCP's Robustness to Blind In-Window Attacks)
773773
Default: 100
774774

775+
tcp_rx_skb_cache - BOOLEAN
776+
Controls a per TCP socket cache of one skb, that might help
777+
performance of some workloads. This might be dangerous
778+
on systems with a lot of TCP sockets, since it increases
779+
memory usage.
780+
781+
Default: 0 (disabled)
782+
775783
UDP variables:
776784

777785
udp_l3mdev_accept - BOOLEAN

include/net/sock.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,13 +2433,11 @@ static inline void skb_setup_tx_timestamp(struct sk_buff *skb, __u16 tsflags)
24332433
* This routine must be called with interrupts disabled or with the socket
24342434
* locked so that the sk_buff queue operation is ok.
24352435
*/
2436+
DECLARE_STATIC_KEY_FALSE(tcp_rx_skb_cache_key);
24362437
static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb)
24372438
{
24382439
__skb_unlink(skb, &sk->sk_receive_queue);
2439-
if (
2440-
#ifdef CONFIG_RPS
2441-
!static_branch_unlikely(&rps_needed) &&
2442-
#endif
2440+
if (static_branch_unlikely(&tcp_rx_skb_cache_key) &&
24432441
!sk->sk_rx_skb_cache) {
24442442
sk->sk_rx_skb_cache = skb;
24452443
skb_orphan(skb);

net/ipv4/sysctl_net_ipv4.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ static int comp_sack_nr_max = 255;
5151
static u32 u32_max_div_HZ = UINT_MAX / HZ;
5252
static int one_day_secs = 24 * 3600;
5353

54+
DEFINE_STATIC_KEY_FALSE(tcp_rx_skb_cache_key);
55+
EXPORT_SYMBOL(tcp_rx_skb_cache_key);
56+
5457
/* obsolete */
5558
static int sysctl_tcp_low_latency __read_mostly;
5659

@@ -559,6 +562,12 @@ static struct ctl_table ipv4_table[] = {
559562
.extra1 = &sysctl_fib_sync_mem_min,
560563
.extra2 = &sysctl_fib_sync_mem_max,
561564
},
565+
{
566+
.procname = "tcp_rx_skb_cache",
567+
.data = &tcp_rx_skb_cache_key.key,
568+
.mode = 0644,
569+
.proc_handler = proc_do_static_key,
570+
},
562571
{ }
563572
};
564573

0 commit comments

Comments
 (0)