* allow the sbrk backend to be requested via UMEM_OPTIONS=backend=sbrk, but note that this appears to be broken on non-solaris platforms.
* make a safer/better check for number of cpus on linux * use pthread_once to register the forkhandler, as it is possible to call it twice in some scenarios without this protection
This commit is contained in:
parent
b2ee64fc04
commit
f82ad44b62
2 changed files with 36 additions and 25 deletions
55
init_lib.c
55
init_lib.c
|
@ -56,28 +56,31 @@ vmem_heap_init(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
vmem_backend = VMEM_BACKEND_MMAP;
|
vmem_backend = VMEM_BACKEND_MMAP;
|
||||||
|
(void) vmem_sbrk_arena(NULL, NULL);
|
||||||
#else
|
#else
|
||||||
#if 0
|
# if defined(sun)
|
||||||
void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD);
|
void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD);
|
||||||
|
|
||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
#endif
|
|
||||||
log_message("sbrk backend disabled\n");
|
log_message("sbrk backend disabled\n");
|
||||||
vmem_backend = VMEM_BACKEND_MMAP;
|
vmem_backend = VMEM_BACKEND_MMAP;
|
||||||
#if 0
|
|
||||||
}
|
}
|
||||||
#endif
|
# else
|
||||||
#endif
|
if (vmem_backend == 0) {
|
||||||
|
/* prefer mmap, as sbrk() seems to have problems wither working
|
||||||
|
* with other allocators or has some Solaris specific assumptions. */
|
||||||
|
vmem_backend = VMEM_BACKEND_MMAP;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
if ((vmem_backend & VMEM_BACKEND_MMAP) != 0) {
|
if ((vmem_backend & VMEM_BACKEND_MMAP) != 0) {
|
||||||
vmem_backend = VMEM_BACKEND_MMAP;
|
vmem_backend = VMEM_BACKEND_MMAP;
|
||||||
(void) vmem_mmap_arena(NULL, NULL);
|
(void) vmem_mmap_arena(NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
#ifndef _WIN32
|
|
||||||
vmem_backend = VMEM_BACKEND_SBRK;
|
vmem_backend = VMEM_BACKEND_SBRK;
|
||||||
(void) vmem_sbrk_arena(NULL, NULL);
|
(void) vmem_sbrk_arena(NULL, NULL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
|
@ -104,28 +107,32 @@ umem_get_max_ncpus(void)
|
||||||
* in /proc/stat. To avoid recursion in the malloc replacement
|
* in /proc/stat. To avoid recursion in the malloc replacement
|
||||||
* version of libumem, read /proc/stat into a static buffer.
|
* version of libumem, read /proc/stat into a static buffer.
|
||||||
*/
|
*/
|
||||||
static char proc_stat[8192];
|
static int ncpus = 0;
|
||||||
int fd;
|
|
||||||
int ncpus = 1;
|
|
||||||
|
|
||||||
fd = open("/proc/stat", O_RDONLY);
|
if (ncpus == 0) {
|
||||||
if (fd >= 0) {
|
char proc_stat[8192];
|
||||||
const ssize_t n = read(fd, proc_stat, sizeof(proc_stat) - 1);
|
int fd;
|
||||||
if (n >= 0) {
|
|
||||||
const char *cur;
|
|
||||||
const char *next;
|
|
||||||
|
|
||||||
proc_stat[n] = '\0';
|
ncpus = 1;
|
||||||
cur = proc_stat;
|
fd = open("/proc/stat", O_RDONLY);
|
||||||
while (*cur && (next = strstr(cur + 3, "cpu"))) {
|
if (fd >= 0) {
|
||||||
cur = next;
|
const ssize_t n = read(fd, proc_stat, sizeof(proc_stat) - 1);
|
||||||
|
if (n >= 0) {
|
||||||
|
const char *cur;
|
||||||
|
const char *next;
|
||||||
|
|
||||||
|
proc_stat[n] = '\0';
|
||||||
|
cur = proc_stat;
|
||||||
|
while (*cur && (next = strstr(cur + 3, "cpu"))) {
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*cur)
|
||||||
|
ncpus = atoi(cur + 3) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*cur)
|
close(fd);
|
||||||
ncpus = atoi(cur + 3) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ncpus;
|
return ncpus;
|
||||||
|
|
6
umem.c
6
umem.c
|
@ -621,6 +621,9 @@ static umem_cache_t *umem_alloc_table[UMEM_MAXBUF >> UMEM_ALIGN_SHIFT] = {
|
||||||
caddr_t umem_min_stack;
|
caddr_t umem_min_stack;
|
||||||
caddr_t umem_max_stack;
|
caddr_t umem_max_stack;
|
||||||
|
|
||||||
|
#ifndef UMEM_STANDALONE
|
||||||
|
static pthread_once_t umem_forkhandler_once = PTHREAD_ONCE_INIT;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we use the _ versions, since we don't want to be cancelled.
|
* we use the _ versions, since we don't want to be cancelled.
|
||||||
|
@ -2907,7 +2910,8 @@ umem_startup(caddr_t start, size_t len, size_t pagesize, caddr_t minstack,
|
||||||
int idx;
|
int idx;
|
||||||
/* Standalone doesn't fork */
|
/* Standalone doesn't fork */
|
||||||
#else
|
#else
|
||||||
umem_forkhandler_init(); /* register the fork handler */
|
/* register the fork handler */
|
||||||
|
(void) pthread_once(&umem_forkhandler_once, umem_forkhandler_init);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __lint
|
#ifdef __lint
|
||||||
|
|
Loading…
Reference in a new issue