84 # include <sys/time.h>
85 # include <sys/times.h>
86 # include <sys/utsname.h>
87 # include <sys/socket.h>
88 # include <sys/wait.h>
89 # include <pwd.h>
90 # include <poll.h>
91 # include <semaphore.h>
92 # include <fcntl.h>
93 # include <string.h>
94 # include <syscall.h>
95 # include <sys/sysinfo.h>
96 # include <gnu/libc-version.h>
97 # include <sys/ipc.h>
98 # include <sys/shm.h>
99 # include <link.h>
100 # include <stdint.h>
101 # include <inttypes.h>
102 # include <sys/ioctl.h>
103
104 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
105 // getrusage() is prepared to handle the associated failure.
106 #ifndef RUSAGE_THREAD
107 #define RUSAGE_THREAD (1) /* only the calling thread */
108 #endif
109
110 #define MAX_PATH (2 * K)
111
112 #define MAX_SECS 100000000
113
114 // for timer info max values which include all bits
115 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
116
117 #define LARGEPAGES_BIT (1 << 6)
118 ////////////////////////////////////////////////////////////////////////////////
119 // global variables
120 julong os::Linux::_physical_memory = 0;
121
122 address os::Linux::_initial_thread_stack_bottom = NULL;
123 uintptr_t os::Linux::_initial_thread_stack_size = 0;
2120
2121 void os::print_os_info_brief(outputStream* st) {
2122 os::Linux::print_distro_info(st);
2123
2124 os::Posix::print_uname_info(st);
2125
2126 os::Linux::print_libversion_info(st);
2127
2128 }
2129
2130 void os::print_os_info(outputStream* st) {
2131 st->print("OS:");
2132
2133 os::Linux::print_distro_info(st);
2134
2135 os::Posix::print_uname_info(st);
2136
2137 // Print warning if unsafe chroot environment detected
2138 if (unsafe_chroot_detected) {
2139 st->print("WARNING!! ");
2140 st->print_cr(unstable_chroot_error);
2141 }
2142
2143 os::Linux::print_libversion_info(st);
2144
2145 os::Posix::print_rlimit_info(st);
2146
2147 os::Posix::print_load_average(st);
2148
2149 os::Linux::print_full_memory_info(st);
2150 }
2151
2152 // Try to identify popular distros.
2153 // Most Linux distributions have a /etc/XXX-release file, which contains
2154 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2155 // file that also contains the OS version string. Some have more than one
2156 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2157 // /etc/redhat-release.), so the order is important.
2158 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2159 // their own specific XXX-release file as well as a redhat-release file.
2160 // Because of this the XXX-release file needs to be searched for before the
2181 !_print_ascii_file("/etc/turbolinux-release", st) &&
2182 !_print_ascii_file("/etc/gentoo-release", st) &&
2183 !_print_ascii_file("/etc/ltib-release", st) &&
2184 !_print_ascii_file("/etc/angstrom-version", st) &&
2185 !_print_ascii_file("/etc/system-release", st) &&
2186 !_print_ascii_file("/etc/os-release", st)) {
2187
2188 if (file_exists("/etc/debian_version")) {
2189 st->print("Debian ");
2190 _print_ascii_file("/etc/debian_version", st);
2191 } else {
2192 st->print("Linux");
2193 }
2194 }
2195 st->cr();
2196 }
2197
2198 void os::Linux::print_libversion_info(outputStream* st) {
2199 // libc, pthread
2200 st->print("libc:");
2201 st->print(os::Linux::glibc_version()); st->print(" ");
2202 st->print(os::Linux::libpthread_version()); st->print(" ");
2203 if (os::Linux::is_LinuxThreads()) {
2204 st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
2205 }
2206 st->cr();
2207 }
2208
2209 void os::Linux::print_full_memory_info(outputStream* st) {
2210 st->print("\n/proc/meminfo:\n");
2211 _print_ascii_file("/proc/meminfo", st);
2212 st->cr();
2213 }
2214
2215 void os::print_memory_info(outputStream* st) {
2216
2217 st->print("Memory:");
2218 st->print(" %dk page", os::vm_page_size()>>10);
2219
2220 // values in struct sysinfo are "unsigned long"
2221 struct sysinfo si;
2222 sysinfo(&si);
3399 // Create a large shared memory region to attach to based on size.
3400 // Currently, size is the total size of the heap
3401 int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
3402 if (shmid == -1) {
3403 // Possible reasons for shmget failure:
3404 // 1. shmmax is too small for Java heap.
3405 // > check shmmax value: cat /proc/sys/kernel/shmmax
3406 // > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
3407 // 2. not enough large page memory.
3408 // > check available large pages: cat /proc/meminfo
3409 // > increase amount of large pages:
3410 // echo new_value > /proc/sys/vm/nr_hugepages
3411 // Note 1: different Linux may use different name for this property,
3412 // e.g. on Redhat AS-3 it is "hugetlb_pool".
3413 // Note 2: it's possible there's enough physical memory available but
3414 // they are so fragmented after a long run that they can't
3415 // coalesce into large pages. Try to reserve large pages when
3416 // the system is still "fresh".
3417 if (warn_on_failure) {
3418 jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
3419 warning(msg);
3420 }
3421 return NULL;
3422 }
3423
3424 // attach to the region
3425 addr = (char*)shmat(shmid, req_addr, 0);
3426 int err = errno;
3427
3428 // Remove shmid. If shmat() is successful, the actual shared memory segment
3429 // will be deleted when it's detached by shmdt() or when the process
3430 // terminates. If shmat() is not successful this will remove the shared
3431 // segment immediately.
3432 shmctl(shmid, IPC_RMID, NULL);
3433
3434 if ((intptr_t)addr == -1) {
3435 if (warn_on_failure) {
3436 jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
3437 warning(msg);
3438 }
3439 return NULL;
3440 }
3441
3442 return addr;
3443 }
3444
3445 static void warn_on_large_pages_failure(char* req_addr, size_t bytes, int error) {
3446 assert(error == ENOMEM, "Only expect to fail if no memory is available");
3447
3448 bool warn_on_failure = UseLargePages &&
3449 (!FLAG_IS_DEFAULT(UseLargePages) ||
3450 !FLAG_IS_DEFAULT(UseHugeTLBFS) ||
3451 !FLAG_IS_DEFAULT(LargePageSizeInBytes));
3452
3453 if (warn_on_failure) {
3454 char msg[128];
3455 jio_snprintf(msg, sizeof(msg), "Failed to reserve large pages memory req_addr: "
3456 PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
3457 warning(msg);
3458 }
3459 }
3460
3461 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec) {
3462 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
3463 assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size");
3464 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
3465
3466 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
3467 char* addr = (char*)::mmap(req_addr, bytes, prot,
3468 MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB,
3469 -1, 0);
3470
3471 if (addr == MAP_FAILED) {
3472 warn_on_large_pages_failure(req_addr, bytes, errno);
3473 return NULL;
3474 }
3475
3476 assert(is_ptr_aligned(addr, os::large_page_size()), "Must be");
3477
|
84 # include <sys/time.h>
85 # include <sys/times.h>
86 # include <sys/utsname.h>
87 # include <sys/socket.h>
88 # include <sys/wait.h>
89 # include <pwd.h>
90 # include <poll.h>
91 # include <semaphore.h>
92 # include <fcntl.h>
93 # include <string.h>
94 # include <syscall.h>
95 # include <sys/sysinfo.h>
96 # include <gnu/libc-version.h>
97 # include <sys/ipc.h>
98 # include <sys/shm.h>
99 # include <link.h>
100 # include <stdint.h>
101 # include <inttypes.h>
102 # include <sys/ioctl.h>
103
104 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
105
106 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
107 // getrusage() is prepared to handle the associated failure.
108 #ifndef RUSAGE_THREAD
109 #define RUSAGE_THREAD (1) /* only the calling thread */
110 #endif
111
112 #define MAX_PATH (2 * K)
113
114 #define MAX_SECS 100000000
115
116 // for timer info max values which include all bits
117 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
118
119 #define LARGEPAGES_BIT (1 << 6)
120 ////////////////////////////////////////////////////////////////////////////////
121 // global variables
122 julong os::Linux::_physical_memory = 0;
123
124 address os::Linux::_initial_thread_stack_bottom = NULL;
125 uintptr_t os::Linux::_initial_thread_stack_size = 0;
2122
2123 void os::print_os_info_brief(outputStream* st) {
2124 os::Linux::print_distro_info(st);
2125
2126 os::Posix::print_uname_info(st);
2127
2128 os::Linux::print_libversion_info(st);
2129
2130 }
2131
2132 void os::print_os_info(outputStream* st) {
2133 st->print("OS:");
2134
2135 os::Linux::print_distro_info(st);
2136
2137 os::Posix::print_uname_info(st);
2138
2139 // Print warning if unsafe chroot environment detected
2140 if (unsafe_chroot_detected) {
2141 st->print("WARNING!! ");
2142 st->print_cr("%s", unstable_chroot_error);
2143 }
2144
2145 os::Linux::print_libversion_info(st);
2146
2147 os::Posix::print_rlimit_info(st);
2148
2149 os::Posix::print_load_average(st);
2150
2151 os::Linux::print_full_memory_info(st);
2152 }
2153
2154 // Try to identify popular distros.
2155 // Most Linux distributions have a /etc/XXX-release file, which contains
2156 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2157 // file that also contains the OS version string. Some have more than one
2158 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2159 // /etc/redhat-release.), so the order is important.
2160 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2161 // their own specific XXX-release file as well as a redhat-release file.
2162 // Because of this the XXX-release file needs to be searched for before the
2183 !_print_ascii_file("/etc/turbolinux-release", st) &&
2184 !_print_ascii_file("/etc/gentoo-release", st) &&
2185 !_print_ascii_file("/etc/ltib-release", st) &&
2186 !_print_ascii_file("/etc/angstrom-version", st) &&
2187 !_print_ascii_file("/etc/system-release", st) &&
2188 !_print_ascii_file("/etc/os-release", st)) {
2189
2190 if (file_exists("/etc/debian_version")) {
2191 st->print("Debian ");
2192 _print_ascii_file("/etc/debian_version", st);
2193 } else {
2194 st->print("Linux");
2195 }
2196 }
2197 st->cr();
2198 }
2199
2200 void os::Linux::print_libversion_info(outputStream* st) {
2201 // libc, pthread
2202 st->print("libc:");
2203 st->print("%s ", os::Linux::glibc_version());
2204 st->print("%s ", os::Linux::libpthread_version());
2205 if (os::Linux::is_LinuxThreads()) {
2206 st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
2207 }
2208 st->cr();
2209 }
2210
2211 void os::Linux::print_full_memory_info(outputStream* st) {
2212 st->print("\n/proc/meminfo:\n");
2213 _print_ascii_file("/proc/meminfo", st);
2214 st->cr();
2215 }
2216
2217 void os::print_memory_info(outputStream* st) {
2218
2219 st->print("Memory:");
2220 st->print(" %dk page", os::vm_page_size()>>10);
2221
2222 // values in struct sysinfo are "unsigned long"
2223 struct sysinfo si;
2224 sysinfo(&si);
3401 // Create a large shared memory region to attach to based on size.
3402 // Currently, size is the total size of the heap
3403 int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
3404 if (shmid == -1) {
3405 // Possible reasons for shmget failure:
3406 // 1. shmmax is too small for Java heap.
3407 // > check shmmax value: cat /proc/sys/kernel/shmmax
3408 // > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
3409 // 2. not enough large page memory.
3410 // > check available large pages: cat /proc/meminfo
3411 // > increase amount of large pages:
3412 // echo new_value > /proc/sys/vm/nr_hugepages
3413 // Note 1: different Linux may use different name for this property,
3414 // e.g. on Redhat AS-3 it is "hugetlb_pool".
3415 // Note 2: it's possible there's enough physical memory available but
3416 // they are so fragmented after a long run that they can't
3417 // coalesce into large pages. Try to reserve large pages when
3418 // the system is still "fresh".
3419 if (warn_on_failure) {
3420 jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
3421 warning("%s", msg);
3422 }
3423 return NULL;
3424 }
3425
3426 // attach to the region
3427 addr = (char*)shmat(shmid, req_addr, 0);
3428 int err = errno;
3429
3430 // Remove shmid. If shmat() is successful, the actual shared memory segment
3431 // will be deleted when it's detached by shmdt() or when the process
3432 // terminates. If shmat() is not successful this will remove the shared
3433 // segment immediately.
3434 shmctl(shmid, IPC_RMID, NULL);
3435
3436 if ((intptr_t)addr == -1) {
3437 if (warn_on_failure) {
3438 jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
3439 warning("%s", msg);
3440 }
3441 return NULL;
3442 }
3443
3444 return addr;
3445 }
3446
3447 static void warn_on_large_pages_failure(char* req_addr, size_t bytes, int error) {
3448 assert(error == ENOMEM, "Only expect to fail if no memory is available");
3449
3450 bool warn_on_failure = UseLargePages &&
3451 (!FLAG_IS_DEFAULT(UseLargePages) ||
3452 !FLAG_IS_DEFAULT(UseHugeTLBFS) ||
3453 !FLAG_IS_DEFAULT(LargePageSizeInBytes));
3454
3455 if (warn_on_failure) {
3456 char msg[128];
3457 jio_snprintf(msg, sizeof(msg), "Failed to reserve large pages memory req_addr: "
3458 PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
3459 warning("%s", msg);
3460 }
3461 }
3462
3463 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec) {
3464 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
3465 assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size");
3466 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
3467
3468 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
3469 char* addr = (char*)::mmap(req_addr, bytes, prot,
3470 MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB,
3471 -1, 0);
3472
3473 if (addr == MAP_FAILED) {
3474 warn_on_large_pages_failure(req_addr, bytes, errno);
3475 return NULL;
3476 }
3477
3478 assert(is_ptr_aligned(addr, os::large_page_size()), "Must be");
3479
|