Whamcloud - gitweb
LU-7982 libcfs: memory allocation without CPT for binheap 17/19317/5
authorLi Xi <lixi@ddn.com>
Tue, 21 Jul 2015 09:12:16 +0000 (17:12 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 28 Apr 2016 04:23:42 +0000 (04:23 +0000)
In order to use heap in cases which are not tied to a specific CPT,
memory allocation should support normal memory allocation. This
patch adds support for it.

Signed-off-by: Li Xi <lixi@ddn.com>
Change-Id: I1daeb76b708489b3adf09251fe1fbf2ddeab35aa
Reviewed-on: http://review.whamcloud.com/19317
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Nikitas Angelinas <nikitasangelinas@gmail.com>
Reviewed-by: Emoly Liu <emoly.liu@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
libcfs/libcfs/heap.c

index f784fb9..4efc4eb 100644 (file)
 
 #define CBH_ALLOC(ptr, h)                                              \
 do {                                                                   \
-       if ((h)->cbh_flags & CBH_FLAG_ATOMIC_GROW)                      \
-               LIBCFS_CPT_ALLOC_GFP((ptr), h->cbh_cptab, h->cbh_cptid, \
-                                    CBH_NOB, GFP_ATOMIC);              \
-       else                                                            \
-               LIBCFS_CPT_ALLOC((ptr), h->cbh_cptab, h->cbh_cptid,     \
-                                CBH_NOB);                              \
+       if (h->cbh_cptab) {                                             \
+               if ((h)->cbh_flags & CBH_FLAG_ATOMIC_GROW)              \
+                       LIBCFS_CPT_ALLOC_GFP((ptr), h->cbh_cptab,       \
+                                            h->cbh_cptid, CBH_NOB,     \
+                                            GFP_ATOMIC);               \
+               else                                                    \
+                       LIBCFS_CPT_ALLOC((ptr), h->cbh_cptab,           \
+                                        h->cbh_cptid, CBH_NOB);        \
+       } else {                                                        \
+               if ((h)->cbh_flags & CBH_FLAG_ATOMIC_GROW)              \
+                       LIBCFS_ALLOC_ATOMIC((ptr), CBH_NOB);            \
+               else                                                    \
+                       LIBCFS_ALLOC((ptr), CBH_NOB);                   \
+       }                                                               \
 } while (0)
 
 #define CBH_FREE(ptr)  LIBCFS_FREE(ptr, CBH_NOB)
@@ -164,12 +172,14 @@ cfs_binheap_create(struct cfs_binheap_ops *ops, unsigned int flags,
 
        LASSERT(ops != NULL);
        LASSERT(ops->hop_compare != NULL);
-       LASSERT(cptab != NULL);
-       LASSERT(cptid == CFS_CPT_ANY ||
-              (cptid >= 0 && cptid < cptab->ctb_nparts));
-
-       LIBCFS_CPT_ALLOC(h, cptab, cptid, sizeof(*h));
-       if (h == NULL)
+       if (cptab) {
+               LASSERT(cptid == CFS_CPT_ANY ||
+                      (cptid >= 0 && cptid < cptab->ctb_nparts));
+               LIBCFS_CPT_ALLOC(h, cptab, cptid, sizeof(*h));
+       } else {
+               LIBCFS_ALLOC(h, sizeof(*h));
+       }
+       if (!h)
                return NULL;
 
        h->cbh_ops        = ops;