[git commit] libbb/yescrypt: madvise(MADV_HUGEPAGE) our usually very large allocation
Denys Vlasenko
vda.linux at googlemail.com
Mon Jul 7 21:07:58 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
Nearly ~2 faster run when buffer is gigabytes in size
function old new delta
yescrypt_kdf32_body 1386 1406 +20
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
libbb/yescrypt/alg-yescrypt-kdf.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libbb/yescrypt/alg-yescrypt-kdf.c b/libbb/yescrypt/alg-yescrypt-kdf.c
index ab095eae1..4c2cfe849 100644
--- a/libbb/yescrypt/alg-yescrypt-kdf.c
+++ b/libbb/yescrypt/alg-yescrypt-kdf.c
@@ -832,14 +832,25 @@ static void smix(uint8_t *B, size_t r, uint32_t N, uint32_t p, uint32_t t,
static void alloc_region(yescrypt_region_t *region, size_t size)
{
+ uint8_t *base;
int flags =
# ifdef MAP_NOCORE /* huh? */
MAP_NOCORE |
# endif
MAP_ANON | MAP_PRIVATE;
- uint8_t *base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+
+ base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
if (base == MAP_FAILED)
bb_die_memory_exhausted();
+
+#if defined(MADV_HUGEPAGE)
+ /* Reduces mkpasswd qweRTY123 at -+ '$y$jHT$123'
+ * (which allocates 4 Gbytes)
+ * run time from 10.543s to 5.635s
+ * Seen on linux-5.18.0.
+ */
+ madvise(base, size, MADV_HUGEPAGE);
+#endif
//region->base = base;
//region->base_size = size;
region->aligned = base;
@@ -960,7 +971,7 @@ static int yescrypt_kdf32_body(
if (yctx->local->aligned_size < need) {
free_region(yctx->local);
alloc_region(yctx->local, need);
- dbg("allocated local:%u 0x%x", need, need);
+ dbg("allocated local:%lu 0x%lx", (long)need, (long)need);
/* standard "j9T" params allocate 16Mbytes here */
}
if (flags & YESCRYPT_ALLOC_ONLY)
More information about the busybox-cvs
mailing list