Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.24.5-rc2 /mm/allocpercpu.c

Filename:/mm/allocpercpu.c
Lines Added:14
Lines Deleted:1
Also changed in: (Previous) 2.6.24.5-rc1  2.6.24-git22  2.6.24-git21  2.6.24-git20  2.6.24-git19  2.6.24-git18 
(Following) 2.6.24.5  2.6.24.6  2.6.24.7  2.6.25-git3  2.6.25-git4  2.6.25-git5 

Location
[  2.6.24.5-rc2
  [  mm
     o  allocpercpu.c

Patch

diff --git a/mm/allocpercpu.c b/mm/allocpercpu.c
index 00b0262..b0012e2 100644
--- a/mm/allocpercpu.c
+++ b/mm/allocpercpu.c
@@ -6,6 +6,10 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 
+#ifndef cache_line_size
+#define cache_line_size()   L1_CACHE_BYTES
+#endif
+
 /**
  * percpu_depopulate - depopulate per-cpu data for given cpu
  * @__pdata: per-cpu data to depopulate
@@ -52,6 +56,11 @@ void *percpu_populate(void *__pdata, size_t size, gfp_t gfp, int cpu)
    struct percpu_data *pdata = __percpu_disguise(__pdata);
    int node = cpu_to_node(cpu);
 
+   /*
+    * We should make sure each CPU gets private memory.
+    */
+   size = roundup(size, cache_line_size());
+
    BUG_ON(pdata->ptrs[cpu]);
    if (node_online(node))
       pdata->ptrs[cpu] = kmalloc_node(size, gfp|__GFP_ZERO, node);
@@ -98,7 +107,11 @@ EXPORT_SYMBOL_GPL(__percpu_populate_mask);
  */
 void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
 {
-   void *pdata = kzalloc(sizeof(struct percpu_data), gfp);
+   /*
+    * We allocate whole cache lines to avoid false sharing
+    */
+   size_t sz = roundup(nr_cpu_ids * sizeof(void *), cache_line_size());
+   void *pdata = kzalloc(sz, gfp);
    void *__pdata = __percpu_disguise(pdata);
 
    if (unlikely(!pdata))


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.