mm: Reimplementation of dynamic per-cpu allocator
Subsystems (14)
cover mm: Reimplementation of dynamic per-cpu allocator
I have been maintaining a set of patches based on the reimplemented dynamic per-cpu allocator. I would like to have them included in -mm for testing and maybe merged when the mainline merge window opens :)...
The reimplementation of the dynamic per-cpu allocator has been published earlier and discussed, But the re-implementation with the applications and supporting numbers weren't published earlier. Here is an attempt towards the same.
This patchset contains
a) Reimplementation of alloc_percpu.
b) Rusty's implementation of distributed reference counters (bigrefs)
c) Code to change struct netdevice.refcnt to bigrefs -- this patch improves tbench performance by 6% on a 8 way 3.00 GHZ x86 Intel xeon (x445).
d) Code to change struct dst_entry.__refcnt per-cpu. This patch was originally submitted sometime back by Christoph. The reworked patch uses alloc_percpu, and struct dst_entry does not bloat up now. This patch along with the netdevice ref-counter patch above gives a whopping 55 % improvement on tbench on a 8way x86 xeon (x445). The same patchset resulted in 30% better tbench throughput on a x460 (8 way 3.3 Ghz x86_64 xeon).
All tbench numbers were on loopback with 8 clients.
The patches consist of
1. vmalloc_fixup
(Fix up __get_vm_area to take gfp flags as extra arg -- preparatory for 3.)
2. alloc_percpu
(Main allocator)
3. alloc_percpu_atomic
(Add GFP_FLAGS args to alloc_percpu -- for dst_entry.refcount)
4.change_alloc_percpu_users
(Change alloc_percpu users to use modified interface (with gfp_flags))
5. add_getcpuptr
(This is needed for bigrefs)
6. bigrefs
(Fixed up bigref from rusty)
7. netdev_refcnt_bigref.patch
(Bigref based netdev refcount)
8. dst_abstraction
9. dst_alloc_percpu
(dst_entry.refcount patches)
10. allow_early_mapvmarea
11. hotplug_alloc_percpu_blocks
(If alloc_percpu needs to be used real early then these patches will be needed. This patch allows us to use bigrefs/alloc_percpu for refcounters like struct vfsmount.mnt_count)
PATCH 1/11 mm: Reimplementation of dynamic per-cpu allocator -- vmalloc_fixup
Patch to add gfp_flags as args to __get_vm_area. alloc_percpu needs to use GFP flags as the dst_entry.refcount needs to be allocated with GFP_ATOMIC. Since alloc_percpu needs get_vm_area underneath, this patch changes __get_vmarea to accept gfp_flags as arg, so that alloc_percpu can use __get_vm_area. get_vm_area remains unchanged.
arch/arm/kernel/module.c +2 -1
@@ -40,7 +40,8 @@if (!size)return NULL ; - area =__get_vm_area (size,VM_ALLOC ,MODULE_START ,MODULE_END ); + area =__get_vm_area (size,VM_ALLOC ,MODULE_START ,MODULE_END , +GFP_KERNEL );if (!area)return NULL ;
arch/sh/kernel/cpu/sh4/sq.c +2 -1
@@ -189,7 +189,8 @@* writeout before we hit the TLB flush, we do it anyways. This way * we at least save ourselves the initial page fault overhead. */ - vma =__get_vm_area (map->size,VM_ALLOC , map->sq_addr,SQ_ADDRMAX ); + vma =__get_vm_area (map->size,VM_ALLOC , map->sq_addr,SQ_ADDRMAX , +GFP_KERNEL );if (!vma)return ERR_PTR (-ENOMEM );
arch/sparc64/kernel/module.c +2 -1
@@ -25,7 +25,8 @@if (!size || size >MODULES_LEN )return NULL ; - area =__get_vm_area (size,VM_ALLOC ,MODULES_VADDR ,MODULES_END ); + area =__get_vm_area (size,VM_ALLOC ,MODULES_VADDR ,MODULES_END , +GFP_KERNEL );if (!area)return NULL ;
arch/x86_64/kernel/module.c +2 -1
@@ -48,7 +48,8 @@if (size >MODULES_LEN )return NULL ; - area =__get_vm_area (size,VM_ALLOC ,MODULES_VADDR ,MODULES_END ); + area =__get_vm_area (size,VM_ALLOC ,MODULES_VADDR ,MODULES_END , +GFP_KERNEL );if (!area)return NULL ;
include/linux/vmalloc.h +2 -1
@@ -39,7 +39,8 @@*/ extern struct vm_struct *get_vm_area (unsigned long size,unsigned long flags);extern struct vm_struct *__get_vm_area (unsigned long size,unsigned long flags, -unsigned long start,unsigned long end); +unsigned long start,unsigned long end, +unsigned int gfpflags);extern struct vm_struct *remove_vm_area (void *addr);extern struct vm_struct *__remove_vm_area (void *addr); extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
mm/vmalloc.c +5 -3
@@ -161,7 +161,8 @@#define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT)/* 128 pages */ struct vm_struct *__get_vm_area (unsigned long size,unsigned long flags, -unsigned long start,unsigned long end) +unsigned long start,unsigned long end, +unsigned int gfp_flags) {struct vm_struct **p, *tmp, *area;unsigned long align =1 ;
@@ -180,7 +181,7 @@ addr =ALIGN (start, align); size =PAGE_ALIGN (size); - area =kmalloc (sizeof (*area),GFP_KERNEL ); + area =kmalloc (sizeof (*area), gfp_flags);if (unlikely (!area))return NULL ;
@@ -245,7 +246,8 @@*/ struct vm_struct *get_vm_area (unsigned long size,unsigned long flags) { -return __get_vm_area (size, flags,VMALLOC_START ,VMALLOC_END ); +return __get_vm_area (size, flags,VMALLOC_START ,VMALLOC_END , +GFP_KERNEL ); }/* Caller must hold vmlist_lock */
Re: [patch 1/11] mm: Reimplementation of dynamic per-cpu allocator -- vmalloc_fixup
Quoted 6 lines · Ravikiran G Thirumalai
Patch to add
gfp_flagsas args to__get_vm_area.alloc_percpuneeds to use
GFP flags as the dst_entry.refcount needs to be allocated withGFP_ATOMIC. Sincealloc_percpuneedsget_vm_areaunderneath, this patch changes__get_vmareato acceptgfp_flagsas arg, so thatalloc_percpucan use__get_vm_area.get_vm_arearemains unchanged.
Is dst_alloc() ever called from IRQ or softirq contexts?
If so, __get_vm_area()'s write_lock(&vmlist_lock) is now deadlockable.
If not, then you've just added a restriction to dst_alloc()'s usage which should be checked over by the net guys and which needs commenting in the code.
PATCH 2/11 mm: Reimplementation of dynamic per-cpu allocator -- alloc_percpu
In reply to Ravikiran G ThirumalaiThe following patch re-implements the linux dynamic percpu memory allocator so that:
1. Percpu memory dereference is faster
- One less memory reference compared to existing simple alloc_percpu
- As fast as with static percpu areas, one mem ref less actually.
2. Better memory usage
- Doesn't need a NR_CPUS pointer array for each allocation
- Interlaces objects making better utilization of memory/cachelines
- Userspace tests show 98% utilization with random sized allocations after repeated random frees. Utilization with small sized allocations (counters) expected to be better than random sized allocations.
3. Provides truly node local allocation
- The percpu memory with existing alloc_percpu does node local allocation, but the NR_CPUS place holder is not node local. This problem doesn't exist with the new implementation.
4. CPU Hotplug friendly
5. Independent of slab. Works early
Design:
We have "blocks" of memory akin to slabs. Each block has
(percpu blocksize) * NR_CPUS + (block management data structures) of kernel VA space allocated to it. Node local pages are allocated and mapped against the corresponding cpus' VA space. Pages are allocated for block management data structures and mapped to their corresponding VA. These reside at (percpu blocksize) * NR_CPUS offset from the beginning of the block. The allocator maintains a circular linked list of blocks, sorted in descending order of block utilization. On requests for objects, allocator tries to serve the request from the most utilized block.
The allocator allocates memory in multiples of a fixed currency size for a request. The allocator returns address of the percpu
object corresponding to cpu0. The cpu local variable for any given cpu can be obtained by simple arithmetic:obj_address + cpu_id * PCPU_BLKSIZE.
Testing:
The block allocator has undergone some userspace stress testing with small counter sized objects as well as a large number of random sized objects.
---
include/linux/kernel.h +2 -0
@@ -29,6 +29,8 @@#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))#define ALIGN (x,a) (((x)+(a)-1)&~((a)-1)) +#define IS_ALIGNED (x,a) (!(((a) - 1) & (x))) +#define IS_POWEROFTWO (x) (!(((x) - 1) & (x)))#define KERN_EMERG "<0>"/* system is unusable */ #define KERN_ALERT "<1>"/* action must be taken immediately */
include/linux/percpu.h +7 -11
@@ -15,23 +15,19 @@#define get_cpu_var (var) (*({ preempt_disable(); &__get_cpu_var(var); }))#define put_cpu_var (var) preempt_enable() -#ifdef CONFIG_SMP - -struct percpu_data { -void *ptrs[NR_CPUS ]; -void *blkp; -}; +/* This is the upper bound for an object using alloc_percpu */ +#define PCPU_BLKSIZE (PAGE_SIZE << 1) +#define PCPU_CURR_SIZE (sizeof (int)) +#ifdef CONFIG_SMP /* * Use this to get to a cpu's version of the per-cpu object allocated using * alloc_percpu. Non-atomic access to the current CPU's version should * probably be combined with get_cpu()/put_cpu(). */ #define per_cpu_ptr (ptr, cpu) \ -({ \ - struct percpu_data *__p = (struct percpu_data *)~(unsigned long)(ptr); \ - (__typeof__(ptr))__p->ptrs[(cpu)]; \ -}) + ((__typeof__(ptr)) \ + (RELOC_HIDE(ptr, PCPU_BLKSIZE * cpu)))extern void *__alloc_percpu (size_t size,size_t align);extern void free_percpu (const void *);
@@ -56,6 +52,6 @@/* Simple wrapper for the common case: zeros memory. */ #define alloc_percpu (type) \ - ((type *)(__alloc_percpu(sizeof(type), __alignof__(type)))) + ((type *)(__alloc_percpu(ALIGN(sizeof (type), PCPU_CURR_SIZE), __alignof__(type))))#endif /* __LINUX_PERCPU_H */
mm/Makefile +1 -0
@@ -18,5 +18,6 @@ obj-$(CONFIG_SPARSEMEM) += sparse.o obj-$(CONFIG_SHMEM) += shmem.o obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o +obj-$(CONFIG_SMP) += percpu.o obj-$(CONFIG_FS_XIP) += filemap_xip.o
mm/percpu.c +693 -0
693 lines not on this page · raw message
mm/slab.c +0 -67
79 lines not on this page · raw message
PATCH 3/11 mm: Reimplementation of dynamic per-cpu allocator -- alloc_percpu_atomic
In reply to Ravikiran G ThirumalaiFollowing patch changes the alloc_percpu interface to accept gfp_flags as an argument.
include/linux/percpu.h +10 -5
@@ -29,16 +29,17 @@ ((__typeof__ (ptr)) \ (RELOC_HIDE(ptr, PCPU_BLKSIZE * cpu))) -extern void *__alloc_percpu (size_t size,size_t align); +extern void *__alloc_percpu (size_t size,size_t align,unsigned int gfpflags);extern void free_percpu (const void *);#else /* CONFIG_SMP */ #define per_cpu_ptr (ptr, cpu) (ptr) -static inline void *__alloc_percpu (size_t size,size_t align) +static inline void * +__alloc_percpu (size_t size,size_t align,unsigned int gfpflags) { -void *ret =kmalloc (size,GFP_KERNEL ); +void *ret =kmalloc (size, gfpflags);if (ret)memset (ret,0 , size);return ret;
@@ -51,7 +52,11 @@#endif /* CONFIG_SMP */ /* Simple wrapper for the common case: zeros memory. */ -#define alloc_percpu (type) \ - ((type *)(__alloc_percpu(ALIGN(sizeof (type), PCPU_CURR_SIZE), __alignof__(type)))) +#define alloc_percpu (type, gfpflags) \ +({ \ + BUG_ON(~(GFP_ATOMIC|GFP_KERNEL) & gfpflags); \ + ((type *)(__alloc_percpu(ALIGN(sizeof (type), PCPU_CURR_SIZE), \ + __alignof__(type), gfpflags))); \ +})#endif /* __LINUX_PERCPU_H */
mm/percpu.c +16 -12
@@ -109,7 +109,7 @@* contiguous kva space, and PCPU_BLKSIZE amount of node local * memory (pages) for all cpus possible + BLOCK_MANAGEMENT_SIZE pages */ -static void *valloc_percpu (void ) +static void *valloc_percpu (unsigned int gfpflags) {int i, j =0 ;unsigned int nr_pages;
@@ -118,14 +118,21 @@struct page *pages[BLOCK_MANAGEMENT_PAGES ];unsigned int cpu_pages =PCPU_BLKSIZE >>PAGE_SHIFT ;struct pcpu_block *blkp =NULL ; +unsigned int flags;BUG_ON (!IS_ALIGNED (PCPU_BLKSIZE ,PAGE_SIZE ));BUG_ON (!PCPU_BLKSIZE ); nr_pages =PCPUPAGES_PER_BLOCK +BLOCK_MANAGEMENT_PAGES ; +/* gfpflags can be either GFP_KERNEL or GFP_ATOMIC only */ +if (gfpflags &GFP_KERNEL ) + flags =GFP_KERNEL |__GFP_HIGHMEM|__GFP_ZERO; +else + flags =GFP_ATOMIC |__GFP_ZERO; +/* Alloc Managent block pages */ for (i =0 ; i <BLOCK_MANAGEMENT_PAGES ; i++) { - pages[i] =alloc_pages (GFP_ATOMIC |__GFP_ZERO,0 ); + pages[i] =alloc_pages (flags,0 );if (!pages[i]) {while (--i >=0 )__free_pages (pages[i],0 );
@@ -135,7 +142,7 @@/* Get the contiguous VA space for this block */ area =__get_vm_area (nr_pages <<PAGE_SHIFT ,VM_MAP ,VMALLOC_START , -VMALLOC_END ,GFP_KERNEL ); +VMALLOC_END , gfpflags);if (!area) goto rollback_mgt;
@@ -156,11 +163,8 @@for_each_cpu (i) {int start_idx = i * cpu_pages;for (j = start_idx; j < start_idx + cpu_pages; j++) { - blkp->pages[j] =alloc_pages_node (cpu_to_node (i) - , -GFP_ATOMIC | - __GFP_HIGHMEM, -0 ); + blkp->pages[j] =alloc_pages_node (cpu_to_node (i) , + flags,0 );if (unlikely (!blkp->pages[j])) goto rollback_pages; }
@@ -260,13 +264,13 @@ } -static int add_percpu_block (void ) +static int add_percpu_block (unsigned int gfpflags) {struct pcpu_block *blkp;void *start_addr;unsigned long flags; - start_addr =valloc_percpu (); + start_addr =valloc_percpu (gfpflags);if (!start_addr)return 0 ; blkp = start_addr +PCPUPAGES_PER_BLOCK *PAGE_SIZE ;
@@ -464,7 +468,7 @@* by during boot/module init. * Should not be called from interrupt context */ -void *__alloc_percpu (size_t size,size_t align) +void *__alloc_percpu (size_t size,size_t align,unsigned int gfpflags) {struct pcpu_block *blkp;struct list_head *l;
@@ -512,7 +516,7 @@ unlock_and_get_mem:spin_unlock_irqrestore (&blklist_lock, flags); -if (add_percpu_block ()) +if (add_percpu_block (gfpflags)) goto try_after_refill;return NULL ;
PATCH 4/11 mm: Reimplementation of dynamic per-cpu allocator -- change_alloc_percpu_users
In reply to Ravikiran G ThirumalaiChange all current users of alloc_percpu to the new alloc_percpu interface
include/linux/genhd.h +1 -1
@@ -199,7 +199,7 @@#ifdef CONFIG_SMP static inline int init_disk_stats (struct gendisk *disk) { - disk->dkstats = alloc_percpu(struct disk_stats); + disk->dkstats = alloc_percpu(struct disk_stats, GFP_KERNEL);if (!disk->dkstats)return 0 ;return 1 ;
include/linux/percpu_counter.h +1 -1
@@ -30,7 +30,7 @@ {spin_lock_init (&fbc->lock); fbc->count =0 ; - fbc->counters =alloc_percpu (long); + fbc->counters =alloc_percpu (long,GFP_KERNEL ); }static inline void percpu_counter_destroy (struct percpu_counter *fbc)
net/core/neighbour.c +1 -1
@@ -1350,7 +1350,7 @@if (!tbl->kmem_cachep)panic ("cannot create neighbour cache" ); - tbl->stats = alloc_percpu(struct neigh_statistics); + tbl->stats = alloc_percpu(struct neigh_statistics, GFP_KERNEL);if (!tbl->stats)panic ("cannot create neighbour cache statistics" );
net/ipv4/af_inet.c +10 -10
@@ -985,16 +985,16 @@static int __init init_ipv4_mibs (void ) { - net_statistics[0] = alloc_percpu(struct linux_mib); - net_statistics[1] = alloc_percpu(struct linux_mib); - ip_statistics[0] = alloc_percpu(struct ipstats_mib); - ip_statistics[1] = alloc_percpu(struct ipstats_mib); - icmp_statistics[0] = alloc_percpu(struct icmp_mib); - icmp_statistics[1] = alloc_percpu(struct icmp_mib); - tcp_statistics[0] = alloc_percpu(struct tcp_mib); - tcp_statistics[1] = alloc_percpu(struct tcp_mib); - udp_statistics[0] = alloc_percpu(struct udp_mib); - udp_statistics[1] = alloc_percpu(struct udp_mib); + net_statistics[0] = alloc_percpu(struct linux_mib, GFP_KERNEL); + net_statistics[1] = alloc_percpu(struct linux_mib, GFP_KERNEL); + ip_statistics[0] = alloc_percpu(struct ipstats_mib, GFP_KERNEL); + ip_statistics[1] = alloc_percpu(struct ipstats_mib, GFP_KERNEL); + icmp_statistics[0] = alloc_percpu(struct icmp_mib, GFP_KERNEL); + icmp_statistics[1] = alloc_percpu(struct icmp_mib, GFP_KERNEL); + tcp_statistics[0] = alloc_percpu(struct tcp_mib, GFP_KERNEL); + tcp_statistics[1] = alloc_percpu(struct tcp_mib, GFP_KERNEL); + udp_statistics[0] = alloc_percpu(struct udp_mib, GFP_KERNEL); + udp_statistics[1] = alloc_percpu(struct udp_mib, GFP_KERNEL); if (! (net_statistics[0] && net_statistics[1] && ip_statistics[0] && ip_statistics[1] && tcp_statistics[0] && tcp_statistics[1]
net/ipv4/ipcomp.c +2 -2
@@ -306,7 +306,7 @@if (ipcomp_scratch_users++)return ipcomp_scratches; - scratches = alloc_percpu(void *); + scratches = alloc_percpu(void *, GFP_KERNEL);if (!scratches)return NULL ;
@@ -380,7 +380,7 @@INIT_LIST_HEAD (&pos->list);list_add (&pos->list, &ipcomp_tfms_list); - pos->tfms = tfms = alloc_percpu(struct crypto_tfm *); + pos->tfms = tfms = alloc_percpu(struct crypto_tfm *, GFP_KERNEL);if (!tfms) goto error;
net/ipv4/route.c +1 -1
@@ -3154,7 +3154,7 @@ ipv4_dst_ops.gc_thresh = (rt_hash_mask +1 ); ip_rt_max_size = (rt_hash_mask +1 ) *16 ; - rt_cache_stat = alloc_percpu(struct rt_cache_stat); + rt_cache_stat = alloc_percpu(struct rt_cache_stat, GFP_KERNEL);if (!rt_cache_stat)return -ENOMEM ;
net/ipv6/ipcomp6.c +2 -2
@@ -302,7 +302,7 @@if (ipcomp6_scratch_users++)return ipcomp6_scratches; - scratches = alloc_percpu(void *); + scratches = alloc_percpu(void *, GFP_KERNEL);if (!scratches)return NULL ;
@@ -376,7 +376,7 @@INIT_LIST_HEAD (&pos->list);list_add (&pos->list, &ipcomp6_tfms_list); - pos->tfms = tfms = alloc_percpu(struct crypto_tfm *); + pos->tfms = tfms = alloc_percpu(struct crypto_tfm *, GFP_KERNEL);if (!tfms) goto error;
net/sctp/protocol.c +2 -2
@@ -939,10 +939,10 @@static int __init init_sctp_mibs (void ) { - sctp_statistics[0] = alloc_percpu(struct sctp_mib); + sctp_statistics[0] = alloc_percpu(struct sctp_mib, GFP_KERNEL);if (!sctp_statistics[0 ])return -ENOMEM ; - sctp_statistics[1] = alloc_percpu(struct sctp_mib); + sctp_statistics[1] = alloc_percpu(struct sctp_mib, GFP_KERNEL);if (!sctp_statistics[1 ]) {free_percpu (sctp_statistics[0 ]);return -ENOMEM ;
PATCH 5/11 mm: Bigrefs -- add_getcpuptr
In reply to Ravikiran G ThirumalaiReintroduce __get_cpu_ptr for bigrefs
include/linux/percpu.h +1 -0
@@ -59,4 +59,5 @@ __alignof__(type), gfpflags))); \ }) +#define __get_cpu_ptr (ptr) per_cpu_ptr(ptr, smp_processor_id())#endif /* __LINUX_PERCPU_H */
PATCH 6/11 mm: Bigrefs -- distributed refcounters
In reply to Ravikiran G ThirumalaiDistributed refcounting infrastructure patch originally by Rusty Russel.
http://lkml.org/lkml/2005/1/14/47
Changes from the original:
- Rediffed and changed to use new alloc_percpu interface
- Added bigref_set for some applications which initialize refcounters to 0
- Donot call release at bigref_put if NULL
- Use synchronize_sched instead of synchronize_kernel
include/linux/bigref.h +84 -0
@@ -0,0 +1,84 @@ +#ifndef _LINUX_BIGREF_H +#define _LINUX_BIGREF_H +/* Per-cpu reference counters. Useful when speed is important, and +counter will only hit zero after some explicit event (such as being +discarded from a list). + +(C) 2003 Rusty Russell, IBM Corporation. +*/ +#include <linux/config.h> +#include <asm/atomic.h> +#include <asm/local.h> + +#ifdef CONFIG_SMP +struct bigref +{ +/* If this is zero, we use per-cpu counters. */ +atomic_t slow_ref; +local_t *local_ref; +}; + +/* Initialize reference to 1. */ +void bigref_init (struct bigref *bigref); +/* Initialize reference to val */ +void bigref_set (struct bigref *bigref,int val); +/* Disown reference: next bigref_put can hit zero */ +void bigref_disown (struct bigref *bigref); +/* Grab reference */ +void bigref_get (struct bigref *bigref); +/* Drop reference */ +void bigref_put (struct bigref *bigref,void (*release)(struct bigref *bigref)); +/* Destroy bigref prematurely (which might not have hit zero) */ +void bigref_destroy (struct bigref *bigref); + +/* Get current value of reference, useful for debugging info. */ +unsigned int bigref_val (struct bigref *bigref); +#else /* ... !SMP */ +struct bigref +{ +atomic_t ref; +}; + +/* Initialize reference to 1. */ +static inline void bigref_init (struct bigref *bigref) +{ +atomic_set (&bigref->ref,1 ); +} + +/* Initialize reference to val */ +static inline void bigref_set (struct bigref *bigref,int val) +{ +atomic_set (&bigref->ref, val); +} + +/* Disown reference: next bigref_put can hit zero */ +static inline void bigref_disown (struct bigref *bigref) +{ +} + +/* Grab reference */ +static inline void bigref_get (struct bigref *bigref) +{ +atomic_inc (&bigref->ref); +} + +/* Drop reference */ +static inline void bigref_put (struct bigref *bigref, +void (*release)(struct bigref *bigref)) +{ +if (atomic_dec_and_test (&bigref->ref)) +release (bigref); +} + +/* Get current value of reference, useful for debugging info. */ +static inline unsigned int bigref_val (struct bigref *bigref) +{ +return atomic_read (&bigref->ref); +} + +static inline void bigref_destroy (struct bigref *bigref) +{ +} +#endif /* !SMP */ + +#endif /* _LINUX_BIGREF_H */
kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o -obj-$(CONFIG_SMP) += cpu.o spinlock.o +obj-$(CONFIG_SMP) += cpu.o spinlock.o bigref.o obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_KALLSYMS) += kallsyms.o
kernel/bigref.c +112 -0
112 lines not on this page · raw message
Re: [patch 6/11] mm: Bigrefs -- distributed refcounters
Quoted 1 line · Ravikiran G Thirumalai
Signed-off-by Rusty Russel <[email protected]>
This is the second time this has happened in as many weeks, by different people Obviously, I can spell my own name, know my own email address, and did not sign off on this patch.
If Signed-off lines have a purpose, that is destroyed by fake ones. Worse, a future lawyer can now convincingly argue that many correctly-spelled Signed-off lines are worthless fakes, too.
A few well-placed private slaps on wrists can probably prevent this becoming common practice.
Rusty.
PS. Of course, it's only the dumb ones being caught at the moment.
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
Re: [patch 6/11] mm: Bigrefs -- distributed refcounters
Quoted 5 lines · Rusty Russell
Quoted 1 line · Ravikiran G Thirumalai
Signed-off-by Rusty Russel <[email protected]>This is the second time this has happened in as many weeks, by different people Obviously, I can spell my own name, know my own email address,
I am extremely sorry
Quoted 1 line
and did not sign off on this patch.
I thought the following was applicable here: (from SubmittingPatches)
(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
And since it was publised on lkml (and the signoff process was not in place then), I thought I could sign you off with a cc. I even added the url to your original posting. I guess I was wrong. Really sorry :(.
Quoted 3 lines
A few well-placed private slaps on wrists can probably prevent this becoming common practice.
Ouch. I have learnt my lesson.
Btw, what is linux-arch for? I couldn't find the listinfo on vger-lists.
Thanks,
Kiran
PATCH 7/11 net: Use bigrefs for net_device.refcount
In reply to Ravikiran G ThirumalaiThe net_device has a refcnt used to keep track of it's uses. This is used at the time of unregistering the network device (module unloading ..) (see netdev_wait_allrefs) .
For loopback_dev , this refcnt increment/decrement is causing unnecessary traffic on the interlink for NUMA system
affecting it's performance. This patch improves tbench numbers by 6% on a 8way x86 Xeon (x445).
This patch is dependent on the bigref patch
drivers/net/loopback.c +6 -0
@@ -226,6 +226,12 @@ loopback_dev.priv = stats; loopback_dev.get_stats = &get_stats; } + +/* +* This is the only struct net_device not allocated by alloc_netdev +* So explicitly init the bigref hanging off loopback_dev +*/ +bigref_init (&loopback_dev.netdev_refcnt);return register_netdev (&loopback_dev); };
include/linux/netdevice.h +5 -4
@@ -37,6 +37,7 @@#include <linux/config.h> #include <linux/device.h> #include <linux/percpu.h> +#include <linux/bigref.h> struct divert_blk ;struct vlan_group ;
@@ -377,7 +378,7 @@/* device queue lock */ spinlock_t queue_lock;/* Number of references to this device */ -atomic_t refcnt; +struct bigref netdev_refcnt;/* delayed register/unregister */ struct list_head todo_list;/* device name hash chain */
@@ -677,11 +678,11 @@static inline void dev_put (struct net_device *dev) { -atomic_dec (&dev->refcnt); +bigref_put (&dev->netdev_refcnt,NULL ); } -#define __dev_put (dev) atomic_dec(&(dev)->refcnt) -#define dev_hold (dev) atomic_inc(&(dev)->refcnt) +#define __dev_put (dev) bigref_put(&(dev)->netdev_refcnt, NULL); +#define dev_hold (dev) bigref_get(&(dev)->netdev_refcnt);/* Carrier loss detection, dial on demand. The functions netif_carrier_on * and _off may be called from IRQ context, but it is caller
net/core/dev.c +8 -4
@@ -2658,6 +2658,7 @@ goto out; dev->iflink =-1 ; +bigref_set (&dev->netdev_refcnt,0 );/* Init, if this function is available */ if (dev->init) {
@@ -2808,7 +2809,7 @@unsigned long rebroadcast_time, warning_time; rebroadcast_time = warning_time = jiffies; -while (atomic_read (&dev->refcnt) !=0 ) { +while (bigref_val (&dev->netdev_refcnt) !=0 ) {if (time_after (jiffies, rebroadcast_time +1 *HZ )) {rtnl_shlock ();
@@ -2838,7 +2839,7 @@printk (KERN_EMERG "unregister_netdevice: " "waiting for %s to become free. Usage " "count = %d\n" , - dev->name,atomic_read (&dev->refcnt)); + dev->name,bigref_val (&dev->netdev_refcnt)); warning_time = jiffies; } }
@@ -2909,7 +2910,7 @@netdev_wait_allrefs (dev);/* paranoia */ -BUG_ON (atomic_read (&dev->refcnt)); +BUG_ON (bigref_val (&dev->netdev_refcnt));BUG_TRAP (!dev->ip_ptr);BUG_TRAP (!dev->ip6_ptr);BUG_TRAP (!dev->dn_ptr);
@@ -2969,6 +2970,7 @@setup (dev);strcpy (dev->name, name); +bigref_init (&dev->netdev_refcnt);return dev; }EXPORT_SYMBOL (alloc_netdev);
@@ -2986,6 +2988,7 @@#ifdef CONFIG_SYSFS /* Compatiablity with error handling in drivers */ if (dev->reg_state ==NETREG_UNINITIALIZED ) { +bigref_destroy (&dev->netdev_refcnt);kfree ((char *)dev - dev->padded);return ; }
@@ -2996,6 +2999,7 @@/* will free via class release */ class_device_put (&dev->class_dev);#else +bigref_destroy (&dev->netdev_refcnt);kfree ((char *)dev - dev->padded);#endif }
@@ -3210,7 +3214,7 @@set_bit (__LINK_STATE_START, &queue->backlog_dev.state); queue->backlog_dev.weight = weight_p; queue->backlog_dev.poll = process_backlog; -atomic_set (&queue->backlog_dev.refcnt,1 ); +bigref_init (&queue->backlog_dev.netdev_refcnt); } dev_boot_phase =0 ;
net/core/net-sysfs.c +3 -0
@@ -16,6 +16,7 @@#include <net/sock.h> #include <linux/rtnetlink.h> #include <linux/wireless.h> +#include <linux/bigref.h> #define to_class_dev (obj) container_of(obj,struct class_device,kobj)#define to_net_dev (class) container_of(class, struct net_device, class_dev)
@@ -400,6 +401,8 @@ = container_of(cd, struct net_device, class_dev);BUG_ON (dev->reg_state !=NETREG_RELEASED ); + +bigref_destroy (&dev->netdev_refcnt);kfree ((char *)dev - dev->padded); }
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
Quoted 8 lines · On Tue, 13 Sep 2005 09:10:12 -0700 Ravikiran G Thirumalai <[email protected]>…
The
net_devicehas a refcnt used to keep track of it's uses. This is used at the time of unregistering the network device (module unloading ..) (seenetdev_wait_allrefs) .
Forloopback_dev, this refcnt increment/decrement is causing unnecessary traffic on the interlink for NUMA system
affecting it's performance. This patch improves tbench numbers by 6% on a 8way x86 Xeon (x445).
Since when is bringing a network device up/down performance critical?
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
Quoted 14 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 13 Sep 2005 09:10:12 -0700 Ravikiran G Thirumalai <[email protected]>…
The
net_devicehas a refcnt used to keep track of it's uses. This is used at the time of unregistering the network device (module unloading ..) (seenetdev_wait_allrefs) .
Forloopback_dev, this refcnt increment/decrement is causing unnecessary traffic on the interlink for NUMA system
affecting it's performance. This patch improves tbench numbers by 6% on a 8way x86 Xeon (x445).
Quoted 1 line
Since when is bringing a network device up/down performance critical?
We grab and drop a reference for each poll of a device, roughly.
See dev_hold in _netif_rx_schedule(struct net_device *dev) in include/netdevice.h, for instance.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
Quoted 15 lines · On Tue, 13 Sep 2005 09:35:14 -0700 Ben Greear <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 13 Sep 2005 09:10:12 -0700 Ravikiran G Thirumalai <[email protected]>…
The
net_devicehas a refcnt used to keep track of it's uses. This is used at the time of unregistering the network device (module unloading ..) (seenetdev_wait_allrefs) .
Forloopback_dev, this refcnt increment/decrement is causing unnecessary traffic on the interlink for NUMA system
affecting it's performance. This patch improves tbench numbers by 6% on a 8way x86 Xeon (x445).
Quoted 6 lines
Quoted 1 line
Since when is bringing a network device up/down performance critical?
We grab and drop a reference for each poll of a device, roughly.
See
dev_holdin_netif_rx_schedule(struct net_device *dev)ininclude/netdevice.h, for instance.
Yeah, that would be an issue, especially since the rest of that path is nicely per-cpu
David S. Miller
maintainerRe: [patch 7/11] net: Use bigrefs for net_device.refcount
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 13 Sep 2005 09:26:59 -0700
Quoted 1 line
Since when is bringing a network device up/down performance critical?
The issue is the dev_get()'s that occur all over the place to during packet transmit/receive, that's what they are trying to address.
I'm still against all of these invasive NUMA changes to the networking though, they are simply too ugly and special cased to consider seriously.
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
Quoted 5 lines · David S. Miller
From: Stephen Hemminger <[email protected]>
Date: Tue, 13 Sep 2005 09:26:59 -0700Quoted 1 line
Since when is bringing a network device up/down performance critical?
Quoted 7 lines
The issue is the dev_get()'s that occur all over the place to during packet transmit/receive, that's what they are trying to address.
I'm still against all of these invasive NUMA changes to the networking though, they are simply too ugly and special cased to consider seriously.
All of them or the dst ones? Hopefully the netdevice refcounter patch is not ugly or complicated as the dst ones? And why are they special cased? Are networking workloads with high route locality not interesting?
Thanks,
Kiran
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
In reply to Ravikiran G ThirumalaiQuoted 7 lines · Ravikiran G Thirumalai
The
net_devicehas a refcnt used to keep track of it's uses. This is used at the time of unregistering the network device (module unloading ..) (seenetdev_wait_allrefs) .
Forloopback_dev, this refcnt increment/decrement is causing unnecessary traffic on the interlink for NUMA system
affecting it's performance. This patch improves tbench numbers by 6% on a 8way x86 Xeon (x445).
===================================================================
include/linux/netdevice.h
Quoted 20 lines
include/linux/netdevice.h +2
-1@@ -37,6 +37,7 @@#include <linux/config.h> #include <linux/device.h> #include <linux/percpu.h> +#include <linux/bigref.h> struct divert_blk ;struct vlan_group ;@@ -377,7 +378,7 @@/* device queue lock */ spinlock_t queue_lock;/* Number of references to this device */ -atomic_t refcnt; +struct bigref netdev_refcnt;/* delayed register/unregister */ struct list_head todo_list;/* device name hash chain */ @@ -677,11 +678,11 @@
Hum...
Did you tried to place refcnt/netdev_refcnt in a separate cache line than queue_lock ? I got good results too...
include/linux/netdevice.h line 384
Quoted 8 lines
include/linux/netdevice.h +1
-1/* device queue lock */ spinlock_t queue_lock;/* Number of references to this device */ -atomic_t refcnt; +struct bigref netdev_refcnt____cacheline_aligned_in_smp ;/* delayed register/unregister */ struct list_head todo_list;/* device name hash chain */
Every time a cpu take the queue_lock spinlock, it exclusively gets one cache line. If another cpu try to access netdev_refcnt, it has to grab this cache line (even if properely per_cpu designed, there is still one shared field). In fact the whole struct net_device should be re-ordered for SMP/NUMA performance.
Eric
Re: [patch 7/11] net: Use bigrefs for net_device.refcount
Quoted 7 lines · Eric Dumazet
Ravikiran G Thirumalai a écrit :
Hum...
Did you tried to place refcnt/netdev_refcnt in a separate cache line than
queue_lock? I got good results too...
Quoted 14 lines
include/linux/netdevice.h line 384
Quoted 8 lines
include/linux/netdevice.h +1
-1/* device queue lock */ spinlock_t queue_lock;/* Number of references to this device */ -atomic_t refcnt; +struct bigref netdev_refcnt____cacheline_aligned_in_smp ;/* delayed register/unregister */ struct list_head todo_list;/* device name hash chain */ Every time a cpu take the
queue_lockspinlock, it exclusively gets one cache line. If another cpu try to accessnetdev_refcnt, it has to grab this cache line (even if properelyper_cpudesigned, there is still one shared field). In fact the whole structnet_deviceshould be re-ordered for SMP/NUMA performance.
I agree. Maybe placing the queue_lock in a different cacheline is the right approach?
Thanks,
Kiran
PATCH 8/11 net: dst_abstraction macros
In reply to Ravikiran G ThirumalaiThis patch introduces macros to handle the use, lastuse and refcnt fields in the dst_entry structure using macros. Having macros manipulate these fields allows cleaner source code and provides an easy way for modifications to the way these performance critical fields are handled.
The introduction of macros removes some code that is repeated in various places. Also
- decnet_dn_route: introduces dn_dst_useful to check the usefulness of a dst entry. dst_update_rtu used to reduce code duplication.
- net/ipv4/route.c: add ip_rt_copy. dst_update_rtu used to reduce code duplication.
The patch is a prerequisite for the dst numa patch.
include/net/dst.h +26 -17
@@ -103,6 +103,30 @@#ifdef __KERNEL__ +#define dst_use (__dst) (__dst)->__use +#define dst_use_inc (__dst) (__dst)->__use++ + +#define dst_lastuse (__dst) (__dst)->lastuse +#define dst_lastuse_set (__dst) (__dst)->lastuse = jiffies + +#define dst_update_tu (__dst) do { dst_lastuse_set(__dst);dst_use_inc(__dst); } while (0) +#define dst_update_rtu (__dst) do { dst_lastuse_set(__dst);dst_hold(__dst);dst_use_inc(__dst); } while (0) + +#define dst_refcnt (__dst) atomic_read(&(__dst)->__refcnt) +#define dst_refcnt_one (__dst) atomic_set(&(__dst)->__refcnt, 1) +#define dst_refcnt_dec (__dst) atomic_dec(&(__dst)->__refcnt) +#define dst_hold (__dst) atomic_inc(&(__dst)->__refcnt) + +static inline +void dst_release (struct dst_entry * dst) +{ +if (dst) { +WARN_ON (dst_refcnt (dst) <1 ); +smp_mb__before_atomic_dec (); +dst_refcnt_dec (dst); + } +} +static inline u32 dst_metric (const struct dst_entry *dst,int metric) {
@@ -134,29 +158,14 @@return dst_metric (dst,RTAX_LOCK ) & (1 <<metric); } -static inline void dst_hold (struct dst_entry * dst) -{ -atomic_inc (&dst->__refcnt); -} -static inline struct dst_entry *dst_clone (struct dst_entry * dst) {if (dst) -atomic_inc (&dst->__refcnt); +dst_hold (dst);return dst; } -static inline -void dst_release (struct dst_entry * dst) -{ -if (dst) { -WARN_ON (atomic_read (&dst->__refcnt) <1 ); -smp_mb__before_atomic_dec (); -atomic_dec (&dst->__refcnt); - } -} -/* Children define the path of the packet through the * Linux networking. Thus, destinations are stackable. */
@@ -177,7 +186,7 @@ {if (dst->obsolete >1 )return ; -if (!atomic_read (&dst->__refcnt)) { +if (!dst_refcnt (dst)) { dst =dst_destroy (dst);if (!dst)return ;
net/core/dst.c +10 -11
@@ -57,7 +57,7 @@ dstp = &dst_garbage_list; work_performed =0 ;while ((dst = *dstp) !=NULL ) { -if (atomic_read (&dst->__refcnt)) { +if (dst_refcnt (dst)) { dstp = &dst->next; delayed++;continue ;
@@ -176,9 +176,8 @@struct neighbour *neigh;struct hh_cache *hh; -smp_rmb (); - again: +smp_rmb (); neigh = dst->neighbour; hh = dst->hh; child = dst->child;
@@ -206,16 +205,16 @@ dst = child;if (dst) {int nohash = dst->flags &DST_NOHASH ; - -if (atomic_dec_and_test (&dst->__refcnt)) { -/* We were real parent of this dst, so kill child. */ -if (nohash) +dst_refcnt_dec (dst); +if (nohash) { +if (!dst_refcnt (dst)) { +/* We were real parent of this dst, so kill child. */ goto again; - }else { -/* Child is still referenced, return it for freeing. */ -if (nohash) + }else { +/* Child is still referenced, return it for freeing. */ return dst; -/* Child is still in his hash table */ +/* Child is still in his hash table */ + } } }return NULL ;
net/decnet/dn_route.c +21 -28
128 lines not on this page · raw message
net/ipv4/ipvs/ip_vs_xmit.c +1 -1
@@ -88,7 +88,7 @@__ip_vs_dst_set (dest, rtos,dst_clone (&rt->u.dst));IP_VS_DBG (10 ,"new dst %u.%u.%u.%u, refcnt=%d, rtos=%X\n" ,NIPQUAD (dest->addr), -atomic_read (&rt->u.dst.__refcnt), rtos); +dst_refcnt (&rt->u.dst), rtos); }spin_unlock (&dest->dst_lock); }else {
net/ipv4/multipath_drr.c +1 -2
@@ -149,8 +149,7 @@ multipath_comparekeys(&nh->fl, flp)) {int nh_ifidx = nh->u.dst.dev->ifindex; - nh->u.dst.lastuse = jiffies; - nh->u.dst.__use++; +dst_update_tu (&nh->u.dst);if (result !=NULL )continue ;
net/ipv4/multipath_random.c +3 -2
@@ -94,7 +94,8 @@for (rt = first; rt; rt = rt->u.rt_next) {if ((rt->u.dst.flags &DST_BALANCED ) !=0 &&multipath_comparekeys (&rt->fl, flp)) { - rt->u.dst.lastuse = jiffies; + +dst_lastuse_set (&rt->u.dst);if (i == candidate_no) decision = rt;
@@ -107,7 +108,7 @@ } } - decision->u.dst.__use++; +dst_use_inc (&decision->u.dst); *rp = decision; }
net/ipv4/multipath_rr.c +5 -4
@@ -62,10 +62,11 @@ nh = rcu_dereference(nh->u.rt_next)) {if ((nh->u.dst.flags &DST_BALANCED ) !=0 &&multipath_comparekeys (&nh->fl, flp)) { - nh->u.dst.lastuse = jiffies; +int __use =dst_use (&nh->u.dst); +dst_lastuse_set (&nh->u.dst); -if (min_use ==-1 || nh->u.dst.__use < min_use) { - min_use = nh->u.dst.__use; +if (min_use ==-1 || __use < min_use) { + min_use = __use; min_use_cand = nh; } }
@@ -74,7 +75,7 @@if (!result) result = first; - result->u.dst.__use++; +dst_use_inc (&result->u.dst); *rp = result; }
net/ipv4/multipath_wrandom.c +2 -3
@@ -202,7 +202,7 @@ decision = first; last_mpc =NULL ;for (mpc = first_mpc; mpc; mpc = mpc->next) { - mpc->rt->u.dst.lastuse = jiffies; +dst_lastuse_set (&mpc->rt->u.dst);if (last_power <= selector && selector < mpc->power) decision = mpc->rt;
@@ -217,8 +217,7 @@/* concurrent __multipath_flush may lead to !last_mpc */ kfree (last_mpc); } - - decision->u.dst.__use++; +dst_use_inc (&decision->u.dst); *rp = decision; }
net/ipv4/route.c +28 -29
159 lines not on this page · raw message
net/ipv4/xfrm4_policy.c +1 -1
@@ -135,7 +135,7 @@dev_hold (rt->u.dst.dev); dst_prev->obsolete =-1 ; dst_prev->flags |=DST_HOST ; - dst_prev->lastuse = jiffies; +dst_lastuse_set (dst_prev); dst_prev->header_len = header_len; dst_prev->trailer_len = trailer_len;memcpy (&dst_prev->metrics, &x->route->metrics,sizeof (dst_prev->metrics));
net/ipv6/ip6_fib.c +2 -2
@@ -1160,8 +1160,8 @@ } gc_args.more++; }else if (rt->rt6i_flags &RTF_CACHE ) { -if (atomic_read (&rt->u.dst.__refcnt) ==0 && -time_after_eq (now, rt->u.dst.lastuse + gc_args.timeout)) { +if (dst_refcnt (&rt->u.dst) ==0 && +time_after_eq (now,dst_lastuse (&rt->u.dst) + gc_args.timeout)) {RT6_TRACE ("aging clone %p\n" , rt);return -1 ; } else if ((rt->rt6i_flags & RTF_GATEWAY) &&
net/ipv6/route.c +13 -16
@@ -368,10 +368,9 @@ fn =fib6_lookup (&ip6_routing_table, daddr, saddr); rt =rt6_device_match (fn->leaf, oif, strict);dst_hold (&rt->u.dst); - rt->u.dst.__use++; -read_unlock_bh (&rt6_lock); - rt->u.dst.lastuse = jiffies; +read_unlock_bh (&rt6_lock); +dst_update_tu (&rt->u.dst);if (rt->u.dst.error ==0 )return rt;dst_release (&rt->u.dst);
@@ -512,8 +511,7 @@ out:read_unlock_bh (&rt6_lock); out2: - rt->u.dst.lastuse = jiffies; - rt->u.dst.__use++; +dst_update_tu (&rt->u.dst); skb->dst = (struct dst_entry *) rt; }
@@ -572,8 +570,7 @@ out:read_unlock_bh (&rt6_lock); out2: - rt->u.dst.lastuse = jiffies; - rt->u.dst.__use++; +dst_update_tu (&rt->u.dst);return &rt->u.dst; }
@@ -685,7 +682,7 @@ rt->rt6i_dev = dev; rt->rt6i_idev = idev; rt->rt6i_nexthop = neigh; -atomic_set (&rt->u.dst.__refcnt,1 ); +dst_refcnt_one (&rt->u.dst); rt->u.dst.metrics[RTAX_HOPLIMIT -1 ] =255 ; rt->u.dst.metrics[RTAX_MTU -1 ] =ipv6_get_mtu (rt->rt6i_dev); rt->u.dst.metrics[RTAX_ADVMSS -1 ] =ipv6_advmss (dst_mtu (&rt->u.dst));
@@ -719,7 +716,7 @@ pprev = &ndisc_dst_gc_list; freed =0 ;while ((dst = *pprev) !=NULL ) { -if (!atomic_read (&dst->__refcnt)) { +if (!dst_refcnt (dst)) { *pprev = dst->next;dst_free (dst); freed++;
@@ -1261,7 +1258,7 @@ rt->rt6i_idev = ort->rt6i_idev;if (rt->rt6i_idev)in6_dev_hold (rt->rt6i_idev); - rt->u.dst.lastuse = jiffies; +dst_lastuse_set (&rt->u.dst); rt->rt6i_expires =0 ;ipv6_addr_copy (&rt->rt6i_gateway, &ort->rt6i_gateway);
@@ -1424,7 +1421,7 @@ipv6_addr_copy (&rt->rt6i_dst.addr, addr); rt->rt6i_dst.plen =128 ; -atomic_set (&rt->u.dst.__refcnt,1 ); +dst_refcnt_one (&rt->u.dst);return rt; }
@@ -1637,13 +1634,13 @@if (rt->u.dst.dev)RTA_PUT (skb,RTA_OIF ,sizeof (int ), &rt->rt6i_dev->ifindex);RTA_PUT (skb,RTA_PRIORITY ,4 , &rt->rt6i_metric); - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); + ci.rta_lastuse =jiffies_to_clock_t (jiffies -dst_lastuse (&rt->u.dst));if (rt->rt6i_expires) ci.rta_expires =jiffies_to_clock_t (rt->rt6i_expires - jiffies);else ci.rta_expires =0 ; - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); + ci.rta_used =dst_use (&rt->u.dst); + ci.rta_clntref =dst_refcnt (&rt->u.dst); ci.rta_error = rt->u.dst.error; ci.rta_id =0 ; ci.rta_ts =0 ;
@@ -1927,8 +1924,8 @@ } arg->len +=sprintf (arg->buffer + arg->len," %08x %08x %08x %08x %8s\n" , - rt->rt6i_metric,atomic_read (&rt->u.dst.__refcnt), - rt->u.dst.__use, rt->rt6i_flags, + rt->rt6i_metric,dst_refcnt (&rt->u.dst), +dst_use (&rt->u.dst), rt->rt6i_flags, rt->rt6i_dev ? rt->rt6i_dev->name :"" );return 0 ; }
net/ipv6/xfrm6_policy.c +1 -1
@@ -156,7 +156,7 @@dev_hold (rt->u.dst.dev); dst_prev->obsolete =-1 ; dst_prev->flags |=DST_HOST ; - dst_prev->lastuse = jiffies; +dst_lastuse_set (dst_prev); dst_prev->header_len = header_len; dst_prev->trailer_len = trailer_len;memcpy (&dst_prev->metrics, &x->route->metrics,sizeof (dst_prev->metrics));
net/xfrm/xfrm_policy.c +1 -1
@@ -1090,7 +1090,7 @@static int unused_bundle (struct dst_entry *dst) { -return !atomic_read (&dst->__refcnt); +return !dst_refcnt (dst); }static void __xfrm_garbage_collect (void )
PATCH 9/11 net: dst_entry.refcount, use, lastuse to use alloc_percpu
In reply to Ravikiran G ThirumalaiPatch to use alloc_percpu for dst_entry.refcount. This patch reduces the cacheline bouncing of the atomic_t dst_entry.__refcount. This Patch gets us 55% better tbench throughput, on a 8way x445 box.
Signed-off by: Pravin B. Shelar <[email protected]> Signed-off by: Shobhit Dayal <[email protected]> Signed-off by: Christoph Lameter <[email protected]> Signed-off by: Ravikiran Thirumalai <[email protected]>
include/net/dst.h +136 -4
@@ -35,11 +35,33 @@struct sk_buff ; +#ifdef CONFIG_NUMA + +/* A per cpu instance of this exist for every dst_entry. +* These are the most written fields of dst_entry. +*/ +struct per_cpu_cnt +{ +int refcnt; +int use; +unsigned long lastuse; +}; + +#endif +struct dst_entry {struct dst_entry *next; +#ifdef CONFIG_NUMA +/* first cpu that should be checked for time-out */ +int s_cpu; +/* per cpu client references */ +struct per_cpu_cnt *pcc; +#else atomic_t __refcnt;/* client references */ int __use; +unsigned long lastuse; +#endif struct dst_entry *child;struct net_device *dev;short error;
@@ -50,7 +72,6 @@#define DST_NOPOLICY 4#define DST_NOHASH 8#define DST_BALANCED 0x10 -unsigned long lastuse;unsigned long expires;unsigned short header_len;/* more space at head required */
@@ -103,25 +124,94 @@#ifdef __KERNEL__ +#ifdef CONFIG_NUMA + +static inline int dst_use (struct dst_entry *dst) +{ +int total =0 , cpu; + +for_each_online_cpu (cpu) + total +=per_cpu_ptr (dst->pcc, cpu)->use; +return total; +} + +#define dst_use_inc (__dst) do { \ + per_cpu_ptr((__dst)->pcc, get_cpu())->use++ ; \ + put_cpu(); \ + } while(0); + +static inline unsigned long dst_lastuse (struct dst_entry *dst) +{ +unsigned long max =0 ; +int cpu; + +for_each_online_cpu (cpu) +if (max <per_cpu_ptr (dst->pcc, cpu)->lastuse) + max =per_cpu_ptr (dst->pcc, cpu)->lastuse; +return max; +} + +#define dst_lastuse_set (__dst) do { \ + per_cpu_ptr((__dst)->pcc, get_cpu())->lastuse = jiffies ; \ + put_cpu(); \ + } while(0); + +static inline int dst_refcnt (struct dst_entry *dst) +{ +int cpu, sum =0 ; + +for_each_online_cpu (cpu) + sum +=per_cpu_ptr (dst->pcc, cpu)->refcnt; + +return sum; +} + +#define dst_refcnt_one (__dst) do { \ + per_cpu_ptr((__dst)->pcc, get_cpu())->refcnt = 1; \ + put_cpu(); \ + } while(0); + +#define dst_refcnt_dec (__dst) do { \ + per_cpu_ptr((__dst)->pcc, get_cpu())->refcnt--; \ + put_cpu(); \ + } while(0); +#define dst_hold (__dst) do { \ + per_cpu_ptr((__dst)->pcc, get_cpu())->refcnt++ ; \ + put_cpu(); \ + } while(0); + +#else +#define dst_use (__dst) (__dst)->__use#define dst_use_inc (__dst) (__dst)->__use++#define dst_lastuse (__dst) (__dst)->lastuse#define dst_lastuse_set (__dst) (__dst)->lastuse = jiffies -#define dst_update_tu (__dst) do { dst_lastuse_set(__dst);dst_use_inc(__dst); } while (0) -#define dst_update_rtu (__dst) do { dst_lastuse_set(__dst);dst_hold(__dst);dst_use_inc(__dst); } while (0) -#define dst_refcnt (__dst) atomic_read(&(__dst)->__refcnt)#define dst_refcnt_one (__dst) atomic_set(&(__dst)->__refcnt, 1)#define dst_refcnt_dec (__dst) atomic_dec(&(__dst)->__refcnt)#define dst_hold (__dst) atomic_inc(&(__dst)->__refcnt) +#endif +#define dst_update_tu (__dst) do { \ + dst_lastuse_set(__dst); \ + dst_use_inc(__dst); \ + } while (0); + +#define dst_update_rtu (__dst) do { \ + dst_lastuse_set(__dst); \ + dst_hold(__dst); \ + dst_use_inc(__dst); \ + } while (0) +static inline void dst_release (struct dst_entry * dst) {if (dst) { +#if (!defined (CONFIG_NUMA ) || (RT_CACHE_DEBUG >=2 ))WARN_ON (dst_refcnt (dst) <1 ); +#endif smp_mb__before_atomic_dec ();dst_refcnt_dec (dst); }
@@ -271,6 +361,48 @@extern void dst_init (void ); +/* This function allocates and initializes rtu array of given dst-entry. +*/ +static inline int dst_init_rtu_array (struct dst_entry *dst) +{ +#ifdef CONFIG_NUMA +int cpu; + dst->pcc = alloc_percpu(struct per_cpu_cnt, GFP_ATOMIC); +if (!dst->pcc) +return -ENOMEM ; + +for_each_cpu (cpu) { +per_cpu_ptr (dst->pcc, cpu)->use =0 ; +per_cpu_ptr (dst->pcc, cpu)->refcnt =0 ; +per_cpu_ptr (dst->pcc, cpu)->lastuse = jiffies; + } + dst->s_cpu =smp_processor_id (); +#else +atomic_set (&dst->__refcnt,0 ); + dst->lastuse = jiffies; +#endif +return 0 ; +} + +static inline void dst_free_rtu_array (struct dst_entry *dst) +{ +#ifdef CONFIG_NUMA +free_percpu (dst->pcc); +#endif +} + +#if defined (CONFIG_HOTPLUG_CPU ) && defined (CONFIG_NUMA ) +inline static void dst_ref_xfr_cpu_down (struct dst_entry *__dst,int cpu) +{ +int refcnt =per_cpu_ptr ((__dst)->pcc, cpu)->refcnt; +if (refcnt) { +per_cpu_ptr ((__dst)->pcc,get_cpu ())->refcnt += refcnt; +put_cpu (); +per_cpu_ptr ((__dst)->pcc, cpu)->refcnt =0 ; + } +} +#endif +struct flowi ;#ifndef CONFIG_XFRM static inline int xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,
net/bridge/br_netfilter.c +5 -1
@@ -85,7 +85,6 @@static struct rtable __fake_rtable = { .u = { .dst = { - .__refcnt =ATOMIC_INIT (1 ), .dev = &__fake_net_device, .path = &__fake_rtable.u.dst, .metrics = {[RTAX_MTU -1 ] =1500 },
@@ -1010,6 +1009,10 @@ {int i; +if (dst_init_rtu_array (&__fake_rtable.u.dst) <0 ) +panic ("br_netfilter : cannot allocate memory for dst-entry rtu array" ); +dst_refcnt_one (&__fake_rtable.u.dst); +for (i =0 ; i <ARRAY_SIZE (br_nf_ops); i++) {int ret;
@@ -1046,4 +1049,5 @@#ifdef CONFIG_SYSCTL unregister_sysctl_table (brnf_sysctl_header);#endif +dst_free_rtu_array (&__fake_rtable.u.dst); }
net/core/dst.c +3 -2
@@ -131,9 +131,9 @@if (!dst)return NULL ;memset (dst,0 , ops->entry_size); -atomic_set (&dst->__refcnt,0 ); +if (dst_init_rtu_array (dst) <0 ) +return NULL ; dst->ops = ops; - dst->lastuse = jiffies; dst->path = dst; dst->input = dst_discard_in; dst->output = dst_discard_out;
@@ -200,6 +200,7 @@#if RT_CACHE_DEBUG >=2 atomic_dec (&dst_total);#endif +dst_free_rtu_array (dst);kmem_cache_free (dst->ops->kmem_cachep, dst); dst = child;
net/decnet/dn_route.c +66 -0
95 lines not on this page · raw message
net/ipv4/route.c +92 -0
130 lines not on this page · raw message
net/ipv6/ip6_fib.c +35 -0
@@ -1209,6 +1209,35 @@spin_unlock_bh (&fib6_gc_lock); } +#if defined(CONFIG_NUMA ) && defined(CONFIG_HOTPLUG_CPU ) +#include <linux/cpu.h> +inline static int rt6_ref_xfr_cpu_down (struct rt6_info *rt,void *arg) +{ +dst_ref_xfr_cpu_down (&rt->u.dst, (int )arg); +return 0 ; +} + +static int __devinit ipv6_rtcache_cpu_callback (struct notifier_block *nfb, +unsigned long action, +void *hcpu) +{ +int cpu = (int ) hcpu; + +switch (action) { +case CPU_DEAD : +write_lock_bh (&rt6_lock); +fib6_clean_tree (&ip6_routing_table, rt6_ref_xfr_cpu_down, +0 , (void *)cpu); +write_unlock_bh (&rt6_lock); +break ; + } +return NOTIFY_OK ; +} + +static struct notifier_block ipv6_rtcache_cpu_notifier = + { &ipv6_rtcache_cpu_callback,NULL ,0 }; +#endif +void __init fib6_init (void ) { fib6_node_kmem = kmem_cache_create("fib6_nodes",
@@ -1217,10 +1246,16 @@ NULL, NULL);if (!fib6_node_kmem)panic ("cannot create fib6_nodes cache" ); +#if defined(CONFIG_NUMA ) && defined(CONFIG_HOTPLUG_CPU ) +register_cpu_notifier (&ipv6_rtcache_cpu_notifier); +#endif }void fib6_gc_cleanup (void ) { +#if defined(CONFIG_NUMA ) && defined(CONFIG_HOTPLUG_CPU ) +unregister_cpu_notifier (&ipv6_rtcache_cpu_notifier); +#endif del_timer (&ip6_fib_timer);kmem_cache_destroy (fib6_node_kmem); }
net/ipv6/route.c +5 -2
@@ -110,8 +110,6 @@struct rt6_info ip6_null_entry = { .u = { .dst = { - .__refcnt =ATOMIC_INIT (1 ), - .__use =1 , .dev = &loopback_dev, .obsolete =-1 , .error = -ENETUNREACH ,
@@ -2104,6 +2102,10 @@ NULL, NULL);if (!ip6_dst_ops.kmem_cachep)panic ("cannot create ip6_dst_cache" ); +if (dst_init_rtu_array (&ip6_null_entry.u.dst) <0 ) +panic ("ip6_route : can't allocate memory for dst-entry array" ); +dst_use_inc (&ipv6_null_entry.u.dist); +dst_refcnt_one (&ip6_null_entry.u.dst);fib6_init ();#ifdef CONFIG_PROC_FS
@@ -2130,4 +2132,5 @@rt6_ifdown (NULL );fib6_gc_cleanup ();kmem_cache_destroy (ip6_dst_ops.kmem_cachep); +dst_free_rtu_array (&ip6_null_entry.u.dst); }
David S. Miller
maintainerRe: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
There is no way in the world this enormous amount of NUMA complexity is being added to the destination cache layer.
Sorry.
Re: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
Quoted 3 lines · David S. Miller
There is no way in the world this enormous amount of NUMA complexity is being added to the destination cache layer.
Agreed the dst changes are ugly; that can be worked on. But the cacheline bouncing problem on the atomic_t dst_entry refcounter has been around for quite a while -- even on SMPs, not just NUMA. We need a solution for that. I thought you were against the dst_entry bloat caused by the previous version of the dst patch. alloc_percpu takes that away. You had concerns about workloads with low route locality. Unfortunately we don't have access to infrastructure setup for such tests :(
As for the ugliness, would something on the lines of net_device refcounter patch in the series above be acceptable?
Thanks,
Kiran
David S. Miller
maintainerRe: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
From: Ravikiran G Thirumalai <[email protected]>
Date: Tue, 13 Sep 2005 15:07:37 -0700
Quoted 8 lines
Agreed the dst changes are ugly; that can be worked on. But the cacheline bouncing problem on the
atomic_tdst_entryrefcounter has been around for quite a while -- even on SMPs, not just NUMA. We need a solution for that. I thought you were against thedst_entrybloat caused by the previous version of the dst patch.alloc_percputakes that away. You had concerns about workloads with low route locality. Unfortunately we don't have access to infrastructure setup for such tests :(
You don't have two computers connected on a network?
All you need is that, load a bunch of routes into one system that point to an IP address which you just force an ARP entry for (so it just gets lost in the ether) and then generate a rDOS workload through it from another machine using pktgen.
I'm fine with funny per-cpu memory allocation strategies, perhaps (would have to see a patch doing _only_ that to be sure).
But using bigrefs, no way. We have enough trouble making the data structures small without adding bloat like that. A busy server can have hundreds of thousands of dst cache entries active on it, and they chew up enough memory as is.
Re: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
Quoted 8 lines · David S. Miller
From: Ravikiran G Thirumalai <[email protected]>
Date: Tue, 13 Sep 2005 15:07:37 -0700
...
But using bigrefs, no way. We have enough trouble making the data structures small without adding bloat like that. A busy server can have hundreds of thousands of dst cache entries active on it, and they chew up enough memory as is.
But even 1 Million dst cache entries would be 16+4 MB additional for a 4 cpu box....is that too much? The alloc_percpu reimplementation interleaves objects on cache lines, unlike the existing implementation which pads per-cpu objects to cache lines...
If you are referring to embedded routing devices,
would they use CONFIG_NUMA or CONFIG_SMP?? (bigrefs nicely fold back to regular atomic_t s on UPs)
Thanks,
Kiran
David S. Miller
maintainerRe: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
From: Ravikiran G Thirumalai <[email protected]>
Date: Tue, 13 Sep 2005 16:17:17 -0700
Quoted 2 lines
But even 1 Million dst cache entries would be 16+4 MB additional for a 4 cpu box....is that too much?
Absolutely.
Per-cpu counters are great for things like single instance statistics et al. But once you start doing them per-object that's out of control bloat as far as I'm concerned.
Re: [patch 9/11] net: dst_entry.refcount, use, lastuse to use alloc_percpu
Quoted 11 lines · David S. Miller
From: Ravikiran G Thirumalai <[email protected]>
Date: Tue, 13 Sep 2005 16:17:17 -0700Quoted 2 lines
But even 1 Million dst cache entries would be 16+4 MB additional for a 4 cpu box....is that too much?
Absolutely.
Per-cpu counters are great for things like single instance statistics et al. But once you start doing them per-object that's out of control bloat as far as I'm concerned.
This is why my original per-cpu allocator patch was damn slow, and GFP_KERNEL only. I wasn't convinced that high-churn objects are a good fit for spreading across cpus.
I thought that net devices and modules (which uses a primitive hard-coded "bigref" currently) were a fair uses for bigrefs, though I'd like to see some stats.
Cheers,
Rusty.
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
PATCH 10/11 mm: Reimplementation of dynamic per-cpu allocator -- allow_early_mapvmarea
In reply to Ravikiran G ThirumalaiThis patch provides for early calls to map_vm_area. Currently, map_vm_area cannot be called early during the boot process since map_vm_area depends on kmalloc for the vm_struct objects. This patch is a bad hack to let map_vm_area work early, but just for a few calls so that the dynamic per-cpu subsystem can allocate a block and satisfy some early requests. This is primarily to enable slab code use alloc_percpu for slab head arrays. This patch might not be elegant, but solves the chicken and egg problem in using alloc_percpu for slab.
include/linux/slab.h +2 -0
@@ -76,6 +76,8 @@extern struct cache_sizes malloc_sizes[];extern void *__kmalloc (size_t ,unsigned int __nocast ); +#define SLAB_READY ({malloc_sizes[0].cs_cachep != NULL;}) +static inline void *kmalloc (size_t size,unsigned int __nocast flags) {if (__builtin_constant_p (size)) {
include/linux/vmalloc.h +1 -0
@@ -8,6 +8,7 @@#define VM_IOREMAP 0x00000001/* ioremap() and friends */ #define VM_ALLOC 0x00000002/* vmalloc() */ #define VM_MAP 0x00000004/* vmap()ed pages */ +#define VM_EARLY 0x00000008/* indicates static vm_struct */ /* bits [20..32] reserved for arch specific ioremap internals */ struct vm_struct {
mm/vmalloc.c +28 -7
@@ -160,6 +160,15 @@#define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT)/* 128 pages */ +/* +* Statically define a few vm_structs so that early per-cpu allocator code +* can get vm_areas even before slab is up. NR_EARLY_VMAREAS should remain +* in single digits +*/ +#define NR_EARLY_VMAREAS (1) +static struct vm_struct early_vmareas[NR_EARLY_VMAREAS ]; +static int early_vmareas_idx =0 ; +struct vm_struct *__get_vm_area (unsigned long size,unsigned long flags,unsigned long start,unsigned long end,unsigned int gfp_flags)
@@ -168,6 +177,9 @@unsigned long align =1 ;unsigned long addr; +if (unlikely (!size)) +return NULL ; +if (flags &VM_IOREMAP ) {int bit =fls (size);
@@ -184,10 +196,16 @@ area =kmalloc (sizeof (*area), gfp_flags);if (unlikely (!area))return NULL ; - -if (unlikely (!size)) { -kfree (area); -return NULL ; +if (likely (SLAB_READY )) { + area =kmalloc (sizeof (*area),GFP_KERNEL ); +if (unlikely (!area)) +return NULL ; + }else { +if (early_vmareas_idx <NR_EARLY_VMAREAS ) { + area = &early_vmareas[early_vmareas_idx++]; + flags |=VM_EARLY ; + }else +return NULL ; }/*
@@ -228,7 +246,8 @@ out:write_unlock (&vmlist_lock); -kfree (area); +if (likely (!(flags &VM_EARLY ))) +kfree (area);if (printk_ratelimit ())printk (KERN_WARNING "allocation failed: out of vmalloc space - use vmalloc=<size> to increase size.\n" );return NULL ;
@@ -326,7 +345,8 @@kfree (area->pages); } -kfree (area); +if (likely (!(area->flags &VM_EARLY ))) +kfree (area);return ; }
@@ -415,7 +435,8 @@ area->pages = pages;if (!area->pages) {remove_vm_area (area->addr); -kfree (area); +if (likely (!(area->flags &VM_EARLY ))) +kfree (area);return NULL ; }memset (area->pages,0 , array_size);
PATCH 11/11 mm: Reimplementation of dynamic per-cpu allocator -- hotplug_alloc_percpu_blocks
In reply to Ravikiran G ThirumalaiPatch to hotplug chunks of memory for alloc_percpu blocks when a cpu comes up. This is needed when alloc_percpu is used real early and the cpu_possible mask is not fully setup. Then, the backing chunks of memory are allocated when cpus come up.
include/linux/percpu.h +3 -0
@@ -31,6 +31,7 @@extern void *__alloc_percpu (size_t size,size_t align,unsigned int gfpflags);extern void free_percpu (const void *); +extern void __init alloc_percpu_init (void );#else /* CONFIG_SMP */
@@ -49,6 +50,8 @@ kfree(ptr); } +#define alloc_percpu_init () do {} while (0) +#endif /* CONFIG_SMP */ /* Simple wrapper for the common case: zeros memory. */
init/main.c +3 -0
@@ -495,6 +495,9 @@#endif vfs_caches_init_early ();mem_init (); + +alloc_percpu_init (); +kmem_cache_init ();setup_per_cpu_pageset ();numa_policy_init ();
mm/percpu.c +89 -2
111 lines not on this page · raw message