mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Try to avoid OOM killer on low-memory systems without swap.
Benchmark for memory-hard KDF is tricky, seems that relying on maximum half of physical memory is not enough. Let's allow only free physical available space if there is no swap. This should not cause changes on normal systems, at least.
This commit is contained in:
@@ -63,7 +63,7 @@ const struct crypt_pbkdf_type *crypt_get_pbkdf_type_params(const char *pbkdf_typ
|
||||
|
||||
static uint32_t adjusted_phys_memory(void)
|
||||
{
|
||||
uint64_t memory_kb = crypt_getphysmemory_kb();
|
||||
uint64_t free_kb, memory_kb = crypt_getphysmemory_kb();
|
||||
|
||||
/* Ignore bogus value */
|
||||
if (memory_kb < (128 * 1024) || memory_kb > UINT32_MAX)
|
||||
@@ -75,6 +75,15 @@ static uint32_t adjusted_phys_memory(void)
|
||||
*/
|
||||
memory_kb /= 2;
|
||||
|
||||
/*
|
||||
* Never use more that available free space on system without swap.
|
||||
*/
|
||||
if (!crypt_swapavailable()) {
|
||||
free_kb = crypt_getphysmemoryfree_kb();
|
||||
if (free_kb > (64 * 1024) && free_kb < memory_kb)
|
||||
return free_kb;
|
||||
}
|
||||
|
||||
return memory_kb;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user