--n/aVsWSeQ4JHkrmm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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 m=
y=20
>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 =3D uma_zalloc(ng_qzone, wait | M_ZERO);
>+ mtx_lock_spin(&itemcachemtx);
>+ item =3D itemcache;
>+ itemcache =3D NULL;
>+ mtx_unlock_spin(&itemcachemtx);
=3D item =3D atomic_readandclear_ptr(&itemcache);
>+ if (item =3D=3D NULL)
>+ item =3D uma_zalloc(ng_qzone, wait | M_ZERO);
>+ else
>+ bzero(item, sizeof(*item));
>.....free.....
>- uma_zfree(ng_qzone, item);
>+ mtx_lock_spin(&itemcachemtx);
>+ if (itemcache =3D=3D NULL) {
>+ itemcache =3D item;
>+ item =3D NULL;
>+ }
>+ mtx_unlock_spin(&itemcachemtx);
>+ if (item)
>+ uma_zfree(ng_qzone, item);
=3D if (atomic_cmpset_ptr(&itemcache, NULL, item) =3D=3D 0)
=3D uma_zfree(ng_qzone, item);
--=20
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.
--n/aVsWSeQ4JHkrmm
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)
iD8DBQFHpMZY/opHv/APuIcRAjX8AJ9Tr3OIDEmNTcd6GFUNOG8/5JOt9wCfTaXz
zXwtwl46hYGVRmJI8P2gfXw=
=urmE
-----END PGP SIGNATURE-----
--n/aVsWSeQ4JHkrmm--