x86: PAT documentation
[sfrench/cifs-2.6.git] / mm / allocpercpu.c
index b2486cf887a06c1ecbd3c3d60d10682e2e5fc7d0..b0012e27fea8796da01cfb2172d1d5930c60d22f 100644 (file)
@@ -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,13 +56,15 @@ 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)) {
-               /* FIXME: kzalloc_node(size, gfp, node) */
-               pdata->ptrs[cpu] = kmalloc_node(size, gfp, node);
-               if (pdata->ptrs[cpu])
-                       memset(pdata->ptrs[cpu], 0, size);
-       } else
+       if (node_online(node))
+               pdata->ptrs[cpu] = kmalloc_node(size, gfp|__GFP_ZERO, node);
+       else
                pdata->ptrs[cpu] = kzalloc(size, gfp);
        return pdata->ptrs[cpu];
 }
@@ -101,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))