From cbe5b45a1d157c7345bd1352c257bee22ad8d085 Mon Sep 17 00:00:00 2001 From: Li Xi Date: Tue, 21 Jul 2015 17:12:16 +0800 Subject: [PATCH] LU-7982 libcfs: memory allocation without CPT for binheap 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 Change-Id: I1daeb76b708489b3adf09251fe1fbf2ddeab35aa Reviewed-on: http://review.whamcloud.com/19317 Tested-by: Jenkins Reviewed-by: Andreas Dilger Reviewed-by: Nikitas Angelinas Reviewed-by: Emoly Liu Tested-by: Maloo Reviewed-by: James Simmons --- libcfs/libcfs/heap.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libcfs/libcfs/heap.c b/libcfs/libcfs/heap.c index f784fb9..4efc4eb 100644 --- a/libcfs/libcfs/heap.c +++ b/libcfs/libcfs/heap.c @@ -39,12 +39,20 @@ #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; -- 1.8.3.1