mm: maintain randomization of page free lists
[sfrench/cifs-2.6.git] / mm / shuffle.c
index bc0419a61fbe1aa1d1fcd2f734ec38d1eb9f4a45..3ce12481b1dccfb01112ca9b168a442cc81d5d4f 100644 (file)
@@ -182,3 +182,26 @@ void __meminit __shuffle_free_memory(pg_data_t *pgdat)
        for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
                shuffle_zone(z);
 }
+
+void add_to_free_area_random(struct page *page, struct free_area *area,
+               int migratetype)
+{
+       static u64 rand;
+       static u8 rand_bits;
+
+       /*
+        * The lack of locking is deliberate. If 2 threads race to
+        * update the rand state it just adds to the entropy.
+        */
+       if (rand_bits == 0) {
+               rand_bits = 64;
+               rand = get_random_u64();
+       }
+
+       if (rand & 1)
+               add_to_free_area(page, area, migratetype);
+       else
+               add_to_free_area_tail(page, area, migratetype);
+       rand_bits--;
+       rand >>= 1;
+}