aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2007-11-06 02:38:39 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2007-11-07 07:08:57 -0500
commit286ab3d46058840d68e5d7d52e316c1f7e98c59f (patch)
tree1d70e7895c49d2b148e026aa047efe186697fff9 /include
parent91781004b9c029ee55b7aa9ef950a373ba865dc6 (diff)
[NET]: Define infrastructure to keep 'inuse' changes in an efficent SMP/NUMA way.
"struct proto" currently uses an array stats[NR_CPUS] to track change on 'inuse' sockets per protocol. If NR_CPUS is big, this means we use a big memory area for this. Moreover, all this memory area is located on a single node on NUMA machines, increasing memory pressure on the boot node. In this patch, I tried to : - Keep a fast !CONFIG_SMP implementation - Keep a fast CONFIG_SMP implementation for often used protocols (tcp,udp,raw,...) - Introduce a NUMA efficient implementation Some helper macros are defined in include/net/sock.h These macros take into account CONFIG_SMP If a "struct proto" is declared without using DEFINE_PROTO_INUSE / REF_PROTO_INUSE macros, it will automatically use a default implementation, using a dynamically allocated percpu zone. This default implementation will be NUMA efficient, but might use 32/64 bytes per possible cpu because of current alloc_percpu() implementation. However it still should be better than previous implementation based on stats[NR_CPUS] field. When a "struct proto" is changed to use the new macros, we use a single static "int" percpu variable, lowering the memory and cpu costs, still preserving NUMA efficiency. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/net/sock.h63
1 files changed, 57 insertions, 6 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 20de3fa7ae40..5504fb9fa88a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -560,6 +560,14 @@ struct proto {
560 void (*unhash)(struct sock *sk); 560 void (*unhash)(struct sock *sk);
561 int (*get_port)(struct sock *sk, unsigned short snum); 561 int (*get_port)(struct sock *sk, unsigned short snum);
562 562
563#ifdef CONFIG_SMP
564 /* Keeping track of sockets in use */
565 void (*inuse_add)(struct proto *prot, int inc);
566 int (*inuse_getval)(const struct proto *prot);
567 int *inuse_ptr;
568#else
569 int inuse;
570#endif
563 /* Memory pressure */ 571 /* Memory pressure */
564 void (*enter_memory_pressure)(void); 572 void (*enter_memory_pressure)(void);
565 atomic_t *memory_allocated; /* Current allocated memory. */ 573 atomic_t *memory_allocated; /* Current allocated memory. */
@@ -592,12 +600,38 @@ struct proto {
592#ifdef SOCK_REFCNT_DEBUG 600#ifdef SOCK_REFCNT_DEBUG
593 atomic_t socks; 601 atomic_t socks;
594#endif 602#endif
595 struct {
596 int inuse;
597 u8 __pad[SMP_CACHE_BYTES - sizeof(int)];
598 } stats[NR_CPUS];
599}; 603};
600 604
605/*
606 * Special macros to let protos use a fast version of inuse{get|add}
607 * using a static percpu variable per proto instead of an allocated one,
608 * saving one dereference.
609 * This might be changed if/when dynamic percpu vars become fast.
610 */
611#ifdef CONFIG_SMP
612# define DEFINE_PROTO_INUSE(NAME) \
613static DEFINE_PER_CPU(int, NAME##_inuse); \
614static void NAME##_inuse_add(struct proto *prot, int inc) \
615{ \
616 __get_cpu_var(NAME##_inuse) += inc; \
617} \
618 \
619static int NAME##_inuse_getval(const struct proto *prot)\
620{ \
621 int res = 0, cpu; \
622 \
623 for_each_possible_cpu(cpu) \
624 res += per_cpu(NAME##_inuse, cpu); \
625 return res; \
626}
627# define REF_PROTO_INUSE(NAME) \
628 .inuse_add = NAME##_inuse_add, \
629 .inuse_getval = NAME##_inuse_getval,
630#else
631# define DEFINE_PROTO_INUSE(NAME)
632# define REF_PROTO_INUSE(NAME)
633#endif
634
601extern int proto_register(struct proto *prot, int alloc_slab); 635extern int proto_register(struct proto *prot, int alloc_slab);
602extern void proto_unregister(struct proto *prot); 636extern void proto_unregister(struct proto *prot);
603 637
@@ -629,12 +663,29 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
629/* Called with local bh disabled */ 663/* Called with local bh disabled */
630static __inline__ void sock_prot_inc_use(struct proto *prot) 664static __inline__ void sock_prot_inc_use(struct proto *prot)
631{ 665{
632 prot->stats[smp_processor_id()].inuse++; 666#ifdef CONFIG_SMP
667 prot->inuse_add(prot, 1);
668#else
669 prot->inuse++;
670#endif
633} 671}
634 672
635static __inline__ void sock_prot_dec_use(struct proto *prot) 673static __inline__ void sock_prot_dec_use(struct proto *prot)
636{ 674{
637 prot->stats[smp_processor_id()].inuse--; 675#ifdef CONFIG_SMP
676 prot->inuse_add(prot, -1);
677#else
678 prot->inuse--;
679#endif
680}
681
682static __inline__ int sock_prot_inuse(struct proto *proto)
683{
684#ifdef CONFIG_SMP
685 return proto->inuse_getval(proto);
686#else
687 return proto->inuse;
688#endif
638} 689}
639 690
640/* With per-bucket locks this operation is not-atomic, so that 691/* With per-bucket locks this operation is not-atomic, so that