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

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

[NET]: prot_inuse cleanups and optimizations



1) Cleanups (all functions are prefixed by sock_prot_inuse)

sock_prot_inc_use(prot) -> sock_prot_inuse_add(prot,-1)
sock_prot_dec_use(prot) -> sock_prot_inuse_add(prot,-1)
sock_prot_inuse()       -> sock_prot_inuse_get()

New functions :

sock_prot_inuse_init() and sock_prot_inuse_free() to abstract pcounter use.

2) if CONFIG_PROC_FS=n, we can zap 'inuse' member from "struct proto",
since nobody wants to read the inuse value.

This saves 1372 bytes on i386/SMP and some cpu cycles.

Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 571e7682
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -293,7 +293,7 @@ static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk)
	}
	}


	if (__sk_del_node_init(sk))
	if (__sk_del_node_init(sk))
		sock_prot_dec_use(sk->sk_prot);
		sock_prot_inuse_add(sk->sk_prot, -1);
	write_unlock_bh(lock);
	write_unlock_bh(lock);
out:
out:
	if (sk->sk_state == TCP_LISTEN)
	if (sk->sk_state == TCP_LISTEN)
+30 −10
Original line number Original line Diff line number Diff line
@@ -548,7 +548,9 @@ struct proto {
	int			(*get_port)(struct sock *sk, unsigned short snum);
	int			(*get_port)(struct sock *sk, unsigned short snum);


	/* Keeping track of sockets in use */
	/* Keeping track of sockets in use */
#ifdef CONFIG_PROC_FS
	struct pcounter		inuse;
	struct pcounter		inuse;
#endif


	/* Memory pressure */
	/* Memory pressure */
	void			(*enter_memory_pressure)(void);
	void			(*enter_memory_pressure)(void);
@@ -584,9 +586,6 @@ struct proto {
#endif
#endif
};
};


#define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
#define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)

extern int proto_register(struct proto *prot, int alloc_slab);
extern int proto_register(struct proto *prot, int alloc_slab);
extern void proto_unregister(struct proto *prot);
extern void proto_unregister(struct proto *prot);


@@ -615,21 +614,42 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
#define sk_refcnt_debug_release(sk) do { } while (0)
#define sk_refcnt_debug_release(sk) do { } while (0)
#endif /* SOCK_REFCNT_DEBUG */
#endif /* SOCK_REFCNT_DEBUG */



#ifdef CONFIG_PROC_FS
# define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
# define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)
/* Called with local bh disabled */
/* Called with local bh disabled */
static __inline__ void sock_prot_inc_use(struct proto *prot)
static inline void sock_prot_inuse_add(struct proto *prot, int inc)
{
{
	pcounter_add(&prot->inuse, 1);
	pcounter_add(&prot->inuse, inc);
}
}

static inline int sock_prot_inuse_init(struct proto *proto)
static __inline__ void sock_prot_dec_use(struct proto *prot)
{
{
	pcounter_add(&prot->inuse, -1);
	return pcounter_alloc(&proto->inuse);
}
}

static inline int sock_prot_inuse_get(struct proto *proto)
static __inline__ int sock_prot_inuse(struct proto *proto)
{
{
	return pcounter_getval(&proto->inuse);
	return pcounter_getval(&proto->inuse);
}
}
static inline void sock_prot_inuse_free(struct proto *proto)
{
	pcounter_free(&proto->inuse);
}
#else
# define DEFINE_PROTO_INUSE(NAME)
# define REF_PROTO_INUSE(NAME)
static void inline sock_prot_inuse_add(struct proto *prot, int inc)
{
}
static int inline sock_prot_inuse_init(struct proto *proto)
{
	return 0;
}
static void inline sock_prot_inuse_free(struct proto *proto)
{
}
#endif



/* With per-bucket locks this operation is not-atomic, so that
/* With per-bucket locks this operation is not-atomic, so that
 * this version is not worse.
 * this version is not worse.
+1 −1
Original line number Original line Diff line number Diff line
@@ -115,7 +115,7 @@ static inline void udp_lib_unhash(struct sock *sk)
	write_lock_bh(&udp_hash_lock);
	write_lock_bh(&udp_hash_lock);
	if (sk_del_node_init(sk)) {
	if (sk_del_node_init(sk)) {
		inet_sk(sk)->num = 0;
		inet_sk(sk)->num = 0;
		sock_prot_dec_use(sk->sk_prot);
		sock_prot_inuse_add(sk->sk_prot, -1);
	}
	}
	write_unlock_bh(&udp_hash_lock);
	write_unlock_bh(&udp_hash_lock);
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -1913,7 +1913,7 @@ int proto_register(struct proto *prot, int alloc_slab)
	char *request_sock_slab_name = NULL;
	char *request_sock_slab_name = NULL;
	char *timewait_sock_slab_name;
	char *timewait_sock_slab_name;


	if (pcounter_alloc(&prot->inuse) != 0) {
	if (sock_prot_inuse_init(prot) != 0) {
		printk(KERN_CRIT "%s: Can't alloc inuse counters!\n", prot->name);
		printk(KERN_CRIT "%s: Can't alloc inuse counters!\n", prot->name);
		goto out;
		goto out;
	}
	}
@@ -1984,7 +1984,7 @@ int proto_register(struct proto *prot, int alloc_slab)
	kmem_cache_destroy(prot->slab);
	kmem_cache_destroy(prot->slab);
	prot->slab = NULL;
	prot->slab = NULL;
out_free_inuse:
out_free_inuse:
	pcounter_free(&prot->inuse);
	sock_prot_inuse_free(prot);
out:
out:
	return -ENOBUFS;
	return -ENOBUFS;
}
}
@@ -1997,7 +1997,7 @@ void proto_unregister(struct proto *prot)
	list_del(&prot->node);
	list_del(&prot->node);
	write_unlock(&proto_list_lock);
	write_unlock(&proto_list_lock);


	pcounter_free(&prot->inuse);
	sock_prot_inuse_free(prot);


	if (prot->slab != NULL) {
	if (prot->slab != NULL) {
		kmem_cache_destroy(prot->slab);
		kmem_cache_destroy(prot->slab);
+3 −3
Original line number Original line Diff line number Diff line
@@ -278,7 +278,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
	sk->sk_hash = hash;
	sk->sk_hash = hash;
	BUG_TRAP(sk_unhashed(sk));
	BUG_TRAP(sk_unhashed(sk));
	__sk_add_node(sk, &head->chain);
	__sk_add_node(sk, &head->chain);
	sock_prot_inc_use(sk->sk_prot);
	sock_prot_inuse_add(sk->sk_prot, 1);
	write_unlock(lock);
	write_unlock(lock);


	if (twp) {
	if (twp) {
@@ -321,7 +321,7 @@ void __inet_hash_nolisten(struct inet_hashinfo *hashinfo, struct sock *sk)


	write_lock(lock);
	write_lock(lock);
	__sk_add_node(sk, list);
	__sk_add_node(sk, list);
	sock_prot_inc_use(sk->sk_prot);
	sock_prot_inuse_add(sk->sk_prot, 1);
	write_unlock(lock);
	write_unlock(lock);
}
}
EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
@@ -342,7 +342,7 @@ void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)


	inet_listen_wlock(hashinfo);
	inet_listen_wlock(hashinfo);
	__sk_add_node(sk, list);
	__sk_add_node(sk, list);
	sock_prot_inc_use(sk->sk_prot);
	sock_prot_inuse_add(sk->sk_prot, 1);
	write_unlock(lock);
	write_unlock(lock);
	wake_up(&hashinfo->lhash_wait);
	wake_up(&hashinfo->lhash_wait);
}
}
Loading