MCPcopy Create free account
hub / github.com/F-Stack/f-stack / init_thp_state

Function init_thp_state

app/redis-6.2.6/deps/jemalloc/src/pages.c:515–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

513}
514
515static void
516init_thp_state(void) {
517 if (!have_madvise_huge) {
518 if (metadata_thp_enabled() && opt_abort) {
519 malloc_write("<jemalloc>: no MADV_HUGEPAGE support\n");
520 abort();
521 }
522 goto label_error;
523 }
524
525 static const char sys_state_madvise[] = "always [madvise] never\n";
526 static const char sys_state_always[] = "[always] madvise never\n";
527 static const char sys_state_never[] = "always madvise [never]\n";
528 char buf[sizeof(sys_state_madvise)];
529
530#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open)
531 int fd = (int)syscall(SYS_open,
532 "/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY);
533#else
534 int fd = open("/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY);
535#endif
536 if (fd == -1) {
537 goto label_error;
538 }
539
540 ssize_t nread = malloc_read_fd(fd, &buf, sizeof(buf));
541#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_close)
542 syscall(SYS_close, fd);
543#else
544 close(fd);
545#endif
546
547 if (strncmp(buf, sys_state_madvise, (size_t)nread) == 0) {
548 init_system_thp_mode = thp_mode_default;
549 } else if (strncmp(buf, sys_state_always, (size_t)nread) == 0) {
550 init_system_thp_mode = thp_mode_always;
551 } else if (strncmp(buf, sys_state_never, (size_t)nread) == 0) {
552 init_system_thp_mode = thp_mode_never;
553 } else {
554 goto label_error;
555 }
556 return;
557label_error:
558 opt_thp = init_system_thp_mode = thp_mode_not_supported;
559}
560
561bool
562pages_boot(void) {

Callers 1

pages_bootFunction · 0.85

Calls 7

metadata_thp_enabledFunction · 0.85
malloc_writeFunction · 0.85
abortClass · 0.85
malloc_read_fdFunction · 0.85
strncmpFunction · 0.85
syscallFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected