};
struct slub_percpu_sheaves {
- local_lock_t lock;
+ localtry_lock_t lock;
struct slab_sheaf *main; /* never NULL when unlocked */
struct slab_sheaf *spare; /* empty or full, may be NULL */
struct slab_sheaf *rcu_free;
static void __kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p);
-static void sheaf_flush_main(struct kmem_cache *s)
+/* returns true if at least partially flushed */
+static bool sheaf_flush_main(struct kmem_cache *s)
{
struct slub_percpu_sheaves *pcs;
unsigned int batch, remaining;
void *objects[PCS_BATCH_MAX];
struct slab_sheaf *sheaf;
- unsigned long flags;
+ bool ret = false;
next_batch:
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ return ret;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
sheaf = pcs->main;
remaining = sheaf->size;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
__kmem_cache_free_bulk(s, batch, &objects[0]);
stat_add(s, SHEAF_FLUSH_MAIN, batch);
+ ret = true;
+
if (remaining)
goto next_batch;
+
+ return ret;
}
static void sheaf_flush(struct kmem_cache *s, struct slab_sheaf *sheaf)
* Caller needs to make sure migration is disabled in order to fully flush
* single cpu's sheaves
*
+ * must not be called from an irq
+ *
* flushing operations are rare so let's keep it simple and flush to slabs
* directly, skipping the barn
*/
{
struct slub_percpu_sheaves *pcs;
struct slab_sheaf *spare, *rcu_free;
- unsigned long flags;
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ localtry_lock(&s->cpu_sheaves->lock);
pcs = this_cpu_ptr(s->cpu_sheaves);
spare = pcs->spare;
rcu_free = pcs->rcu_free;
pcs->rcu_free = NULL;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
if (spare) {
sheaf_flush(s, spare);
void *alloc_from_pcs(struct kmem_cache *s, gfp_t gfp)
{
struct slub_percpu_sheaves *pcs;
- unsigned long flags;
void *object;
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ return NULL;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->main->size == 0)) {
}
}
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
if (!can_alloc)
return NULL;
if (!full)
return NULL;
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ /*
+ * we can reach here only when gfpflags_allow_blocking
+ * so this must not be an irq
+ */
+ localtry_lock(&s->cpu_sheaves->lock);
pcs = this_cpu_ptr(s->cpu_sheaves);
/*
do_alloc:
object = pcs->main->objects[--pcs->main->size];
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
stat(s, ALLOC_PCS);
{
struct slub_percpu_sheaves *pcs;
struct slab_sheaf *main;
- unsigned long flags;
unsigned int allocated = 0;
unsigned int batch;
next_batch:
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ return allocated;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->main->size == 0)) {
goto do_alloc;
}
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
/*
* Once full sheaves in barn are depleted, let the bulk
main->size -= batch;
memcpy(p, main->objects + main->size, batch * sizeof(void *));
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
stat_add(s, ALLOC_PCS, batch);
* The object is expected to have passed slab_free_hook() already.
*/
static __fastpath_inline
-void free_to_pcs(struct kmem_cache *s, void *object)
+bool free_to_pcs(struct kmem_cache *s, void *object)
{
struct slub_percpu_sheaves *pcs;
- unsigned long flags;
restart:
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ return false;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->main->size == s->sheaf_capacity)) {
struct slab_sheaf *to_flush = pcs->spare;
pcs->spare = NULL;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
sheaf_flush(s, to_flush);
empty = to_flush;
}
alloc_empty:
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
empty = alloc_empty_sheaf(s, GFP_NOWAIT);
if (!empty) {
- sheaf_flush_main(s);
- goto restart;
+ if (sheaf_flush_main(s))
+ goto restart;
+ else
+ return false;
}
got_empty:
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock)) {
+ struct node_barn *barn;
+
+ barn = get_node(s, numa_mem_id())->barn;
+
+ barn_put_empty_sheaf(barn, empty, true);
+ return false;
+ }
+
pcs = this_cpu_ptr(s->cpu_sheaves);
/*
do_free:
pcs->main->objects[pcs->main->size++] = object;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
stat(s, FREE_PCS);
+
+ return true;
}
static void __rcu_free_sheaf_prepare(struct kmem_cache *s,
{
struct slub_percpu_sheaves *pcs;
struct slab_sheaf *rcu_sheaf;
- unsigned long flags;
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ goto fail;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(!pcs->rcu_free)) {
goto do_free;
}
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
empty = alloc_empty_sheaf(s, GFP_NOWAIT);
- if (!empty) {
- stat(s, FREE_RCU_SHEAF_FAIL);
- return false;
- }
+ if (!empty)
+ goto fail;
+
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ goto fail;
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->rcu_free))
rcu_sheaf->objects[rcu_sheaf->size++] = obj;
if (likely(rcu_sheaf->size < s->sheaf_capacity)) {
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
stat(s, FREE_RCU_SHEAF);
return true;
}
pcs->rcu_free = NULL;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
call_rcu(&rcu_sheaf->rcu_head, rcu_free_sheaf);
stat(s, FREE_RCU_SHEAF);
-
return true;
+
+fail:
+ stat(s, FREE_RCU_SHEAF_FAIL);
+ return false;
}
/*
{
struct slub_percpu_sheaves *pcs;
struct slab_sheaf *main;
- unsigned long flags;
unsigned int batch, i = 0;
bool init;
}
next_batch:
- local_lock_irqsave(&s->cpu_sheaves->lock, flags);
+ if (!localtry_trylock(&s->cpu_sheaves->lock))
+ goto fallback;
+
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->main->size == s->sheaf_capacity)) {
}
no_empty:
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
/*
* if we depleted all empty sheaves in the barn or there are too
* many full sheaves, free the rest to slab pages
*/
-
+fallback:
__kmem_cache_free_bulk(s, size, p);
return;
}
memcpy(main->objects + main->size, p, batch * sizeof(void *));
main->size += batch;
- local_unlock_irqrestore(&s->cpu_sheaves->lock, flags);
+ localtry_unlock(&s->cpu_sheaves->lock);
stat_add(s, FREE_PCS, batch);
if (unlikely(!slab_free_hook(s, object, slab_want_init_on_free(s), false)))
return;
- if (s->cpu_sheaves)
- free_to_pcs(s, object);
- else
+ if (!s->cpu_sheaves || !free_to_pcs(s, object))
do_slab_free(s, slab, object, object, 1, addr);
}
pcs = per_cpu_ptr(s->cpu_sheaves, cpu);
- local_lock_init(&pcs->lock);
+ localtry_lock_init(&pcs->lock);
nid = cpu_to_mem(cpu);