[Support] Revert posix_fallocate in resize_file

This reverts 3816c53f04 and removes follow-up
fixups.

The original intention was to show error earlier (posix_fallocate time) than
later for ld.lld but it appears to cause some problems which make it not free.

* FreeBSD ZFS: EINVAL, not too bad.
* FreeBSD UFS: according to khng "devastatingly slow on freebsd because UFS on freebsd does not have preallocation support like illumos. It zero-fills."
* NetBSD: maybe EOPNOTSUPP
* Linux tmpfs: unless tmpfs is set up to use huge pages (requires CONFIG_TRANSPARENT_HUGE_PAGECACHE=y), I can consistently demonstrate ~300ms delay for a 1.4GiB output.
* Linux ext4: I don't measure any benefit, either backed by a hard disk or by a file in tmpfs.
* The current code organization of `defined(HAVE_POSIX_FALLOCATE)` costs us a macro dispatch for AIX.

I think we should just remove it. I think if posix_fallocate ever finds demonstrable benefit,
it is likely Linux specific and will not need HAVE_POSIX_FALLOCATE, and possibly opt-in by some specific programs.

In a filesystem with CoW and compression, the ENOSPC benefit may be lost as well.

Reviewed By: khng300

Differential Revision: https://reviews.llvm.org/D115957
This commit is contained in:
Fangrui Song 2021-12-20 11:16:03 -08:00
parent e96e3912c9
commit 98e0b2cf70
7 changed files with 0 additions and 26 deletions

View File

@ -243,7 +243,6 @@ check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
check_symbol_exists(isatty unistd.h HAVE_ISATTY)
check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
# AddressSanitizer conflicts with lib/Support/Unix/Signals.inc
# Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it
# (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind

View File

@ -152,9 +152,6 @@
/* Define to 1 if you have the `malloc_zone_statistics' function. */
#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS}
/* Define to 1 if you have the `posix_fallocate' function. */
#cmakedefine HAVE_POSIX_FALLOCATE ${HAVE_POSIX_FALLOCATE}
/* Define to 1 if you have the `posix_spawn' function. */
#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN}

View File

@ -590,19 +590,6 @@ std::error_code rename(const Twine &from, const Twine &to) {
}
std::error_code resize_file(int FD, uint64_t Size) {
#if defined(HAVE_POSIX_FALLOCATE)
// If we have posix_fallocate use it. Unlike ftruncate it always allocates
// space, so we get an error if the disk is full.
if (int Err = ::posix_fallocate(FD, 0, Size)) {
#ifdef _AIX
constexpr int NotSupportedError = ENOTSUP;
#else
constexpr int NotSupportedError = EOPNOTSUPP;
#endif
if (Err != EINVAL && Err != NotSupportedError)
return std::error_code(Err, std::generic_category());
}
#endif
// Use ftruncate as a fallback. It may or may not allocate space. At least on
// OS X with HFS+ it does.
if (::ftruncate(FD, Size) == -1)

View File

@ -143,7 +143,6 @@ write_cmake_config("config") {
"HAVE_LINK_H=1",
"HAVE_LSEEK64=1",
"HAVE_MALLINFO=1",
"HAVE_POSIX_FALLOCATE=1",
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
]
} else {
@ -152,7 +151,6 @@ write_cmake_config("config") {
"HAVE_LINK_H=",
"HAVE_LSEEK64=",
"HAVE_MALLINFO=",
"HAVE_POSIX_FALLOCATE=",
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=",
]
}

View File

@ -43,7 +43,6 @@ linux_defines = posix_defines + [
"HAVE_LINK_H=1",
"HAVE_LSEEK64=1",
"HAVE_MALLINFO=1",
"HAVE_POSIX_FALLOCATE=1",
"HAVE_SBRK=1",
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
]

View File

@ -165,9 +165,6 @@
/* Define to 1 if you have the `malloc_zone_statistics' function. */
/* HAVE_MALLOC_ZONE_STATISTICS defined in Bazel */
/* Define to 1 if you have the `posix_fallocate' function. */
/* HAVE_POSIX_FALLOCATE defined in Bazel */
/* Define to 1 if you have the `posix_spawn' function. */
#define HAVE_POSIX_SPAWN 1

View File

@ -152,9 +152,6 @@
/* Define to 1 if you have the `malloc_zone_statistics' function. */
#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS}
/* Define to 1 if you have the `posix_fallocate' function. */
#cmakedefine HAVE_POSIX_FALLOCATE ${HAVE_POSIX_FALLOCATE}
/* Define to 1 if you have the `posix_spawn' function. */
#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN}