util: Avoid waste space when linear alloc'ing large sizes
authorCaio Oliveira <caio.oliveira@intel.com>
Tue, 3 Oct 2023 06:24:51 +0000 (23:24 -0700)
committerMarge Bot <emma+marge@anholt.net>
Sun, 8 Oct 2023 00:55:20 +0000 (00:55 +0000)
commitc005b5a16f5a0e38840d03d419137d6c98090788
tree4db04a7bbe3d42b2d8665aaae80d33c27ec4cd9c
parent52721cfbe80a8e11b1ecb2fbe3e5a02769dc214b
util: Avoid waste space when linear alloc'ing large sizes

In the linear allocator, when a size larger than the minimum
buffer size is allocated, we currently create the new buffer
to fit exactly the requested size.

In that case, don't bother updating the `latest` pointer, since
this newly created buffer is already full.  In the worst case,
the current `latest` is full and it would be the same; in the
best case, there's still room for small allocations, so we avoid
wasting space if the next allocations would fit.

Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25517>
src/util/ralloc.c
src/util/tests/linear_test.cpp