]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/zbud.c
Merge tag 'rdma-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[karo-tx-linux.git] / mm / zbud.c
index f26e7fcc7fa25c7316f60235e8c402ff6bec4f26..4e387bea702eca644da2547c3bd8f9537291c189 100644 (file)
--- a/mm/zbud.c
+++ b/mm/zbud.c
  * NCHUNKS_ORDER determines the internal allocation granularity, effectively
  * adjusting internal fragmentation.  It also determines the number of
  * freelists maintained in each pool. NCHUNKS_ORDER of 6 means that the
- * allocation granularity will be in chunks of size PAGE_SIZE/64, and there
- * will be 64 freelists per pool.
+ * allocation granularity will be in chunks of size PAGE_SIZE/64. As one chunk
+ * in allocated page is occupied by zbud header, NCHUNKS will be calculated to
+ * 63 which shows the max number of free chunks in zbud page, also there will be
+ * 63 freelists per pool.
  */
 #define NCHUNKS_ORDER  6
 
 #define CHUNK_SHIFT    (PAGE_SHIFT - NCHUNKS_ORDER)
 #define CHUNK_SIZE     (1 << CHUNK_SHIFT)
-#define NCHUNKS                (PAGE_SIZE >> CHUNK_SHIFT)
 #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
+#define NCHUNKS                ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
 
 /**
  * struct zbud_pool - stores metadata for each zbud pool
@@ -130,7 +132,7 @@ static struct zbud_ops zbud_zpool_ops = {
 
 static void *zbud_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops)
 {
-       return zbud_create_pool(gfp, &zbud_zpool_ops);
+       return zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
 }
 
 static void zbud_zpool_destroy(void *pool)
@@ -268,10 +270,9 @@ static int num_free_chunks(struct zbud_header *zhdr)
 {
        /*
         * Rather than branch for different situations, just use the fact that
-        * free buddies have a length of zero to simplify everything. -1 at the
-        * end for the zbud header.
+        * free buddies have a length of zero to simplify everything.
         */
-       return NCHUNKS - zhdr->first_chunks - zhdr->last_chunks - 1;
+       return NCHUNKS - zhdr->first_chunks - zhdr->last_chunks;
 }
 
 /*****************
@@ -618,5 +619,5 @@ module_init(init_zbud);
 module_exit(exit_zbud);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Seth Jennings <sjenning@linux.vnet.ibm.com>");
+MODULE_AUTHOR("Seth Jennings <sjennings@variantweb.net>");
 MODULE_DESCRIPTION("Buddy Allocator for Compressed Pages");