obd_support.h

来自「lustre 1.6.5 source code」· C头文件 代码 · 共 679 行 · 第 1/3 页

H
679
字号
                CERROR("kmalloc of '" #ptr "' (%d bytes) failed\n",           \                       (int)(size));                                          \        } else {                                                              \                memset(ptr, 0, size);                                         \                CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p\n",          \                       (int)(size), ptr);                                     \        }                                                                     \} while (0)#else /* this version is for the kernel and liblustre */#define OBD_FREE_RTN0(ptr)                                                    \({                                                                            \        cfs_free(ptr);                                                        \        (ptr) = NULL;                                                         \        0;                                                                    \})#define OBD_ALLOC_GFP(ptr, size, gfp_mask)                                    \do {                                                                          \        (ptr) = cfs_alloc(size, (gfp_mask));                                  \        if (likely((ptr) != NULL &&                                           \                   (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 ||       \                    !obd_alloc_fail(ptr, #ptr, "km", size,                    \                                    __FILE__, __LINE__) ||                    \                    OBD_FREE_RTN0(ptr)))){                                    \                memset(ptr, 0, size);                                         \                obd_memory_add(size);                                         \                CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p.\n",         \                       (int)(size), ptr);                                     \        }                                                                     \} while (0)#endif#ifndef OBD_ALLOC_MASK# define OBD_ALLOC_MASK CFS_ALLOC_IO#endif#define OBD_ALLOC(ptr, size) OBD_ALLOC_GFP(ptr, size, OBD_ALLOC_MASK)#define OBD_ALLOC_WAIT(ptr, size) OBD_ALLOC_GFP(ptr, size, CFS_ALLOC_STD)#define OBD_ALLOC_PTR(ptr) OBD_ALLOC(ptr, sizeof *(ptr))#define OBD_ALLOC_PTR_WAIT(ptr) OBD_ALLOC_WAIT(ptr, sizeof *(ptr))#ifdef __arch_um__# define OBD_VMALLOC(ptr, size) OBD_ALLOC(ptr, size)#else# define OBD_VMALLOC(ptr, size)                                               \do {                                                                          \        (ptr) = cfs_alloc_large(size);                                        \        if (unlikely((ptr) == NULL)) {                                        \                CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",           \                       (int)(size));                                          \                CERROR(LPU64" total bytes allocated by Lustre, %d by LNET\n", \                       obd_memory_sum(), atomic_read(&libcfs_kmemory));      \        } else {                                                              \                memset(ptr, 0, size);                                         \                obd_memory_add(size);                                         \                CDEBUG(D_MALLOC, "vmalloced '" #ptr "': %d at %p.\n",         \                       (int)(size), ptr);                                     \        }                                                                     \} while (0)#endif#ifdef CONFIG_DEBUG_SLAB#define POISON(ptr, c, s) do {} while (0)#else#define POISON(ptr, c, s) memset(ptr, c, s)#endif#ifdef POISON_BULK#define POISON_PAGE(page, val) do { memset(kmap(page), val, CFS_PAGE_SIZE);   \                                    kunmap(page); } while (0)#else#define POISON_PAGE(page, val) do { } while (0)#endif#ifdef __KERNEL__#define OBD_FREE(ptr, size)                                                   \do {                                                                          \        LASSERT(ptr);                                                         \        obd_memory_sub(size);                                                 \        CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p.\n",                    \               (int)(size), ptr);                                             \        POISON(ptr, 0x5a, size);                                              \        cfs_free(ptr);                                                        \        (ptr) = (void *)0xdeadbeef;                                           \} while (0)#ifdef HAVE_RCU# ifdef HAVE_CALL_RCU_PARAM#  define my_call_rcu(rcu, cb)            call_rcu(rcu, cb, rcu)# else#  define my_call_rcu(rcu, cb)            call_rcu(rcu, cb)# endif#else# define my_call_rcu(rcu, cb)             (cb)(rcu)#endif#define OBD_FREE_RCU_CB(ptr, size, handle, free_cb)                           \do {                                                                          \        struct portals_handle *__h = (handle);                                \        LASSERT(handle);                                                      \        __h->h_ptr = (ptr);                                                   \        __h->h_size = (size);                                                 \        __h->h_free_cb = (void (*)(void *, size_t))(free_cb);                 \        my_call_rcu(&__h->h_rcu, class_handle_free_cb);                       \        (ptr) = (void *)0xdeadbeef;                                           \} while(0)#define OBD_FREE_RCU(ptr, size, handle) OBD_FREE_RCU_CB(ptr, size, handle, NULL)#else#define OBD_FREE(ptr, size) ((void)(size), free((ptr)))#define OBD_FREE_RCU(ptr, size, handle) (OBD_FREE(ptr, size))#define OBD_FREE_RCU_CB(ptr, size, handle, cb)     ((*(cb))(ptr, size))#endif#ifdef __arch_um__# define OBD_VFREE(ptr, size) OBD_FREE(ptr, size)#else# define OBD_VFREE(ptr, size)                                                 \do {                                                                          \        LASSERT(ptr);                                                         \        obd_memory_sub(size);                                                 \        CDEBUG(D_MALLOC, "vfreed '" #ptr "': %d at %p.\n",                    \               (int)(size), ptr);                                             \        POISON(ptr, 0x5a, size);                                              \        cfs_free_large(ptr);                                                  \        (ptr) = (void *)0xdeadbeef;                                           \} while (0)#endif/* 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. */#define OBD_SLAB_FREE_RTN0(ptr, slab)                                         \({                                                                            \        cfs_mem_cache_free((slab), (ptr));                                    \        (ptr) = NULL;                                                         \        0;                                                                    \}) #define OBD_SLAB_ALLOC(ptr, slab, type, size)                                 \do {                                                                          \        LASSERT(!in_interrupt());                                             \        (ptr) = cfs_mem_cache_alloc(slab, (type));                            \        if (likely((ptr) != NULL &&                                           \                   (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 ||       \                    !obd_alloc_fail(ptr, #ptr, "slab-", size,                 \                                    __FILE__, __LINE__) ||                    \                    OBD_SLAB_FREE_RTN0(ptr, slab)))) {                        \                memset(ptr, 0, size);                                         \                obd_memory_add(size);                                         \                CDEBUG(D_MALLOC, "slab-alloced '"#ptr"': %d at %p.\n",        \                       (int)(size), ptr);                                     \        }                                                                     \} while (0)#define OBD_FREE_PTR(ptr) OBD_FREE(ptr, sizeof *(ptr))#define OBD_SLAB_FREE(ptr, slab, size)                                        \do {                                                                          \        LASSERT(ptr);                                                         \        CDEBUG(D_MALLOC, "slab-freed '" #ptr "': %d at %p.\n",                \               (int)(size), ptr);                                             \        obd_memory_sub(size);                                                 \        POISON(ptr, 0x5a, size);                                              \        cfs_mem_cache_free(slab, ptr);                                        \        (ptr) = (void *)0xdeadbeef;                                           \} while (0)#define OBD_SLAB_ALLOC_PTR(ptr, slab)                                         \        OBD_SLAB_ALLOC((ptr), (slab), CFS_ALLOC_STD, sizeof *(ptr))#define OBD_SLAB_FREE_PTR(ptr, slab)                                          \        OBD_SLAB_FREE((ptr), (slab), sizeof *(ptr))#define KEY_IS(str) (keylen >= strlen(str) && strcmp(key, str) == 0)/* Wrapper for contiguous page frame allocation */#define OBD_PAGES_ALLOC(ptr, order, gfp_mask)                                 \do {                                                                          \        (ptr) = cfs_alloc_pages(gfp_mask, order);                             \        if (unlikely((ptr) == NULL)) {                                        \                CERROR("alloc_pages of '" #ptr "' %d page(s) / "LPU64" bytes "\                       "failed\n", (int)(1 << (order)),                       \                       (__u64)((1 << (order)) << CFS_PAGE_SHIFT));            \                CERROR(LPU64" total bytes and "LPU64" total pages "           \                       "("LPU64" bytes) allocated by Lustre, "                \                       "%d total bytes by LNET\n",                            \                       obd_memory_sum(),                                      \                       obd_pages_sum() << CFS_PAGE_SHIFT,                     \                       obd_pages_sum(),                                       \                       atomic_read(&libcfs_kmemory));                         \        } else {                                                              \                obd_pages_add(order);                                         \                CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / "      \                       LPU64" bytes at %p.\n",                                \                       (int)(1 << (order)),                                   \                       (__u64)((1 << (order)) << CFS_PAGE_SHIFT), ptr);       \        }                                                                     \} while (0)#define OBD_PAGE_ALLOC(ptr, gfp_mask)                                         \        OBD_PAGES_ALLOC(ptr, 0, gfp_mask)#define OBD_PAGES_FREE(ptr, order)                                            \do {                                                                          \        LASSERT(ptr);                                                         \        obd_pages_sub(order);                                                 \        CDEBUG(D_MALLOC, "free_pages '" #ptr "': %d page(s) / "LPU64" bytes " \               "at %p.\n",                                                    \               (int)(1 << (order)), (__u64)((1 << (order)) << CFS_PAGE_SHIFT),\               ptr);                                                          \        __cfs_free_pages(ptr, order);                                         \        (ptr) = (void *)0xdeadbeef;                                           \} while (0)#define OBD_PAGE_FREE(ptr) OBD_PAGES_FREE(ptr, 0)#if defined(__linux__)#include <linux/obd_support.h>#elif defined(__APPLE__)#include <darwin/obd_support.h>#elif defined(__WINNT__)#include <winnt/obd_support.h>#else#error Unsupported operating system.#endif#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?