On Sat, Feb 02, 2008 at 11:31:31AM +0200, Alexander Motin wrote: >To check UMA dependency I have made a trivial one-element cache which in my >test case allows to avoid two for four allocations per packet.
You should be able to implement this lockless using atomic(9). I haven't verified it, but the following should work. >.....alloc..... >- item = uma_zalloc(ng_qzone, wait | M_ZERO); >+ mtx_lock_spin(&itemcachemtx); >+ item = itemcache; >+ itemcache = NULL; >+ mtx_unlock_spin(&itemcachemtx); = item = atomic_readandclear_ptr(&itemcache); >+ if (item == NULL) >+ item = uma_zalloc(ng_qzone, wait | M_ZERO); >+ else >+ bzero(item, sizeof(*item)); >.....free..... >- uma_zfree(ng_qzone, item); >+ mtx_lock_spin(&itemcachemtx); >+ if (itemcache == NULL) { >+ itemcache = item; >+ item = NULL; >+ } >+ mtx_unlock_spin(&itemcachemtx); >+ if (item) >+ uma_zfree(ng_qzone, item); = if (atomic_cmpset_ptr(&itemcache, NULL, item) == 0) = uma_zfree(ng_qzone, item); -- Peter Jeremy Please excuse any delays as the result of my ISP's inability to implement an MTA that is either RFC2821-compliant or matches their claimed behaviour.
pgpi9wVwsTfGA.pgp
Description: PGP signature