* 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
|
||||
vmem_backend = VMEM_BACKEND_MMAP;
|
||||
(void) vmem_sbrk_arena(NULL, NULL);
|
||||
#else
|
||||
#if 0
|
||||
# if defined(sun)
|
||||
void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD);
|
||||
|
||||
if (handle != NULL) {
|
||||
#endif
|
||||
log_message("sbrk backend disabled\n");
|
||||
vmem_backend = VMEM_BACKEND_MMAP;
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
# else
|
||||
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) {
|
||||
vmem_backend = VMEM_BACKEND_MMAP;
|
||||
(void) vmem_mmap_arena(NULL, NULL);
|
||||
} else {
|
||||
#ifndef _WIN32
|
||||
vmem_backend = VMEM_BACKEND_SBRK;
|
||||
(void) vmem_sbrk_arena(NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
|
@ -104,28 +107,32 @@ umem_get_max_ncpus(void)
|
|||
* in /proc/stat. To avoid recursion in the malloc replacement
|
||||
* version of libumem, read /proc/stat into a static buffer.
|
||||
*/
|
||||
static char proc_stat[8192];
|
||||
int fd;
|
||||
int ncpus = 1;
|
||||
static int ncpus = 0;
|
||||
|
||||
fd = open("/proc/stat", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
const ssize_t n = read(fd, proc_stat, sizeof(proc_stat) - 1);
|
||||
if (n >= 0) {
|
||||
const char *cur;
|
||||
const char *next;
|
||||
if (ncpus == 0) {
|
||||
char proc_stat[8192];
|
||||
int fd;
|
||||
|
||||
proc_stat[n] = '\0';
|
||||
cur = proc_stat;
|
||||
while (*cur && (next = strstr(cur + 3, "cpu"))) {
|
||||
cur = next;
|
||||
ncpus = 1;
|
||||
fd = open("/proc/stat", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
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)
|
||||
ncpus = atoi(cur + 3) + 1;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
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_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.
|
||||
|
@ -2907,7 +2910,8 @@ umem_startup(caddr_t start, size_t len, size_t pagesize, caddr_t minstack,
|
|||
int idx;
|
||||
/* Standalone doesn't fork */
|
||||
#else
|
||||
umem_forkhandler_init(); /* register the fork handler */
|
||||
/* register the fork handler */
|
||||
(void) pthread_once(&umem_forkhandler_once, umem_forkhandler_init);
|
||||
#endif
|
||||
|
||||
#ifdef __lint
|
||||
|
|
Loading…
Reference in a new issue