Check for physical memory available also in PBKDF benchmark.

This commit is contained in:
Milan Broz
2023-04-03 13:31:16 +02:00
parent 23dd988545
commit 7893c33d71
3 changed files with 12 additions and 2 deletions

View File

@@ -89,6 +89,7 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd,
struct crypt_pbkdf_type *pbkdf,
size_t volume_key_size);
const char *crypt_get_cipher_spec(struct crypt_device *cd);
uint32_t pbkdf_adjusted_phys_memory_kb(void);
/* Device backend */
struct device;

View File

@@ -101,6 +101,7 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd,
{
int r, priority;
const char *kdf_opt;
uint32_t memory_kb;
if (!pbkdf || (!password && password_size))
return -EINVAL;
@@ -113,6 +114,14 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd,
log_dbg(cd, "Running %s(%s) benchmark.", pbkdf->type, kdf_opt);
memory_kb = pbkdf_adjusted_phys_memory_kb();
if (memory_kb < pbkdf->max_memory_kb) {
log_dbg(cd, "Not enough physical memory detected, "
"PBKDF max memory decreased from %dkB to %dkB.",
pbkdf->max_memory_kb, memory_kb);
pbkdf->max_memory_kb = memory_kb;
}
crypt_process_priority(cd, &priority, true);
r = crypt_pbkdf_perf(pbkdf->type, pbkdf->hash, password, password_size,
salt, salt_size, volume_key_size, pbkdf->time_ms,

View File

@@ -61,7 +61,7 @@ const struct crypt_pbkdf_type *crypt_get_pbkdf_type_params(const char *pbkdf_typ
return NULL;
}
static uint32_t adjusted_phys_memory(void)
uint32_t pbkdf_adjusted_phys_memory_kb(void)
{
uint64_t free_kb, memory_kb = crypt_getphysmemory_kb();
@@ -258,7 +258,7 @@ int init_pbkdf_type(struct crypt_device *cd,
}
if (cd_pbkdf->max_memory_kb) {
memory_kb = adjusted_phys_memory();
memory_kb = pbkdf_adjusted_phys_memory_kb();
if (cd_pbkdf->max_memory_kb > memory_kb) {
log_dbg(cd, "Not enough physical memory detected, "
"PBKDF max memory decreased from %dkB to %dkB.",