mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Use only half of detected free memory on systems without swap.
As tests shows, limiting used Argon2 memory to free memory on systems without swap is still not enough. Use just half of it, this should bring needed margin while still use Argon2. Note, for very-low memory constrained systems user should avoid memory-hard PBKDF (IOW manually select PBKDF2), we do not do this automatically.
This commit is contained in:
@@ -76,10 +76,17 @@ uint32_t pbkdf_adjusted_phys_memory_kb(void)
|
||||
memory_kb /= 2;
|
||||
|
||||
/*
|
||||
* Never use more that available free space on system without swap.
|
||||
* Never use more that half of available free memory on system without swap.
|
||||
*/
|
||||
if (!crypt_swapavailable()) {
|
||||
free_kb = crypt_getphysmemoryfree_kb();
|
||||
|
||||
/*
|
||||
* Using exactly free memory causes OOM too, use only half of the value.
|
||||
* Ignore small values (< 64MB), user should use PBKDF2 in such environment.
|
||||
*/
|
||||
free_kb /= 2;
|
||||
|
||||
if (free_kb > (64 * 1024) && free_kb < memory_kb)
|
||||
return free_kb;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user