merge from dev

This commit is contained in:
daan 2019-07-22 10:16:59 -07:00
commit 80e09ef44e
14 changed files with 46 additions and 32 deletions

View file

@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc.h"
#include "mimalloc-internal.h"
#include <string.h> // memset
#include <string.h> // memset, memcpy
// ------------------------------------------------------
// Aligned Allocation

View file

@ -19,6 +19,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include <errno.h>
#include <string.h> // memcpy
#include <stdlib.h> // getenv
#ifndef EINVAL
#define EINVAL 22
@ -115,7 +116,7 @@ int mi_dupenv_s(char** buf, size_t* size, const char* name) mi_attr_noexcept {
#pragma warning(suppress:4996)
char* p = getenv(name);
if (p==NULL) {
*buf = NULL;
*buf = NULL;
}
else {
*buf = mi_strdup(p);
@ -146,4 +147,3 @@ int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name)
return 0;
#endif
}

View file

@ -8,7 +8,8 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-internal.h"
#include "mimalloc-atomic.h"
#include <string.h> // memset
#include <string.h> // memset, memcpy, strlen
#include <stdlib.h> // malloc, exit
#define MI_IN_ALLOC_C
#include "alloc-override.c"
@ -465,7 +466,7 @@ char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name)
}
}
#else
#include <unistd.h>
#include <unistd.h> // pathconf
static size_t mi_path_max() {
static size_t path_max = 0;
if (path_max <= 0) {

View file

@ -7,7 +7,8 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc.h"
#include "mimalloc-internal.h"
#include <string.h> // memcpy
#include <string.h> // memcpy, memset
#include <stdlib.h> // atexit
// Empty page used to initialize the small free pages array
const mi_page_t _mi_page_empty = {

View file

@ -9,7 +9,8 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-atomic.h"
#include <stdio.h>
#include <string.h> // strcmp
#include <stdlib.h> // strtol
#include <string.h> // strncpy, strncat, strlen, strstr
#include <ctype.h> // toupper
#include <stdarg.h>
@ -59,7 +60,7 @@ static mi_option_desc_t options[_mi_option_last] =
{ 0, UNINIT, "large_os_pages" }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
{ 0, UNINIT, "page_reset" },
{ 0, UNINIT, "cache_reset" },
{ 0, UNINIT, "reset_decommits" }, // note: cannot enable this if secure is on
{ 0, UNINIT, "reset_decommits" }, // note: cannot enable this if secure is on
{ 0, UNINIT, "reset_discards" } // note: cannot enable this if secure is on
};
@ -68,7 +69,7 @@ static void mi_option_init(mi_option_desc_t* desc);
long mi_option_get(mi_option_t option) {
mi_assert(option >= 0 && option < _mi_option_last);
mi_option_desc_t* desc = &options[option];
if (desc->init == UNINIT) {
if (mi_unlikely(desc->init == UNINIT)) {
mi_option_init(desc);
if (option != mi_option_verbose) {
_mi_verbose_message("option '%s': %ld\n", desc->name, desc->value);
@ -116,15 +117,15 @@ static void mi_vfprintf( FILE* out, const char* prefix, const char* fmt, va_list
char buf[256];
if (fmt==NULL) return;
if (out==NULL) out = stdout;
if (_mi_preloading()) return;
if (_mi_preloading()) return;
vsnprintf(buf,sizeof(buf)-1,fmt,args);
#ifdef _WIN32
// on windows with redirection, the C runtime uses us and we cannot call `fputs`
// on windows with redirection, the C runtime uses us and we cannot call `fputs`
// while called from the C runtime itself, so use a non-locking option
if (out==stderr) {
if (prefix != NULL) _cputs(prefix);
_cputs(buf);
return;
if (out==stderr) {
if (prefix != NULL) _cputs(prefix);
_cputs(buf);
return;
}
#endif
if (prefix != NULL) fputs(prefix,out);
@ -204,10 +205,12 @@ static const char* mi_getenv(const char* name) {
const char* s = getenv(name);
if (s == NULL) {
char buf[64+1];
mi_strlcpy(buf,name,64);
for (size_t i = 0; i < strlen(buf); i++) {
size_t len = strlen(name);
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
for (size_t i = 0; i < len; i++) {
buf[i] = toupper(name[i]);
}
buf[len] = 0;
#pragma warning(suppress:4996)
s = getenv(buf);
}
@ -217,15 +220,17 @@ static const char* mi_getenv(const char* name) {
static void mi_option_init(mi_option_desc_t* desc) {
if (!_mi_preloading()) desc->init = DEFAULTED;
// Read option value from the environment
char buf[64];
char buf[64+1];
mi_strlcpy(buf, "mimalloc_", sizeof(buf));
mi_strlcat(buf, desc->name, sizeof(buf));
const char* s = mi_getenv(buf);
const char* s = mi_getenv(buf);
if (s != NULL) {
mi_strlcpy(buf, s, sizeof(buf));
for (size_t i = 0; i < strlen(buf); i++) {
buf[i] = toupper(buf[i]);
size_t len = strlen(s);
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
for (size_t i = 0; i < len; i++) {
buf[i] = toupper(s[i]);
}
buf[len] = 0;
if (buf[0]==0 || strstr("1;TRUE;YES;ON", buf) != NULL) {
desc->value = 1;
desc->init = INITIALIZED;

View file

@ -12,7 +12,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-internal.h"
#include "mimalloc-atomic.h"
#include <string.h> // memset
#include <string.h> // strerror
#include <errno.h>
#if defined(_WIN32)
@ -211,7 +211,7 @@ static void* mi_win_virtual_alloc(void* addr, size_t size, size_t try_alignment,
if (use_large_os_page(size, try_alignment)) {
uintptr_t try_ok = mi_atomic_read(&large_page_try_ok);
if (try_ok > 0) {
// if a large page page allocation fails, it seems the calls to VirtualAlloc get very expensive.
// if a large page allocation fails, it seems the calls to VirtualAlloc get very expensive.
// therefore, once a large page allocation failed, we don't try again for `large_page_try_ok` times.
mi_atomic_compare_exchange(&large_page_try_ok, try_ok - 1, try_ok);
}

View file

@ -15,8 +15,6 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-internal.h"
#include "mimalloc-atomic.h"
#include <string.h> // memset, memcpy
/* -----------------------------------------------------------
Definition of page queues for each block size
----------------------------------------------------------- */