mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
merge from dev
This commit is contained in:
commit
b3b0fb5832
3 changed files with 32 additions and 10 deletions
|
@ -799,13 +799,14 @@ static inline uintptr_t _mi_random_shuffle(uintptr_t x) {
|
||||||
int _mi_os_numa_node_get(mi_os_tld_t* tld);
|
int _mi_os_numa_node_get(mi_os_tld_t* tld);
|
||||||
size_t _mi_os_numa_node_count_get(void);
|
size_t _mi_os_numa_node_count_get(void);
|
||||||
|
|
||||||
extern size_t _mi_numa_node_count;
|
extern _Atomic(size_t) _mi_numa_node_count;
|
||||||
static inline int _mi_os_numa_node(mi_os_tld_t* tld) {
|
static inline int _mi_os_numa_node(mi_os_tld_t* tld) {
|
||||||
if (mi_likely(_mi_numa_node_count == 1)) return 0;
|
if (mi_likely(mi_atomic_load_relaxed(&_mi_numa_node_count) == 1)) return 0;
|
||||||
else return _mi_os_numa_node_get(tld);
|
else return _mi_os_numa_node_get(tld);
|
||||||
}
|
}
|
||||||
static inline size_t _mi_os_numa_node_count(void) {
|
static inline size_t _mi_os_numa_node_count(void) {
|
||||||
if (mi_likely(_mi_numa_node_count>0)) return _mi_numa_node_count;
|
const size_t count = mi_atomic_load_relaxed(&_mi_numa_node_count);
|
||||||
|
if (mi_likely(count>0)) return count;
|
||||||
else return _mi_os_numa_node_count_get();
|
else return _mi_os_numa_node_count_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
src/os.c
20
src/os.c
|
@ -1214,17 +1214,23 @@ static size_t mi_os_numa_node_countx(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t _mi_numa_node_count = 0; // cache the node count
|
_Atomic(size_t) _mi_numa_node_count; // = 0 // cache the node count
|
||||||
|
|
||||||
size_t _mi_os_numa_node_count_get(void) {
|
size_t _mi_os_numa_node_count_get(void) {
|
||||||
if (mi_unlikely(_mi_numa_node_count <= 0)) {
|
size_t count = mi_atomic_load_acquire(&_mi_numa_node_count);
|
||||||
|
if (count <= 0) {
|
||||||
long ncount = mi_option_get(mi_option_use_numa_nodes); // given explicitly?
|
long ncount = mi_option_get(mi_option_use_numa_nodes); // given explicitly?
|
||||||
if (ncount <= 0) ncount = (long)mi_os_numa_node_countx(); // or detect dynamically
|
if (ncount > 0) {
|
||||||
_mi_numa_node_count = (size_t)(ncount <= 0 ? 1 : ncount);
|
count = (size_t)ncount;
|
||||||
_mi_verbose_message("using %zd numa regions\n", _mi_numa_node_count);
|
|
||||||
}
|
}
|
||||||
mi_assert_internal(_mi_numa_node_count >= 1);
|
else {
|
||||||
return _mi_numa_node_count;
|
count = mi_os_numa_node_countx(); // or detect dynamically
|
||||||
|
if (count == 0) count = 1;
|
||||||
|
}
|
||||||
|
mi_atomic_store_release(&_mi_numa_node_count, count); // save it
|
||||||
|
_mi_verbose_message("using %zd numa regions\n", count);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _mi_os_numa_node_get(mi_os_tld_t* tld) {
|
int _mi_os_numa_node_get(mi_os_tld_t* tld) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ void various_tests();
|
||||||
void test_mt_shutdown();
|
void test_mt_shutdown();
|
||||||
void large_alloc(void); // issue #363
|
void large_alloc(void); // issue #363
|
||||||
void fail_aslr(); // issue #372
|
void fail_aslr(); // issue #372
|
||||||
|
void tsan_numa_test(); // issue #414
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
mi_stats_reset(); // ignore earlier allocations
|
mi_stats_reset(); // ignore earlier allocations
|
||||||
|
@ -44,6 +45,8 @@ int main() {
|
||||||
padding_shrink();
|
padding_shrink();
|
||||||
various_tests();
|
various_tests();
|
||||||
large_alloc();
|
large_alloc();
|
||||||
|
tsan_numa_test();
|
||||||
|
|
||||||
//test_mt_shutdown();
|
//test_mt_shutdown();
|
||||||
//fail_aslr();
|
//fail_aslr();
|
||||||
mi_stats_print(NULL);
|
mi_stats_print(NULL);
|
||||||
|
@ -232,3 +235,15 @@ void fail_aslr() {
|
||||||
printf("pointer p: %p: area up to %p\n", p, (uint8_t*)p + sz);
|
printf("pointer p: %p: area up to %p\n", p, (uint8_t*)p + sz);
|
||||||
*(int*)0x5FFFFFFF000 = 0; // should segfault
|
*(int*)0x5FFFFFFF000 = 0; // should segfault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issues #414
|
||||||
|
void dummy_worker() {
|
||||||
|
void* p = mi_malloc(0);
|
||||||
|
mi_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tsan_numa_test() {
|
||||||
|
auto t1 = std::thread(dummy_worker);
|
||||||
|
dummy_worker();
|
||||||
|
t1.join();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue