From 898a23ec2b4c7974d9381312f5ff01b78747a8d5 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 22 Oct 2021 08:12:14 +0100 Subject: [PATCH 1/4] fixes malloc_usable_size signature on FreeBSD. --- src/alloc-override.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alloc-override.c b/src/alloc-override.c index f97b6e78..af9035dd 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -173,7 +173,7 @@ extern "C" { void cfree(void* p) MI_FORWARD0(mi_free, p) void* reallocf(void* p, size_t newsize) MI_FORWARD2(mi_reallocf,p,newsize) size_t malloc_size(const void* p) MI_FORWARD1(mi_usable_size,p) -#if !defined(__ANDROID__) +#if !defined(__ANDROID__) && !defined(__FreeBSD__) size_t malloc_usable_size(void *p) MI_FORWARD1(mi_usable_size,p) #else size_t malloc_usable_size(const void *p) MI_FORWARD1(mi_usable_size,p) From fc7777ee8c7538fa181ae52c621c09edc11d46b7 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 22 Oct 2021 10:08:16 +0100 Subject: [PATCH 2/4] NUMA base detection on FreeBSD. --- src/os.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/os.c b/src/os.c index 3066dad5..f15a2197 100644 --- a/src/os.c +++ b/src/os.c @@ -51,6 +51,14 @@ terms of the MIT license. A copy of the license can be found in the file #include #endif #endif +#if defined(__FreeBSD__) +#include +#if __FreeBSD_version >= 1200000 +#include +#include +#include +#endif +#endif #endif /* ----------------------------------------------------------- @@ -1236,6 +1244,29 @@ static size_t mi_os_numa_node_countx(void) { } return (node+1); } +#elif defined(__FreeBSD__) && __FreeBSD_version >= 1200000 +static size_t mi_os_numa_nodex(void) { + domainset_t dom; + size_t node; + int policy; + + if (cpuset_getdomain(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, sizeof(dom), &dom, &policy) == -1) return 0ul; + + for (node = 0; node < MAXMEMDOM; node++) { + if (DOMAINSET_ISSET(node, &dom)) return node; + } + + return 0ul; +} + +static size_t mi_os_numa_node_countx(void) { + size_t ndomains = 0; + size_t len = sizeof(ndomains); + + if (sysctlbyname("vm.ndomains", &ndomains, &len, NULL, 0) == -1) return 0ul; + + return ndomains; +} #else static size_t mi_os_numa_nodex(void) { return 0; From 2d2d9af5c6e2473b8aa6b651b0dad7d67b8957f8 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 24 Oct 2021 10:57:40 +0100 Subject: [PATCH 3/4] while at it, doing dragonflybsd too --- src/os.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/os.c b/src/os.c index f15a2197..a4b9602f 100644 --- a/src/os.c +++ b/src/os.c @@ -51,13 +51,13 @@ terms of the MIT license. A copy of the license can be found in the file #include #endif #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__) #include #if __FreeBSD_version >= 1200000 #include #include -#include #endif +#include #endif #endif @@ -1267,6 +1267,24 @@ static size_t mi_os_numa_node_countx(void) { return ndomains; } +#elif defined(__DragonFly__) +static size_t mi_os_numa_nodex(void) { + // TODO DragonFlyBSD does not seem to provide any userland mean to + // check this information, even less the possibility to control + // the allocation to a logical core level's granularity, only the kernel + // is fully NUMA aware at the moment. + return 0ul; +} + +static size_t mi_os_numa_node_countx(void) { + size_t ncpus = 0, nvirtcoresperphys = 0; + size_t len = sizeof(size_t); + + if (sysctlbyname("hw.ncpu", &ncpus, &len, NULL, 0) == -1) return 0ul; + if (sysctlbyname("hw.cpu_topology_ht_ids", &nvirtcoresperphys, &len, NULL, 0) == -1) return 0ul; + + return nvirtcoresperphys * ncpus; +} #else static size_t mi_os_numa_nodex(void) { return 0; From ca9785d40e8c225f5176f2dfba502ab351da8d9c Mon Sep 17 00:00:00 2001 From: Daan Date: Wed, 27 Oct 2021 10:06:34 -0700 Subject: [PATCH 4/4] fix compilation with MI_DEBUG>3, issue #480 --- src/page.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/page.c b/src/page.c index 033976dc..7efbcb8d 100644 --- a/src/page.c +++ b/src/page.c @@ -84,9 +84,10 @@ static bool mi_page_is_valid_init(mi_page_t* page) { mi_assert_internal(mi_page_list_is_valid(page,page->local_free)); #if MI_DEBUG>3 // generally too expensive to check this - if (page->flags.is_zero) { - for(mi_block_t* block = page->free; block != NULL; mi_block_next(page,block)) { - mi_assert_expensive(mi_mem_is_zero(block + 1, page->block_size - sizeof(mi_block_t))); + if (page->is_zero) { + const size_t ubsize = mi_page_usable_block_size(page); + for(mi_block_t* block = page->free; block != NULL; block = mi_block_next(page,block)) { + mi_assert_expensive(mi_mem_is_zero(block + 1, ubsize - sizeof(mi_block_t))); } } #endif