diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-07-07 23:07:58 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-07-07 23:07:58 +0200 |
| commit | 8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30 (patch) | |
| tree | 7e3a397471980a02e053f93289d6c956bc05597b /libbb | |
| parent | f8e9bd30d73f2acf6818da71a2ba44748151b716 (diff) | |
| download | busybox-w32-8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30.tar.gz busybox-w32-8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30.tar.bz2 busybox-w32-8466c3e78fa10d1a3e2bf1a75657fd6d1f4aec30.zip | |
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')
| -rw-r--r-- | libbb/yescrypt/alg-yescrypt-kdf.c | 15 |
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, | |||
| 832 | 832 | ||
| 833 | static void alloc_region(yescrypt_region_t *region, size_t size) | 833 | static void alloc_region(yescrypt_region_t *region, size_t size) |
| 834 | { | 834 | { |
| 835 | uint8_t *base; | ||
| 835 | int flags = | 836 | int flags = |
| 836 | # ifdef MAP_NOCORE /* huh? */ | 837 | # ifdef MAP_NOCORE /* huh? */ |
| 837 | MAP_NOCORE | | 838 | MAP_NOCORE | |
| 838 | # endif | 839 | # endif |
| 839 | MAP_ANON | MAP_PRIVATE; | 840 | MAP_ANON | MAP_PRIVATE; |
| 840 | uint8_t *base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); | 841 | |
| 842 | base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); | ||
| 841 | if (base == MAP_FAILED) | 843 | if (base == MAP_FAILED) |
| 842 | bb_die_memory_exhausted(); | 844 | bb_die_memory_exhausted(); |
| 845 | |||
| 846 | #if defined(MADV_HUGEPAGE) | ||
| 847 | /* Reduces mkpasswd qweRTY123@-+ '$y$jHT$123' | ||
| 848 | * (which allocates 4 Gbytes) | ||
| 849 | * run time from 10.543s to 5.635s | ||
| 850 | * Seen on linux-5.18.0. | ||
| 851 | */ | ||
| 852 | madvise(base, size, MADV_HUGEPAGE); | ||
| 853 | #endif | ||
| 843 | //region->base = base; | 854 | //region->base = base; |
| 844 | //region->base_size = size; | 855 | //region->base_size = size; |
| 845 | region->aligned = base; | 856 | region->aligned = base; |
| @@ -960,7 +971,7 @@ static int yescrypt_kdf32_body( | |||
| 960 | if (yctx->local->aligned_size < need) { | 971 | if (yctx->local->aligned_size < need) { |
| 961 | free_region(yctx->local); | 972 | free_region(yctx->local); |
| 962 | alloc_region(yctx->local, need); | 973 | alloc_region(yctx->local, need); |
| 963 | dbg("allocated local:%u 0x%x", need, need); | 974 | dbg("allocated local:%lu 0x%lx", (long)need, (long)need); |
| 964 | /* standard "j9T" params allocate 16Mbytes here */ | 975 | /* standard "j9T" params allocate 16Mbytes here */ |
| 965 | } | 976 | } |
| 966 | if (flags & YESCRYPT_ALLOC_ONLY) | 977 | if (flags & YESCRYPT_ALLOC_ONLY) |
