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

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

net: Use a percpu_counter for sockets_allocated



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

Note : We revert commit (248969ae
net: af_unix can make unix_nr_socks visbile in /proc),
since it is not anymore used after sock_prot_inuse_add() addition

Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c1b56878
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ void sctp_write_space(struct sock *sk);
unsigned int sctp_poll(struct file *file, struct socket *sock,
		poll_table *wait);
void sctp_sock_rfree(struct sk_buff *skb);
extern struct percpu_counter sctp_sockets_allocated;

/*
 * sctp/primitive.c
+1 −1
Original line number Diff line number Diff line
@@ -649,7 +649,7 @@ struct proto {
	/* Memory pressure */
	void			(*enter_memory_pressure)(struct sock *sk);
	atomic_t		*memory_allocated;	/* Current allocated memory. */
	atomic_t		*sockets_allocated;	/* Current number of sockets. */
	struct percpu_counter	*sockets_allocated;	/* Current number of sockets. */
	/*
	 * Pressure flag: try to collapse.
	 * Technical note: it is used by multiple contexts non atomically.
+1 −1
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ extern int sysctl_tcp_slow_start_after_idle;
extern int sysctl_tcp_max_ssthresh;

extern atomic_t tcp_memory_allocated;
extern atomic_t tcp_sockets_allocated;
extern struct percpu_counter tcp_sockets_allocated;
extern int tcp_memory_pressure;

/*
+7 −3
Original line number Diff line number Diff line
@@ -1071,7 +1071,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
		newsk->sk_sleep	 = NULL;

		if (newsk->sk_prot->sockets_allocated)
			atomic_inc(newsk->sk_prot->sockets_allocated);
			percpu_counter_inc(newsk->sk_prot->sockets_allocated);
	}
out:
	return newsk;
@@ -1463,8 +1463,12 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
	}

	if (prot->memory_pressure) {
		if (!*prot->memory_pressure ||
		    prot->sysctl_mem[2] > atomic_read(prot->sockets_allocated) *
		int alloc;

		if (!*prot->memory_pressure)
			return 1;
		alloc = percpu_counter_read_positive(prot->sockets_allocated);
		if (prot->sysctl_mem[2] > alloc *
		    sk_mem_pages(sk->sk_wmem_queued +
				 atomic_read(&sk->sk_rmem_alloc) +
				 sk->sk_forward_alloc))
+2 −1
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
	seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
		   sock_prot_inuse_get(net, &tcp_prot),
		   atomic_read(&tcp_orphan_count),
		   tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated),
		   tcp_death_row.tw_count,
		   (int)percpu_counter_sum_positive(&tcp_sockets_allocated),
		   atomic_read(&tcp_memory_allocated));
	seq_printf(seq, "UDP: inuse %d mem %d\n",
		   sock_prot_inuse_get(net, &udp_prot),
Loading