mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-24 13:53:11 +00:00
Remove pidfd_open call handling and rely on PIDFD_SELF
This commit is contained in:
committed by
Guangli Dai
parent
9442300cc3
commit
5d5f76ee01
@@ -2638,10 +2638,11 @@ if test "x${je_cv_madvise}" = "xyes" ; then
|
|||||||
|
|
||||||
dnl Check for process_madvise
|
dnl Check for process_madvise
|
||||||
JE_COMPILABLE([process_madvise(2)], [
|
JE_COMPILABLE([process_madvise(2)], [
|
||||||
|
#include <sys/pidfd.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
], [
|
], [
|
||||||
syscall(SYS_process_madvise, 0, (void *)0, 0, 0, 0);
|
syscall(SYS_process_madvise, PIDFD_SELF, (void *)0, 0, 0, 0);
|
||||||
], [je_cv_process_madvise])
|
], [je_cv_process_madvise])
|
||||||
if test "x${je_cv_process_madvise}" = "xyes" ; then
|
if test "x${je_cv_process_madvise}" = "xyes" ; then
|
||||||
AC_DEFINE([JEMALLOC_HAVE_PROCESS_MADVISE], [ ], [ ])
|
AC_DEFINE([JEMALLOC_HAVE_PROCESS_MADVISE], [ ], [ ])
|
||||||
|
|||||||
@@ -127,6 +127,5 @@ bool pages_boot(void);
|
|||||||
void pages_set_thp_state(void *ptr, size_t size);
|
void pages_set_thp_state(void *ptr, size_t size);
|
||||||
void pages_mark_guards(void *head, void *tail);
|
void pages_mark_guards(void *head, void *tail);
|
||||||
void pages_unmark_guards(void *head, void *tail);
|
void pages_unmark_guards(void *head, void *tail);
|
||||||
void pages_postfork_child(void);
|
|
||||||
|
|
||||||
#endif /* JEMALLOC_INTERNAL_PAGES_EXTERNS_H */
|
#endif /* JEMALLOC_INTERNAL_PAGES_EXTERNS_H */
|
||||||
|
|||||||
@@ -4535,7 +4535,6 @@ jemalloc_postfork_child(void) {
|
|||||||
malloc_mutex_postfork_child(tsd_tsdn(tsd), &arenas_lock);
|
malloc_mutex_postfork_child(tsd_tsdn(tsd), &arenas_lock);
|
||||||
tcache_postfork_child(tsd_tsdn(tsd));
|
tcache_postfork_child(tsd_tsdn(tsd));
|
||||||
ctl_postfork_child(tsd_tsdn(tsd));
|
ctl_postfork_child(tsd_tsdn(tsd));
|
||||||
pages_postfork_child();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|||||||
41
src/pages.c
41
src/pages.c
@@ -621,7 +621,11 @@ pages_dodump(void *addr, size_t size) {
|
|||||||
#ifdef JEMALLOC_HAVE_PROCESS_MADVISE
|
#ifdef JEMALLOC_HAVE_PROCESS_MADVISE
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
# include <sys/syscall.h>
|
# include <sys/syscall.h>
|
||||||
static atomic_i_t process_madvise_pidfd = ATOMIC_INIT(-1);
|
|
||||||
|
#ifndef PIDFD_SELF
|
||||||
|
#define PIDFD_SELF -10000
|
||||||
|
#endif
|
||||||
|
|
||||||
static atomic_b_t process_madvise_gate = ATOMIC_INIT(true);
|
static atomic_b_t process_madvise_gate = ATOMIC_INIT(true);
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -650,33 +654,17 @@ pages_purge_process_madvise_impl(
|
|||||||
if (!atomic_load_b(&process_madvise_gate, ATOMIC_RELAXED)) {
|
if (!atomic_load_b(&process_madvise_gate, ATOMIC_RELAXED)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int pid_fd = atomic_load_i(&process_madvise_pidfd, ATOMIC_RELAXED);
|
|
||||||
while (pid_fd == -1) {
|
|
||||||
int newfd = (int) syscall(SYS_pidfd_open, getpid(), 0);
|
|
||||||
if (newfd == -1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!atomic_compare_exchange_strong_i(&process_madvise_pidfd,
|
|
||||||
&pid_fd, newfd,
|
|
||||||
ATOMIC_RELAXED,
|
|
||||||
ATOMIC_RELAXED)) {
|
|
||||||
/* Someone else set the fd, so we close ours */
|
|
||||||
assert(pid_fd != -1);
|
|
||||||
close(newfd);
|
|
||||||
} else {
|
|
||||||
pid_fd = newfd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: remove this save/restore of errno after supporting errno
|
* TODO: remove this save/restore of errno after supporting errno
|
||||||
* preservation for free() call properly.
|
* preservation for free() call properly.
|
||||||
*/
|
*/
|
||||||
int saved_errno = get_errno();
|
int saved_errno = get_errno();
|
||||||
size_t purged_bytes = (size_t)syscall(JE_SYS_PROCESS_MADVISE_NR, pid_fd,
|
size_t purged_bytes = (size_t)syscall(JE_SYS_PROCESS_MADVISE_NR,
|
||||||
(struct iovec *)vec, vec_len, MADV_DONTNEED, 0);
|
PIDFD_SELF, (struct iovec *)vec, vec_len, MADV_DONTNEED, 0);
|
||||||
if (purged_bytes == (size_t) -1) {
|
if (purged_bytes == (size_t) -1) {
|
||||||
if (errno == EPERM || errno == EINVAL || errno == ENOSYS) {
|
if (errno == EPERM || errno == EINVAL || errno == ENOSYS
|
||||||
|
|| errno == EBADF) {
|
||||||
/* Process madvise not supported the way we need it. */
|
/* Process madvise not supported the way we need it. */
|
||||||
atomic_store_b(&process_madvise_gate, false,
|
atomic_store_b(&process_madvise_gate, false,
|
||||||
ATOMIC_RELAXED);
|
ATOMIC_RELAXED);
|
||||||
@@ -687,15 +675,6 @@ pages_purge_process_madvise_impl(
|
|||||||
return purged_bytes != total_bytes;
|
return purged_bytes != total_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pages_postfork_child(void) {
|
|
||||||
/* Reset the file descriptor we inherited from parent process */
|
|
||||||
int pid_fd = atomic_load_i(&process_madvise_pidfd, ATOMIC_RELAXED);
|
|
||||||
if (pid_fd != -1) {
|
|
||||||
atomic_store_i(&process_madvise_pidfd, -1, ATOMIC_RELAXED);
|
|
||||||
close(pid_fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -710,8 +689,6 @@ pages_purge_process_madvise_impl(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pages_postfork_child(void) {}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
Reference in New Issue
Block a user