]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
contrib/ucw/mempool: include chunk metadata in requested size
authorLukáš Ondráček <lukas.ondracek@nic.cz>
Tue, 9 Jun 2026 14:17:56 +0000 (16:17 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 8 Jul 2026 11:38:26 +0000 (13:38 +0200)
Originally, the requested chunk size was enlarged by the size of its metadata (~16 B)
and then in mmap version of mempools it was rounded up to the page size.
As the requested size itself is usually rounded to whole pages,
the chunk size was roughly by one page larger than expected;
still the whole space could have been used by mempools.

In non-mmap version (not used here), the effect might have been even worse,
as the rounding may be involved on the allocator level
and so the excessive memory cannot be used by mempools.

Now, usable size of chunks is a little smaller than requested,
but allocated area size corresponds to what was requested.

src/contrib/ucw/mempool.c

index 5daef642395829baa8ade5cf5e037f57162814c0..cb636b24eed0fb2c7c9935b66480c2f82a87c130 100644 (file)
@@ -71,10 +71,11 @@ struct mempool_chunk {
 static size_t
 mp_align_size(size_t size)
 {
+       size = MAX(size, 64 + MP_CHUNK_TAIL);
 #ifdef CONFIG_UCW_POOL_IS_MMAP
-       return ALIGN_TO(size + MP_CHUNK_TAIL, CPU_PAGE_SIZE) - MP_CHUNK_TAIL;
+       return ALIGN_TO(size, CPU_PAGE_SIZE) - MP_CHUNK_TAIL;
 #else
-       return ALIGN_TO(size, CPU_STRUCT_ALIGN);
+       return ALIGN_TO(size, CPU_STRUCT_ALIGN) - MP_CHUNK_TAIL;
 #endif
 }