Commit 62803fec authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'inuse-cleanups'



Eric Dumazet says:

====================
net: prot_inuse and sock_inuse cleanups

Small series cleaning and optimizing sock_prot_inuse_add()
and sock_inuse_add().
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents abc3342a b3cb764a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ struct netns_core {
	int	sysctl_somaxconn;

#ifdef CONFIG_PROC_FS
	int __percpu *sock_inuse;
	struct prot_inuse __percpu *prot_inuse;
#endif
};
+23 −4
Original line number Diff line number Diff line
@@ -1429,13 +1429,32 @@ proto_memory_pressure(struct proto *prot)


#ifdef CONFIG_PROC_FS
/* Called with local bh disabled */
void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
#define PROTO_INUSE_NR	64	/* should be enough for the first time */
struct prot_inuse {
	int all;
	int val[PROTO_INUSE_NR];
};

static inline void sock_prot_inuse_add(const struct net *net,
				       const struct proto *prot, int val)
{
	this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
}

static inline void sock_inuse_add(const struct net *net, int val)
{
	this_cpu_add(net->core.prot_inuse->all, val);
}

int sock_prot_inuse_get(struct net *net, struct proto *proto);
int sock_inuse_get(struct net *net);
#else
static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
		int inc)
static inline void sock_prot_inuse_add(const struct net *net,
				       const struct proto *prot, int val)
{
}

static inline void sock_inuse_add(const struct net *net, int val)
{
}
#endif
+1 −32
Original line number Diff line number Diff line
@@ -144,8 +144,6 @@
static DEFINE_MUTEX(proto_list_mutex);
static LIST_HEAD(proto_list);

static void sock_inuse_add(struct net *net, int val);

/**
 * sk_ns_capable - General socket capability test
 * @sk: Socket to use a capability on or through
@@ -3536,19 +3534,8 @@ void sk_get_meminfo(const struct sock *sk, u32 *mem)
}

#ifdef CONFIG_PROC_FS
#define PROTO_INUSE_NR	64	/* should be enough for the first time */
struct prot_inuse {
	int val[PROTO_INUSE_NR];
};

static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);

void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
{
	__this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_add);

int sock_prot_inuse_get(struct net *net, struct proto *prot)
{
	int cpu, idx = prot->inuse_idx;
@@ -3561,17 +3548,12 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);

static void sock_inuse_add(struct net *net, int val)
{
	this_cpu_add(*net->core.sock_inuse, val);
}

int sock_inuse_get(struct net *net)
{
	int cpu, res = 0;

	for_each_possible_cpu(cpu)
		res += *per_cpu_ptr(net->core.sock_inuse, cpu);
		res += per_cpu_ptr(net->core.prot_inuse, cpu)->all;

	return res;
}
@@ -3583,22 +3565,12 @@ static int __net_init sock_inuse_init_net(struct net *net)
	net->core.prot_inuse = alloc_percpu(struct prot_inuse);
	if (net->core.prot_inuse == NULL)
		return -ENOMEM;

	net->core.sock_inuse = alloc_percpu(int);
	if (net->core.sock_inuse == NULL)
		goto out;

	return 0;

out:
	free_percpu(net->core.prot_inuse);
	return -ENOMEM;
}

static void __net_exit sock_inuse_exit_net(struct net *net)
{
	free_percpu(net->core.prot_inuse);
	free_percpu(net->core.sock_inuse);
}

static struct pernet_operations net_inuse_ops = {
@@ -3644,9 +3616,6 @@ static inline void release_proto_idx(struct proto *prot)
{
}

static void sock_inuse_add(struct net *net, int val)
{
}
#endif

static void tw_prot_cleanup(struct timewait_sock_ops *twsk_prot)
+2 −2
Original line number Diff line number Diff line
@@ -174,8 +174,8 @@ static int raw_hash(struct sock *sk)
{
	write_lock_bh(&raw_lock);
	sk_add_node(sk, &raw_head);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
	write_unlock_bh(&raw_lock);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);

	return 0;
}
@@ -453,8 +453,8 @@ static int dgram_hash(struct sock *sk)
{
	write_lock_bh(&dgram_lock);
	sk_add_node(sk, &dgram_head);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
	write_unlock_bh(&dgram_lock);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);

	return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -99,8 +99,8 @@ int raw_hash_sk(struct sock *sk)

	write_lock_bh(&h->lock);
	sk_add_node(sk, head);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
	write_unlock_bh(&h->lock);
	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);

	return 0;
}
Loading