Skip to content

Commit

Permalink
Preallocate memory for spl_kmem_alloc_t in spl_kmem_cache_t
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Yao <[email protected]>
  • Loading branch information
ryao committed Apr 11, 2014
1 parent 11f1c30 commit b56687c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/sys/kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ typedef struct spl_kmem_slab {
} spl_kmem_slab_t;

typedef struct spl_kmem_alloc {
struct spl_kmem_cache *ska_cache; /* Owned by cache */
int ska_flags; /* Allocation flags */
taskq_ent_t ska_tqe; /* Task queue entry */
} spl_kmem_alloc_t;
Expand Down Expand Up @@ -489,6 +488,7 @@ typedef struct spl_kmem_cache {
uint64_t skc_obj_deadlock; /* Obj emergency deadlocks */
uint64_t skc_obj_emergency; /* Obj emergency current */
uint64_t skc_obj_emergency_max; /* Obj emergency max */
spl_kmem_alloc_t skc_alloc; /* Memory for spl_cache_grow */
} spl_kmem_cache_t;
#define kmem_cache_t spl_kmem_cache_t

Expand Down
18 changes: 4 additions & 14 deletions module/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,8 +1741,8 @@ spl_cache_obj(spl_kmem_cache_t *skc, spl_kmem_slab_t *sks)
static void
spl_cache_grow_work(void *data)
{
spl_kmem_alloc_t *ska = (spl_kmem_alloc_t *)data;
spl_kmem_cache_t *skc = ska->ska_cache;
spl_kmem_cache_t *skc = (spl_kmem_cache_t *)data;
spl_kmem_alloc_t *ska = &skc->skc_alloc;
spl_kmem_slab_t *sks = NULL;

while (1) {
Expand All @@ -1763,8 +1763,6 @@ spl_cache_grow_work(void *data)
clear_bit(KMC_BIT_DEADLOCKED, &skc->skc_flags);
wake_up_all(&skc->skc_waitq);
spin_unlock(&skc->skc_lock);

kfree(ska);
}

/*
Expand Down Expand Up @@ -1813,21 +1811,13 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
* allocations to ensure forward progress is always maintained.
*/
if (test_and_set_bit(KMC_BIT_GROWING, &skc->skc_flags) == 0) {
spl_kmem_alloc_t *ska;

ska = kmalloc(sizeof(*ska), flags);
if (ska == NULL) {
clear_bit(KMC_BIT_GROWING, &skc->skc_flags);
wake_up_all(&skc->skc_waitq);
SRETURN(-ENOMEM);
}
spl_kmem_alloc_t *ska = &skc->skc_alloc;

atomic_inc(&skc->skc_ref);
ska->ska_cache = skc;
ska->ska_flags = flags & ~__GFP_NORETRY;
taskq_init_ent(&ska->ska_tqe);
taskq_dispatch_ent(spl_kmem_cache_taskq,
spl_cache_grow_work, ska, 0, &ska->ska_tqe);
spl_cache_grow_work, skc, 0, &ska->ska_tqe);
}

/*
Expand Down

0 comments on commit b56687c

Please sign in to comment.