From cb5c2acebb86da5b50f099b39209d22845eda8c7 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 7 Sep 2012 14:24:17 -0700 Subject: [PATCH] Add KMC_NOEMERGENCY slab flag Provide a flag to disable the use of emergency objects for a specific kmem cache. There may be instances where under no circumstances should you kmalloc() an emergency object. For example, when you cache contains very large objects (>128k). Signed-off-by: Brian Behlendorf --- include/sys/kmem.h | 2 ++ module/spl/spl-kmem.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/sys/kmem.h b/include/sys/kmem.h index 116d6db0d..0149e754c 100644 --- a/include/sys/kmem.h +++ b/include/sys/kmem.h @@ -340,6 +340,7 @@ enum { KMC_BIT_KMEM = 5, /* Use kmem cache */ KMC_BIT_VMEM = 6, /* Use vmem cache */ KMC_BIT_OFFSLAB = 7, /* Objects not on slab */ + KMC_BIT_NOEMERGENCY = 8, /* Disable emergency objects */ KMC_BIT_GROWING = 15, /* Growing in progress */ KMC_BIT_REAPING = 16, /* Reaping in progress */ KMC_BIT_DESTROY = 17, /* Destroy in progress */ @@ -365,6 +366,7 @@ typedef enum kmem_cbrc { #define KMC_KMEM (1 << KMC_BIT_KMEM) #define KMC_VMEM (1 << KMC_BIT_VMEM) #define KMC_OFFSLAB (1 << KMC_BIT_OFFSLAB) +#define KMC_NOEMERGENCY (1 << KMC_BIT_NOEMERGENCY) #define KMC_GROWING (1 << KMC_BIT_GROWING) #define KMC_REAPING (1 << KMC_BIT_REAPING) #define KMC_DESTROY (1 << KMC_BIT_DESTROY) diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c index e07e08c91..eca809c47 100644 --- a/module/spl/spl-kmem.c +++ b/module/spl/spl-kmem.c @@ -1727,8 +1727,13 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj) */ remaining = wait_event_timeout(skc->skc_waitq, spl_cache_grow_wait(skc), 1); - if (remaining == 0) - rc = spl_emergency_alloc(skc, flags, obj); + + if (remaining == 0) { + if (test_bit(KMC_BIT_NOEMERGENCY, &skc->skc_flags)) + rc = -ENOMEM; + else + rc = spl_emergency_alloc(skc, flags, obj); + } SRETURN(rc); }