util/disk_cache: use posix_fallocate() for index files

ftruncate() allocates disk space lazily. If the disk is full and it is
unable to allocate disk space when accesed via mmap(), it will crash
with a SIGBUS.

Switch to posix_fallocate(), which ensures disk space is allocated
otherwise it fails if there isn't enough disk space. The disk cache
won't be enabled in this case.

For normal cases, a small increase in disk usage as the 1.3MB index
file will be fully allocated when initialized now.

fallback to ftruncate() if posix_fallocate() isn't found.

Signed-off-by: Juston Li <justonli@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22097>
This commit is contained in:
Juston Li
2023-03-23 13:06:55 -07:00
committed by Marge Bot
parent ba670f0cdf
commit 88d074cb8f
2 changed files with 13 additions and 0 deletions

View File

@@ -1277,6 +1277,7 @@ functions_to_detect = {
'strtok_r': '',
'getrandom': '',
'qsort_s': '',
'posix_fallocate': '',
}
foreach f, prefix: functions_to_detect