Allocate suitable sized buffer when reading a keyfile

If the keyfile size is explicitly given, then allocate a suitable sized
buffer right from the start instead of increasing it in 4k steps. This
speeds up reading larger keyfiles.
This commit is contained in:
angelomariafederichini191269@protonmail.com
2017-08-12 16:01:23 +02:00
committed by Milan Broz
parent 596e374313
commit e2fee206c2

View File

@@ -412,10 +412,11 @@ int crypt_keyfile_read(struct crypt_device *cd, const char *keyfile,
if (keyfile_size_max == 0) {
keyfile_size_max = DEFAULT_KEYFILE_SIZE_MAXKB * 1024 + 1;
unlimited_read = 1;
}
/* use 4k for buffer (page divisor but avoid huge pages) */
buflen = 4096 - sizeof(struct safe_allocation);
} else
buflen = keyfile_size_max;
/* use 4k for buffer (page divisor but avoid huge pages) */
buflen = 4096 - sizeof(struct safe_allocation);
regular_file = 0;
if (keyfile) {
if (stat(keyfile, &st) < 0) {