Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd24c001 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

net: Use a percpu_counter for orphan_count



Instead of using one atomic_t per protocol, use a percpu_counter
for "orphan_count", to reduce cache line contention on
heavy duty network servers. 

Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1748376b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -666,7 +666,7 @@ struct proto {
	unsigned int		obj_size;
	int			slab_flags;

	atomic_t		*orphan_count;
	struct percpu_counter	*orphan_count;

	struct request_sock_ops	*rsk_prot;
	struct timewait_sock_ops *twsk_prot;
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@

extern struct inet_hashinfo tcp_hashinfo;

extern atomic_t tcp_orphan_count;
extern struct percpu_counter tcp_orphan_count;
extern void tcp_time_wait(struct sock *sk, int state, int timeo);

#define MAX_TCP_HEADER	(128 + MAX_HEADER)
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ extern int dccp_debug;

extern struct inet_hashinfo dccp_hashinfo;

extern atomic_t dccp_orphan_count;
extern struct percpu_counter dccp_orphan_count;

extern void dccp_time_wait(struct sock *sk, int state, int timeo);

+10 −6
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly;

EXPORT_SYMBOL_GPL(dccp_statistics);

atomic_t dccp_orphan_count = ATOMIC_INIT(0);

struct percpu_counter dccp_orphan_count;
EXPORT_SYMBOL_GPL(dccp_orphan_count);

struct inet_hashinfo dccp_hashinfo;
@@ -1000,7 +999,7 @@ void dccp_close(struct sock *sk, long timeout)
	state = sk->sk_state;
	sock_hold(sk);
	sock_orphan(sk);
	atomic_inc(sk->sk_prot->orphan_count);
	percpu_counter_inc(sk->sk_prot->orphan_count);

	/*
	 * It is the last release_sock in its life. It will remove backlog.
@@ -1064,18 +1063,21 @@ static int __init dccp_init(void)
{
	unsigned long goal;
	int ehash_order, bhash_order, i;
	int rc = -ENOBUFS;
	int rc;

	BUILD_BUG_ON(sizeof(struct dccp_skb_cb) >
		     FIELD_SIZEOF(struct sk_buff, cb));

	rc = percpu_counter_init(&dccp_orphan_count, 0);
	if (rc)
		goto out;
	rc = -ENOBUFS;
	inet_hashinfo_init(&dccp_hashinfo);
	dccp_hashinfo.bind_bucket_cachep =
		kmem_cache_create("dccp_bind_bucket",
				  sizeof(struct inet_bind_bucket), 0,
				  SLAB_HWCACHE_ALIGN, NULL);
	if (!dccp_hashinfo.bind_bucket_cachep)
		goto out;
		goto out_free_percpu;

	/*
	 * Size and allocate the main established and bind bucket
@@ -1168,6 +1170,8 @@ static int __init dccp_init(void)
out_free_bind_bucket_cachep:
	kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
	dccp_hashinfo.bind_bucket_cachep = NULL;
out_free_percpu:
	percpu_counter_destroy(&dccp_orphan_count);
	goto out;
}

+2 −2
Original line number Diff line number Diff line
@@ -561,7 +561,7 @@ void inet_csk_destroy_sock(struct sock *sk)

	sk_refcnt_debug_release(sk);

	atomic_dec(sk->sk_prot->orphan_count);
	percpu_counter_dec(sk->sk_prot->orphan_count);
	sock_put(sk);
}

@@ -641,7 +641,7 @@ void inet_csk_listen_stop(struct sock *sk)

		sock_orphan(child);

		atomic_inc(sk->sk_prot->orphan_count);
		percpu_counter_inc(sk->sk_prot->orphan_count);

		inet_csk_destroy_sock(child);

Loading