From 919b85d796f845ec3e6633702dda1639a3d86176 Mon Sep 17 00:00:00 2001 From: Yang Sheng Date: Fri, 12 Jun 2015 23:32:47 +0800 Subject: [PATCH] LU-6587 mem: refactor OBD_ALLOC_LARGE marco Always try kmalloc first if that fails then retry with vmalloc. Change checkpach.pl to indicate the OBD_FREE_LARGE has deprecated. since it hasn't any special meaning anymore and just using OBD_FREE instead of. Signed-off-by: Yang Sheng Change-Id: I44a002fb855956bb0c4bea0f328679a5f56e4d49 Reviewed-on: http://review.whamcloud.com/14994 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- contrib/scripts/checkpatch.pl | 1 + lustre/include/obd_support.h | 46 ++++++++++++------------------------------- lustre/mdd/mdd_dir.c | 6 +++--- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/contrib/scripts/checkpatch.pl b/contrib/scripts/checkpatch.pl index a68675b..f7695a5 100755 --- a/contrib/scripts/checkpatch.pl +++ b/contrib/scripts/checkpatch.pl @@ -459,6 +459,7 @@ my %dep_functions = ( 'strcpy', 'strncpy', 'strcat', 'strncat', 'tempnam', 'mkstemp', + 'OBD_FREE_LARGE', 'OBD_FREE', ); my @rawlines = (); diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index 621d263..e07e87d 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -773,38 +773,21 @@ do { \ #define OBD_CPT_VMALLOC(ptr, cptab, cpt, size) \ __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size) -/* Allocations above this size are considered too big and could not be done - * atomically. - * - * Be very careful when changing this value, especially when decreasing it, - * since vmalloc in Linux doesn't perform well on multi-cores system, calling - * vmalloc in critical path would hurt performance badly. See LU-66. - */ -#define OBD_ALLOC_BIG (4 * PAGE_CACHE_SIZE) - #define OBD_ALLOC_LARGE(ptr, size) \ do { \ - if (size > OBD_ALLOC_BIG) \ + OBD_ALLOC_GFP(ptr, size, GFP_NOFS | __GFP_NOWARN); \ + if (ptr == NULL) \ OBD_VMALLOC(ptr, size); \ - else \ - OBD_ALLOC(ptr, size); \ } while (0) #define OBD_CPT_ALLOC_LARGE(ptr, cptab, cpt, size) \ do { \ - if (size > OBD_ALLOC_BIG) \ + OBD_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS | __GFP_NOWARN); \ + if (ptr == NULL) \ OBD_CPT_VMALLOC(ptr, cptab, cpt, size); \ - else \ - OBD_CPT_ALLOC(ptr, cptab, cpt, size); \ } while (0) -#define OBD_FREE_LARGE(ptr, size) \ -do { \ - if (size > OBD_ALLOC_BIG) \ - OBD_VFREE(ptr, size); \ - else \ - OBD_FREE(ptr, size); \ -} while (0) +#define OBD_FREE_LARGE(ptr, size) OBD_FREE(ptr, size) #ifdef CONFIG_DEBUG_SLAB #define POISON(ptr, c, s) do {} while (0) @@ -823,12 +806,16 @@ do { \ #define OBD_FREE(ptr, size) \ do { \ - OBD_FREE_PRE(ptr, size, "kfreed"); \ - kfree(ptr); \ - POISON_PTR(ptr); \ + if (is_vmalloc_addr(ptr)) { \ + OBD_FREE_PRE(ptr, size, "vfreed"); \ + vfree(ptr); \ + } else { \ + OBD_FREE_PRE(ptr, size, "kfreed"); \ + kfree(ptr); \ + } \ + POISON_PTR(ptr); \ } while(0) - #define OBD_FREE_RCU(ptr, size, handle) \ do { \ struct portals_handle *__h = (handle); \ @@ -840,13 +827,6 @@ do { \ POISON_PTR(ptr); \ } while(0) -#define OBD_VFREE(ptr, size) \ - do { \ - OBD_FREE_PRE(ptr, size, "vfreed"); \ - vfree(ptr); \ - POISON_PTR(ptr); \ - } while (0) - /* we memset() the slab object to 0 when allocation succeeds, so DO NOT * HAVE A CTOR THAT DOES ANYTHING. its work will be cleared here. we'd * love to assert on that, but slab.c keeps kmem_cache_s all to itself. */ diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 82f88e0..a6f7605 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -1064,7 +1064,7 @@ out: rc, PFID(mdd_object_fid(mdd_obj))); } - if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG) + if (is_vmalloc_addr(ldata->ld_buf)) /* if we vmalloced a large buffer drop it */ lu_buf_free(ldata->ld_buf); @@ -1397,7 +1397,7 @@ out_unlock: stop: mdd_trans_stop(env, mdd, rc, handle); - if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG) + if (is_vmalloc_addr(ldata->ld_buf)) /* if we vmalloced a large buffer drop it */ lu_buf_free(ldata->ld_buf); out_pending: @@ -2479,7 +2479,7 @@ out_stop: if (rc == 0) rc = rc2; out_free: - if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG) + if (is_vmalloc_addr(ldata->ld_buf)) /* if we vmalloced a large buffer drop it */ lu_buf_free(ldata->ld_buf); -- 1.8.3.1