--- old/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp 2020-05-18 16:30:50.186874711 +0200 +++ new/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp 2020-05-18 16:30:49.929866386 +0200 @@ -112,9 +112,8 @@ static int z_fallocate_hugetlbfs_attempts = 3; static bool z_fallocate_supported = true; -ZPhysicalMemoryBacking::ZPhysicalMemoryBacking() : +ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) : _fd(-1), - _size(0), _filesystem(0), _block_size(0), _available(0), @@ -126,6 +125,13 @@ return; } + // Truncate backing file + if (ftruncate(_fd, max_capacity) == -1) { + ZErrno err; + log_error(gc)("Failed to truncate backing file (%s)", err.to_string()); + return; + } + // Get filesystem statistics struct statfs buf; if (fstatfs(_fd, &buf) == -1) { @@ -361,10 +367,6 @@ warn_max_map_count(max); } -size_t ZPhysicalMemoryBacking::size() const { - return _size; -} - bool ZPhysicalMemoryBacking::is_tmpfs() const { return _filesystem == TMPFS_MAGIC; } @@ -379,18 +381,6 @@ return access(ZFILENAME_SHMEM_ENABLED, R_OK) == 0; } -ZErrno ZPhysicalMemoryBacking::fallocate_compat_ftruncate(size_t size) const { - while (ftruncate(_fd, size) == -1) { - if (errno != EINTR) { - // Failed - return errno; - } - } - - // Success - return 0; -} - ZErrno ZPhysicalMemoryBacking::fallocate_compat_mmap_hugetlbfs(size_t offset, size_t length, bool touch) const { // On hugetlbfs, mapping a file segment will fail immediately, without // the need to touch the mapped pages first, if there aren't enough huge @@ -489,41 +479,13 @@ // since Linux 4.3. When fallocate(2) is not supported we emulate it using // mmap/munmap (for hugetlbfs and tmpfs with transparent huge pages) or pwrite // (for tmpfs without transparent huge pages and other filesystem types). - - const size_t end = offset + length; - if (end > _size) { - // Increase file size - const ZErrno err = fallocate_compat_ftruncate(end); - if (err) { - // Failed - return err; - } - } - - // Allocate backing memory - const ZErrno err = ZLargePages::is_explicit() - ? fallocate_compat_mmap_hugetlbfs(offset, length, false /* touch */) - : (ZLargePages::is_transparent() - ? fallocate_compat_mmap_tmpfs(offset, length) - : fallocate_compat_pwrite(offset, length)); - - if (err) { - if (end > _size) { - // Restore file size - fallocate_compat_ftruncate(_size); - } - - // Failed - return err; - } - - if (end > _size) { - // Record new file size - _size = end; + if (ZLargePages::is_explicit()) { + return fallocate_compat_mmap_hugetlbfs(offset, length, false /* touch */); + } else if (ZLargePages::is_transparent()) { + return fallocate_compat_mmap_tmpfs(offset, length); + } else { + return fallocate_compat_pwrite(offset, length); } - - // Success - return 0; } ZErrno ZPhysicalMemoryBacking::fallocate_fill_hole_syscall(size_t offset, size_t length) { @@ -534,12 +496,6 @@ return errno; } - const size_t end = offset + length; - if (end > _size) { - // Record new file size - _size = end; - } - // Success return 0; }