Whamcloud - gitweb
LU-6587 mem: refactor OBD_ALLOC_LARGE marco 94/14994/9
authorYang Sheng <yang.sheng@intel.com>
Fri, 12 Jun 2015 15:32:47 +0000 (23:32 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 24 Jun 2015 02:23:47 +0000 (02:23 +0000)
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 <yang.sheng@intel.com>
Change-Id: I44a002fb855956bb0c4bea0f328679a5f56e4d49
Reviewed-on: http://review.whamcloud.com/14994
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
contrib/scripts/checkpatch.pl
lustre/include/obd_support.h
lustre/mdd/mdd_dir.c

index a68675b..f7695a5 100755 (executable)
@@ -459,6 +459,7 @@ my %dep_functions = (
        'strcpy',                       'strncpy',
        'strcat',                       'strncat',
        'tempnam',                      'mkstemp',
+       'OBD_FREE_LARGE',               'OBD_FREE',
 );
 
 my @rawlines = ();
index 621d263..e07e87d 100644 (file)
@@ -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. */
index 82f88e0..a6f7605 100644 (file)
@@ -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);