summaryrefslogtreecommitdiff
path: root/libbb/yescrypt
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-07-07 23:07:58 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-07-07 23:07:58 +0200
commit8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30 (patch)
tree7e3a397471980a02e053f93289d6c956bc05597b /libbb/yescrypt
parentf8e9bd30d73f2acf6818da71a2ba44748151b716 (diff)
libbb/yescrypt: madvise(MADV_HUGEPAGE) our usually very large allocation
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@googlemail.com>
Diffstat (limited to 'libbb/yescrypt')
-rw-r--r--libbb/yescrypt/alg-yescrypt-kdf.c15
1 files 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@-+ '$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)