[RFC] : SLAB : Could we have a process context only versions of kmem_cache_alloc(), and kmem_cache_free()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

The cost of local_irq_save(flags)/local_irq_restore(flags) in slab functions is very high
 popf, cli, pushf do stress the modern processors.

Maybe we could provide special functions for caches that are known to be used only from process context ?


These functions may use the local_irq_save(flags)/local_irq_restore(flags) only if needed (cache_alloc_refill() or cache_flusharray())

Something like :

void *kmem_cache_alloc_noirq(kmem_cache_t *cachep, unsigned int __nocast flags)
{
        unsigned long save_flags;
        void* objp;
        struct array_cache *ac;

        cache_alloc_debugcheck_before(cachep, flags);
	check_irq_on();
        preempt_disable();
        ac = ac_data(cachep);
        if (likely(ac->avail)) {
                STATS_INC_ALLOCHIT(cachep);
                ac->touched = 1;
                objp = ac_entry(ac)[--ac->avail];
        } else {
                STATS_INC_ALLOCMISS(cachep);
		local_irq_save(save_flags);
                objp = cache_alloc_refill(cachep, flags);
		local_irq_restore(save_flags);
        }
        preempt_enable();
        objp = cache_alloc_debugcheck_after(cachep, flags, objp, __builtin_return_address(0));
	prefetchw(objp);
        return objp;
}


void kmem_cache_free_noirq(kmem_cache_t *cachep, void *objp)
{
        struct array_cache *ac;

	check_irq_on();
	preempt_disable();
	ac  = ac_data(cachep);

        objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));

        if (likely(ac->avail < ac->limit)) {
                STATS_INC_FREEHIT(cachep);
        } else {
		unsigned long flags;
                STATS_INC_FREEMISS(cachep);
		local_irq_save(flags);
                cache_flusharray(cachep, ac);
		local_irq_restore(flags);
        }
        ac_entry(ac)[ac->avail++] = objp;
	preempt_disable();
}

Thank you

Eric Dumazet

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux