src/hotspot/os_cpu/linux_aarch64/gc/z/zBackingFile_linux_aarch64.cpp
changeset 57899 54845835747f
parent 55379 865775b86780
equal deleted inserted replaced
57898:5ddb746d45e0 57899:54845835747f
    26 #include "gc/z/zBackingFile_linux_aarch64.hpp"
    26 #include "gc/z/zBackingFile_linux_aarch64.hpp"
    27 #include "gc/z/zBackingPath_linux_aarch64.hpp"
    27 #include "gc/z/zBackingPath_linux_aarch64.hpp"
    28 #include "gc/z/zErrno.hpp"
    28 #include "gc/z/zErrno.hpp"
    29 #include "gc/z/zGlobals.hpp"
    29 #include "gc/z/zGlobals.hpp"
    30 #include "gc/z/zLargePages.inline.hpp"
    30 #include "gc/z/zLargePages.inline.hpp"
       
    31 #include "gc/z/zSyscall_linux.hpp"
    31 #include "logging/log.hpp"
    32 #include "logging/log.hpp"
    32 #include "runtime/init.hpp"
    33 #include "runtime/init.hpp"
    33 #include "runtime/os.hpp"
    34 #include "runtime/os.hpp"
    34 #include "utilities/align.hpp"
    35 #include "utilities/align.hpp"
    35 #include "utilities/debug.hpp"
    36 #include "utilities/debug.hpp"
    36 
    37 
    37 #include <fcntl.h>
    38 #include <fcntl.h>
    38 #include <sys/mman.h>
    39 #include <sys/mman.h>
    39 #include <sys/stat.h>
    40 #include <sys/stat.h>
    40 #include <sys/statfs.h>
    41 #include <sys/statfs.h>
    41 #include <sys/syscall.h>
       
    42 #include <sys/types.h>
    42 #include <sys/types.h>
    43 #include <unistd.h>
    43 #include <unistd.h>
    44 
    44 
    45 //
    45 //
    46 // Support for building on older Linux systems
    46 // Support for building on older Linux systems
    47 //
    47 //
    48 
       
    49 // System calls
       
    50 #ifndef SYS_fallocate
       
    51 #define SYS_fallocate                    47
       
    52 #endif
       
    53 #ifndef SYS_memfd_create
       
    54 #define SYS_memfd_create                 279
       
    55 #endif
       
    56 
    48 
    57 // memfd_create(2) flags
    49 // memfd_create(2) flags
    58 #ifndef MFD_CLOEXEC
    50 #ifndef MFD_CLOEXEC
    59 #define MFD_CLOEXEC                      0x0001U
    51 #define MFD_CLOEXEC                      0x0001U
    60 #endif
    52 #endif
   110   NULL
   102   NULL
   111 };
   103 };
   112 
   104 
   113 static int z_fallocate_hugetlbfs_attempts = 3;
   105 static int z_fallocate_hugetlbfs_attempts = 3;
   114 static bool z_fallocate_supported = true;
   106 static bool z_fallocate_supported = true;
   115 
       
   116 static int z_fallocate(int fd, int mode, size_t offset, size_t length) {
       
   117   return syscall(SYS_fallocate, fd, mode, offset, length);
       
   118 }
       
   119 
       
   120 static int z_memfd_create(const char *name, unsigned int flags) {
       
   121   return syscall(SYS_memfd_create, name, flags);
       
   122 }
       
   123 
   107 
   124 ZBackingFile::ZBackingFile() :
   108 ZBackingFile::ZBackingFile() :
   125     _fd(-1),
   109     _fd(-1),
   126     _size(0),
   110     _size(0),
   127     _filesystem(0),
   111     _filesystem(0),
   195   char filename[PATH_MAX];
   179   char filename[PATH_MAX];
   196   snprintf(filename, sizeof(filename), "%s%s", name, ZLargePages::is_explicit() ? ".hugetlb" : "");
   180   snprintf(filename, sizeof(filename), "%s%s", name, ZLargePages::is_explicit() ? ".hugetlb" : "");
   197 
   181 
   198   // Create file
   182   // Create file
   199   const int extra_flags = ZLargePages::is_explicit() ? MFD_HUGETLB : 0;
   183   const int extra_flags = ZLargePages::is_explicit() ? MFD_HUGETLB : 0;
   200   const int fd = z_memfd_create(filename, MFD_CLOEXEC | extra_flags);
   184   const int fd = ZSyscall::memfd_create(filename, MFD_CLOEXEC | extra_flags);
   201   if (fd == -1) {
   185   if (fd == -1) {
   202     ZErrno err;
   186     ZErrno err;
   203     log_debug(gc, init)("Failed to create memfd file (%s)",
   187     log_debug(gc, init)("Failed to create memfd file (%s)",
   204                         ((ZLargePages::is_explicit() && err == EINVAL) ? "Hugepages not supported" : err.to_string()));
   188                         ((ZLargePages::is_explicit() && err == EINVAL) ? "Hugepages not supported" : err.to_string()));
   205     return -1;
   189     return -1;
   414   return 0;
   398   return 0;
   415 }
   399 }
   416 
   400 
   417 ZErrno ZBackingFile::fallocate_fill_hole_syscall(size_t offset, size_t length) {
   401 ZErrno ZBackingFile::fallocate_fill_hole_syscall(size_t offset, size_t length) {
   418   const int mode = 0; // Allocate
   402   const int mode = 0; // Allocate
   419   const int res = z_fallocate(_fd, mode, offset, length);
   403   const int res = ZSyscall::fallocate(_fd, mode, offset, length);
   420   if (res == -1) {
   404   if (res == -1) {
   421     // Failed
   405     // Failed
   422     return errno;
   406     return errno;
   423   }
   407   }
   424 
   408 
   469       return err;
   453       return err;
   470     }
   454     }
   471   }
   455   }
   472 
   456 
   473   const int mode = FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE;
   457   const int mode = FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE;
   474   if (z_fallocate(_fd, mode, offset, length) == -1) {
   458   if (ZSyscall::fallocate(_fd, mode, offset, length) == -1) {
   475     // Failed
   459     // Failed
   476     return errno;
   460     return errno;
   477   }
   461   }
   478 
   462 
   479   // Success
   463   // Success