< prev index next >

src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp

Print this page




 194                         ((ZLargePages::is_explicit() && err == EINVAL) ? "Hugepages not supported" : err.to_string()));
 195     return -1;
 196   }
 197 
 198   log_info(gc, init)("Heap backed by file: /memfd:%s", filename);
 199 
 200   return fd;
 201 }
 202 
 203 int ZPhysicalMemoryBacking::create_file_fd(const char* name) const {
 204   const char* const filesystem = ZLargePages::is_explicit()
 205                                  ? ZFILESYSTEM_HUGETLBFS
 206                                  : ZFILESYSTEM_TMPFS;
 207   const char** const preferred_mountpoints = ZLargePages::is_explicit()
 208                                              ? z_preferred_hugetlbfs_mountpoints
 209                                              : z_preferred_tmpfs_mountpoints;
 210 
 211   // Find mountpoint
 212   ZMountPoint mountpoint(filesystem, preferred_mountpoints);
 213   if (mountpoint.get() == NULL) {
 214     log_error(gc)("Use -XX:ZPath to specify the path to a %s filesystem", filesystem);
 215     return -1;
 216   }
 217 
 218   // Try to create an anonymous file using the O_TMPFILE flag. Note that this
 219   // flag requires kernel >= 3.11. If this fails we fall back to open/unlink.
 220   const int fd_anon = os::open(mountpoint.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
 221   if (fd_anon == -1) {
 222     ZErrno err;
 223     log_debug(gc, init)("Failed to create anonymous file in %s (%s)", mountpoint.get(),
 224                         (err == EINVAL ? "Not supported" : err.to_string()));
 225   } else {
 226     // Get inode number for anonymous file
 227     struct stat stat_buf;
 228     if (fstat(fd_anon, &stat_buf) == -1) {
 229       ZErrno err;
 230       log_error(gc)("Failed to determine inode number for anonymous file (%s)", err.to_string());
 231       return -1;
 232     }
 233 
 234     log_info(gc, init)("Heap backed by file: %s/#" UINT64_FORMAT, mountpoint.get(), (uint64_t)stat_buf.st_ino);


 246   const int fd = os::open(filename, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
 247   if (fd == -1) {
 248     ZErrno err;
 249     log_error(gc)("Failed to create file %s (%s)", filename, err.to_string());
 250     return -1;
 251   }
 252 
 253   // Unlink file
 254   if (unlink(filename) == -1) {
 255     ZErrno err;
 256     log_error(gc)("Failed to unlink file %s (%s)", filename, err.to_string());
 257     return -1;
 258   }
 259 
 260   log_info(gc, init)("Heap backed by file: %s", filename);
 261 
 262   return fd;
 263 }
 264 
 265 int ZPhysicalMemoryBacking::create_fd(const char* name) const {
 266   if (ZPath == NULL) {
 267     // If the path is not explicitly specified, then we first try to create a memfd file
 268     // instead of looking for a tmpfd/hugetlbfs mount point. Note that memfd_create() might
 269     // not be supported at all (requires kernel >= 3.17), or it might not support large
 270     // pages (requires kernel >= 4.14). If memfd_create() fails, then we try to create a
 271     // file on an accessible tmpfs or hugetlbfs mount point.
 272     const int fd = create_mem_fd(name);
 273     if (fd != -1) {
 274       return fd;
 275     }
 276 
 277     log_debug(gc, init)("Falling back to searching for an accessible mount point");
 278   }
 279 
 280   return create_file_fd(name);
 281 }
 282 
 283 bool ZPhysicalMemoryBacking::is_initialized() const {
 284   return _initialized;
 285 }
 286 




 194                         ((ZLargePages::is_explicit() && err == EINVAL) ? "Hugepages not supported" : err.to_string()));
 195     return -1;
 196   }
 197 
 198   log_info(gc, init)("Heap backed by file: /memfd:%s", filename);
 199 
 200   return fd;
 201 }
 202 
 203 int ZPhysicalMemoryBacking::create_file_fd(const char* name) const {
 204   const char* const filesystem = ZLargePages::is_explicit()
 205                                  ? ZFILESYSTEM_HUGETLBFS
 206                                  : ZFILESYSTEM_TMPFS;
 207   const char** const preferred_mountpoints = ZLargePages::is_explicit()
 208                                              ? z_preferred_hugetlbfs_mountpoints
 209                                              : z_preferred_tmpfs_mountpoints;
 210 
 211   // Find mountpoint
 212   ZMountPoint mountpoint(filesystem, preferred_mountpoints);
 213   if (mountpoint.get() == NULL) {
 214     log_error(gc)("Use -XX:AllocateHeapAt to specify the path to a %s filesystem", filesystem);
 215     return -1;
 216   }
 217 
 218   // Try to create an anonymous file using the O_TMPFILE flag. Note that this
 219   // flag requires kernel >= 3.11. If this fails we fall back to open/unlink.
 220   const int fd_anon = os::open(mountpoint.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
 221   if (fd_anon == -1) {
 222     ZErrno err;
 223     log_debug(gc, init)("Failed to create anonymous file in %s (%s)", mountpoint.get(),
 224                         (err == EINVAL ? "Not supported" : err.to_string()));
 225   } else {
 226     // Get inode number for anonymous file
 227     struct stat stat_buf;
 228     if (fstat(fd_anon, &stat_buf) == -1) {
 229       ZErrno err;
 230       log_error(gc)("Failed to determine inode number for anonymous file (%s)", err.to_string());
 231       return -1;
 232     }
 233 
 234     log_info(gc, init)("Heap backed by file: %s/#" UINT64_FORMAT, mountpoint.get(), (uint64_t)stat_buf.st_ino);


 246   const int fd = os::open(filename, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
 247   if (fd == -1) {
 248     ZErrno err;
 249     log_error(gc)("Failed to create file %s (%s)", filename, err.to_string());
 250     return -1;
 251   }
 252 
 253   // Unlink file
 254   if (unlink(filename) == -1) {
 255     ZErrno err;
 256     log_error(gc)("Failed to unlink file %s (%s)", filename, err.to_string());
 257     return -1;
 258   }
 259 
 260   log_info(gc, init)("Heap backed by file: %s", filename);
 261 
 262   return fd;
 263 }
 264 
 265 int ZPhysicalMemoryBacking::create_fd(const char* name) const {
 266   if (AllocateHeapAt == NULL) {
 267     // If the path is not explicitly specified, then we first try to create a memfd file
 268     // instead of looking for a tmpfd/hugetlbfs mount point. Note that memfd_create() might
 269     // not be supported at all (requires kernel >= 3.17), or it might not support large
 270     // pages (requires kernel >= 4.14). If memfd_create() fails, then we try to create a
 271     // file on an accessible tmpfs or hugetlbfs mount point.
 272     const int fd = create_mem_fd(name);
 273     if (fd != -1) {
 274       return fd;
 275     }
 276 
 277     log_debug(gc, init)("Falling back to searching for an accessible mount point");
 278   }
 279 
 280   return create_file_fd(name);
 281 }
 282 
 283 bool ZPhysicalMemoryBacking::is_initialized() const {
 284   return _initialized;
 285 }
 286 


< prev index next >