Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Feb 2008 06:36:56 +1100
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Alexander Motin <mav@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, freebsd-performance@freebsd.org
Subject:   Re: Memory allocation performance
Message-ID:  <20080202193656.GR35170@server.vk2pj.dyndns.org>
In-Reply-To: <47A43873.40801@FreeBSD.org>
References:  <47A25412.3010301@FreeBSD.org> <47A25A0D.2080508@elischer.org> <47A2C2A2.5040109@FreeBSD.org> <20080201185435.X88034@fledge.watson.org> <47A43873.40801@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
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.

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFHpMZY/opHv/APuIcRAjX8AJ9Tr3OIDEmNTcd6GFUNOG8/5JOt9wCfTaXz
zXwtwl46hYGVRmJI8P2gfXw=
=urmE
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080202193656.GR35170>