diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2008-01-03 23:46:48 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 18:00:36 -0500 |
commit | 65f7651788e18fadb2fbb7276af935d7871e1803 (patch) | |
tree | dcad32d4344d6d11d80061773d9d1dbc9ae92223 /include/net | |
parent | 571e7682026fd0e25833d103a3eeb74be29bf199 (diff) |
[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: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/inet_hashtables.h | 2 | ||||
-rw-r--r-- | include/net/sock.h | 40 | ||||
-rw-r--r-- | include/net/udp.h | 2 |
3 files changed, 32 insertions, 12 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 65ddb25d62e8..761bdc01425d 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -293,7 +293,7 @@ static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk) | |||
293 | } | 293 | } |
294 | 294 | ||
295 | if (__sk_del_node_init(sk)) | 295 | if (__sk_del_node_init(sk)) |
296 | sock_prot_dec_use(sk->sk_prot); | 296 | sock_prot_inuse_add(sk->sk_prot, -1); |
297 | write_unlock_bh(lock); | 297 | write_unlock_bh(lock); |
298 | out: | 298 | out: |
299 | if (sk->sk_state == TCP_LISTEN) | 299 | if (sk->sk_state == TCP_LISTEN) |
diff --git a/include/net/sock.h b/include/net/sock.h index 3d938f6c6725..786fae858e77 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -548,7 +548,9 @@ struct proto { | |||
548 | int (*get_port)(struct sock *sk, unsigned short snum); | 548 | int (*get_port)(struct sock *sk, unsigned short snum); |
549 | 549 | ||
550 | /* Keeping track of sockets in use */ | 550 | /* Keeping track of sockets in use */ |
551 | #ifdef CONFIG_PROC_FS | ||
551 | struct pcounter inuse; | 552 | struct pcounter inuse; |
553 | #endif | ||
552 | 554 | ||
553 | /* Memory pressure */ | 555 | /* Memory pressure */ |
554 | void (*enter_memory_pressure)(void); | 556 | void (*enter_memory_pressure)(void); |
@@ -584,9 +586,6 @@ struct proto { | |||
584 | #endif | 586 | #endif |
585 | }; | 587 | }; |
586 | 588 | ||
587 | #define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME) | ||
588 | #define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse) | ||
589 | |||
590 | extern int proto_register(struct proto *prot, int alloc_slab); | 589 | extern int proto_register(struct proto *prot, int alloc_slab); |
591 | extern void proto_unregister(struct proto *prot); | 590 | extern void proto_unregister(struct proto *prot); |
592 | 591 | ||
@@ -615,21 +614,42 @@ static inline void sk_refcnt_debug_release(const struct sock *sk) | |||
615 | #define sk_refcnt_debug_release(sk) do { } while (0) | 614 | #define sk_refcnt_debug_release(sk) do { } while (0) |
616 | #endif /* SOCK_REFCNT_DEBUG */ | 615 | #endif /* SOCK_REFCNT_DEBUG */ |
617 | 616 | ||
617 | |||
618 | #ifdef CONFIG_PROC_FS | ||
619 | # define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME) | ||
620 | # define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse) | ||
618 | /* Called with local bh disabled */ | 621 | /* Called with local bh disabled */ |
619 | static __inline__ void sock_prot_inc_use(struct proto *prot) | 622 | static inline void sock_prot_inuse_add(struct proto *prot, int inc) |
620 | { | 623 | { |
621 | pcounter_add(&prot->inuse, 1); | 624 | pcounter_add(&prot->inuse, inc); |
622 | } | 625 | } |
623 | 626 | static inline int sock_prot_inuse_init(struct proto *proto) | |
624 | static __inline__ void sock_prot_dec_use(struct proto *prot) | ||
625 | { | 627 | { |
626 | pcounter_add(&prot->inuse, -1); | 628 | return pcounter_alloc(&proto->inuse); |
627 | } | 629 | } |
628 | 630 | static inline int sock_prot_inuse_get(struct proto *proto) | |
629 | static __inline__ int sock_prot_inuse(struct proto *proto) | ||
630 | { | 631 | { |
631 | return pcounter_getval(&proto->inuse); | 632 | return pcounter_getval(&proto->inuse); |
632 | } | 633 | } |
634 | static inline void sock_prot_inuse_free(struct proto *proto) | ||
635 | { | ||
636 | pcounter_free(&proto->inuse); | ||
637 | } | ||
638 | #else | ||
639 | # define DEFINE_PROTO_INUSE(NAME) | ||
640 | # define REF_PROTO_INUSE(NAME) | ||
641 | static void inline sock_prot_inuse_add(struct proto *prot, int inc) | ||
642 | { | ||
643 | } | ||
644 | static int inline sock_prot_inuse_init(struct proto *proto) | ||
645 | { | ||
646 | return 0; | ||
647 | } | ||
648 | static void inline sock_prot_inuse_free(struct proto *proto) | ||
649 | { | ||
650 | } | ||
651 | #endif | ||
652 | |||
633 | 653 | ||
634 | /* With per-bucket locks this operation is not-atomic, so that | 654 | /* With per-bucket locks this operation is not-atomic, so that |
635 | * this version is not worse. | 655 | * this version is not worse. |
diff --git a/include/net/udp.h b/include/net/udp.h index 93796beac8ff..c6669c0a74c7 100644 --- a/include/net/udp.h +++ b/include/net/udp.h | |||
@@ -115,7 +115,7 @@ static inline void udp_lib_unhash(struct sock *sk) | |||
115 | write_lock_bh(&udp_hash_lock); | 115 | write_lock_bh(&udp_hash_lock); |
116 | if (sk_del_node_init(sk)) { | 116 | if (sk_del_node_init(sk)) { |
117 | inet_sk(sk)->num = 0; | 117 | inet_sk(sk)->num = 0; |
118 | sock_prot_dec_use(sk->sk_prot); | 118 | sock_prot_inuse_add(sk->sk_prot, -1); |
119 | } | 119 | } |
120 | write_unlock_bh(&udp_hash_lock); | 120 | write_unlock_bh(&udp_hash_lock); |
121 | } | 121 | } |