mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 23:19:31 +03:00
Merge pull request #654 from dscho/git-for-windows-assorted-fixes
Assorted fixes from the Git for Windows project
This commit is contained in:
commit
59ea84cadc
66 changed files with 828 additions and 782 deletions
|
@ -1790,4 +1790,3 @@ tt, code, kbd, samp
|
||||||
u {
|
u {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,4 +143,3 @@
|
||||||
#nav-tree { display: none; }
|
#nav-tree { display: none; }
|
||||||
div.ui-resizable-handle { display: none; position: relative; }
|
div.ui-resizable-handle { display: none; position: relative; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,4 +270,3 @@ DIV.searchresults {
|
||||||
.searchpages {
|
.searchpages {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,4 +36,3 @@ var indexSectionLabels =
|
||||||
7: "Modules",
|
7: "Modules",
|
||||||
8: "Pages"
|
8: "Pages"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,4 +58,3 @@
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0);
|
text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -755,4 +755,3 @@ free list encoding](https://github.com/microsoft/mimalloc/blob/783e3377f79ee82af
|
||||||
* 2019-10-07, `v1.1.0`: stable release 1.1.
|
* 2019-10-07, `v1.1.0`: stable release 1.1.
|
||||||
* 2019-09-01, `v1.0.8`: pre-release 8: more robust windows dynamic overriding, initial huge page support.
|
* 2019-09-01, `v1.0.8`: pre-release 8: more robust windows dynamic overriding, initial huge page support.
|
||||||
* 2019-08-10, `v1.0.6`: pre-release 6: various performance improvements.
|
* 2019-08-10, `v1.0.6`: pre-release 6: various performance improvements.
|
||||||
|
|
||||||
|
|
|
@ -306,4 +306,3 @@ mi_decl_nodiscard void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t
|
||||||
mi_decl_nodiscard void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment) mi_attr_noexcept {
|
mi_decl_nodiscard void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment) mi_attr_noexcept {
|
||||||
return mi_heap_recalloc_aligned(mi_get_default_heap(), p, newcount, size, alignment);
|
return mi_heap_recalloc_aligned(mi_get_default_heap(), p, newcount, size, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,8 +180,15 @@ static void mi_cdecl mi_out_stderr(const char* msg, void* arg) {
|
||||||
if (!_mi_preloading()) {
|
if (!_mi_preloading()) {
|
||||||
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
|
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
|
||||||
static HANDLE hcon = INVALID_HANDLE_VALUE;
|
static HANDLE hcon = INVALID_HANDLE_VALUE;
|
||||||
|
static int write_to_console;
|
||||||
if (hcon == INVALID_HANDLE_VALUE) {
|
if (hcon == INVALID_HANDLE_VALUE) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||||
hcon = GetStdHandle(STD_ERROR_HANDLE);
|
hcon = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
write_to_console = GetConsoleScreenBufferInfo(hcon, &sbi) ? 1 : 0;
|
||||||
|
}
|
||||||
|
if (!write_to_console) {
|
||||||
|
fputs(msg, stderr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const size_t len = strlen(msg);
|
const size_t len = strlen(msg);
|
||||||
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {
|
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {
|
||||||
|
@ -347,7 +354,7 @@ void _mi_fprintf( mi_output_fun* out, void* arg, const char* fmt, ... ) {
|
||||||
static void mi_vfprintf_thread(mi_output_fun* out, void* arg, const char* prefix, const char* fmt, va_list args) {
|
static void mi_vfprintf_thread(mi_output_fun* out, void* arg, const char* prefix, const char* fmt, va_list args) {
|
||||||
if (prefix != NULL && strlen(prefix) <= 32 && !_mi_is_main_thread()) {
|
if (prefix != NULL && strlen(prefix) <= 32 && !_mi_is_main_thread()) {
|
||||||
char tprefix[64];
|
char tprefix[64];
|
||||||
snprintf(tprefix, sizeof(tprefix), "%sthread 0x%zx: ", prefix, _mi_thread_id());
|
snprintf(tprefix, sizeof(tprefix), "%sthread 0x%llx: ", prefix, (unsigned long long)_mi_thread_id());
|
||||||
mi_vfprintf(out, arg, tprefix, fmt, args);
|
mi_vfprintf(out, arg, tprefix, fmt, args);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
7
src/os.c
7
src/os.c
|
@ -177,9 +177,11 @@ typedef struct MI_PROCESSOR_NUMBER_S { WORD Group; BYTE Number; BYTE Reserved; }
|
||||||
typedef VOID (__stdcall *PGetCurrentProcessorNumberEx)(MI_PROCESSOR_NUMBER* ProcNumber);
|
typedef VOID (__stdcall *PGetCurrentProcessorNumberEx)(MI_PROCESSOR_NUMBER* ProcNumber);
|
||||||
typedef BOOL (__stdcall *PGetNumaProcessorNodeEx)(MI_PROCESSOR_NUMBER* Processor, PUSHORT NodeNumber);
|
typedef BOOL (__stdcall *PGetNumaProcessorNodeEx)(MI_PROCESSOR_NUMBER* Processor, PUSHORT NodeNumber);
|
||||||
typedef BOOL (__stdcall* PGetNumaNodeProcessorMaskEx)(USHORT Node, PGROUP_AFFINITY ProcessorMask);
|
typedef BOOL (__stdcall* PGetNumaNodeProcessorMaskEx)(USHORT Node, PGROUP_AFFINITY ProcessorMask);
|
||||||
|
typedef BOOL (__stdcall *PGetNumaProcessorNode)(UCHAR Processor, PUCHAR NodeNumber);
|
||||||
static PGetCurrentProcessorNumberEx pGetCurrentProcessorNumberEx = NULL;
|
static PGetCurrentProcessorNumberEx pGetCurrentProcessorNumberEx = NULL;
|
||||||
static PGetNumaProcessorNodeEx pGetNumaProcessorNodeEx = NULL;
|
static PGetNumaProcessorNodeEx pGetNumaProcessorNodeEx = NULL;
|
||||||
static PGetNumaNodeProcessorMaskEx pGetNumaNodeProcessorMaskEx = NULL;
|
static PGetNumaNodeProcessorMaskEx pGetNumaNodeProcessorMaskEx = NULL;
|
||||||
|
static PGetNumaProcessorNode pGetNumaProcessorNode = NULL;
|
||||||
|
|
||||||
static bool mi_win_enable_large_os_pages(void)
|
static bool mi_win_enable_large_os_pages(void)
|
||||||
{
|
{
|
||||||
|
@ -245,6 +247,7 @@ void _mi_os_init(void)
|
||||||
pGetCurrentProcessorNumberEx = (PGetCurrentProcessorNumberEx)(void (*)(void))GetProcAddress(hDll, "GetCurrentProcessorNumberEx");
|
pGetCurrentProcessorNumberEx = (PGetCurrentProcessorNumberEx)(void (*)(void))GetProcAddress(hDll, "GetCurrentProcessorNumberEx");
|
||||||
pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNodeEx");
|
pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNodeEx");
|
||||||
pGetNumaNodeProcessorMaskEx = (PGetNumaNodeProcessorMaskEx)(void (*)(void))GetProcAddress(hDll, "GetNumaNodeProcessorMaskEx");
|
pGetNumaNodeProcessorMaskEx = (PGetNumaNodeProcessorMaskEx)(void (*)(void))GetProcAddress(hDll, "GetNumaNodeProcessorMaskEx");
|
||||||
|
pGetNumaProcessorNode = (PGetNumaProcessorNode)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNode");
|
||||||
FreeLibrary(hDll);
|
FreeLibrary(hDll);
|
||||||
}
|
}
|
||||||
if (mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
if (mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
||||||
|
@ -1348,11 +1351,11 @@ static size_t mi_os_numa_nodex(void) {
|
||||||
BOOL ok = (*pGetNumaProcessorNodeEx)(&pnum, &nnode);
|
BOOL ok = (*pGetNumaProcessorNodeEx)(&pnum, &nnode);
|
||||||
if (ok) numa_node = nnode;
|
if (ok) numa_node = nnode;
|
||||||
}
|
}
|
||||||
else {
|
else if (pGetNumaProcessorNode != NULL) {
|
||||||
// Vista or earlier, use older API that is limited to 64 processors. Issue #277
|
// Vista or earlier, use older API that is limited to 64 processors. Issue #277
|
||||||
DWORD pnum = GetCurrentProcessorNumber();
|
DWORD pnum = GetCurrentProcessorNumber();
|
||||||
UCHAR nnode = 0;
|
UCHAR nnode = 0;
|
||||||
BOOL ok = GetNumaProcessorNode((UCHAR)pnum, &nnode);
|
BOOL ok = pGetNumaProcessorNode((UCHAR)pnum, &nnode);
|
||||||
if (ok) numa_node = nnode;
|
if (ok) numa_node = nnode;
|
||||||
}
|
}
|
||||||
return numa_node;
|
return numa_node;
|
||||||
|
|
23
src/random.c
23
src/random.c
|
@ -187,10 +187,27 @@ static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
|
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#pragma comment (lib,"bcrypt.lib")
|
|
||||||
#include <bcrypt.h>
|
#ifndef BCRYPT_USE_SYSTEM_PREFERRED_RNG
|
||||||
|
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef LONG (NTAPI *PBCryptGenRandom)(HANDLE, PUCHAR, ULONG, ULONG);
|
||||||
|
static PBCryptGenRandom pBCryptGenRandom = NULL;
|
||||||
|
static int BCryptGenRandom_is_initialized = 0;
|
||||||
|
|
||||||
static bool os_random_buf(void* buf, size_t buf_len) {
|
static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
if (!BCryptGenRandom_is_initialized) {
|
||||||
|
HINSTANCE hDll;
|
||||||
|
hDll = LoadLibrary(TEXT("bcrypt.dll"));
|
||||||
|
if (hDll != NULL) {
|
||||||
|
pBCryptGenRandom = (PBCryptGenRandom)(void (*)(void))GetProcAddress(hDll, "BCryptGenRandom");
|
||||||
|
}
|
||||||
|
BCryptGenRandom_is_initialized = 1;
|
||||||
|
}
|
||||||
|
if (!pBCryptGenRandom)
|
||||||
|
return 0;
|
||||||
|
return (pBCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
45
src/stats.c
45
src/stats.c
|
@ -465,8 +465,6 @@ mi_msecs_t _mi_clock_end(mi_msecs_t start) {
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <psapi.h>
|
|
||||||
#pragma comment(lib,"psapi.lib")
|
|
||||||
|
|
||||||
static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
|
static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
|
||||||
ULARGE_INTEGER i;
|
ULARGE_INTEGER i;
|
||||||
|
@ -476,6 +474,23 @@ static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
|
||||||
return msecs;
|
return msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct _PROCESS_MEMORY_COUNTERS {
|
||||||
|
DWORD cb;
|
||||||
|
DWORD PageFaultCount;
|
||||||
|
SIZE_T PeakWorkingSetSize;
|
||||||
|
SIZE_T WorkingSetSize;
|
||||||
|
SIZE_T QuotaPeakPagedPoolUsage;
|
||||||
|
SIZE_T QuotaPagedPoolUsage;
|
||||||
|
SIZE_T QuotaPeakNonPagedPoolUsage;
|
||||||
|
SIZE_T QuotaNonPagedPoolUsage;
|
||||||
|
SIZE_T PagefileUsage;
|
||||||
|
SIZE_T PeakPagefileUsage;
|
||||||
|
} PROCESS_MEMORY_COUNTERS;
|
||||||
|
typedef PROCESS_MEMORY_COUNTERS* PPROCESS_MEMORY_COUNTERS;
|
||||||
|
typedef BOOL (WINAPI *PGetProcessMemoryInfo)(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
|
||||||
|
static PGetProcessMemoryInfo pGetProcessMemoryInfo = NULL;
|
||||||
|
static int GetProcessMemoryInfo_is_initialized = 0;
|
||||||
|
|
||||||
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
||||||
{
|
{
|
||||||
*elapsed = _mi_clock_end(mi_process_start);
|
*elapsed = _mi_clock_end(mi_process_start);
|
||||||
|
@ -487,12 +502,25 @@ static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msec
|
||||||
*utime = filetime_msecs(&ut);
|
*utime = filetime_msecs(&ut);
|
||||||
*stime = filetime_msecs(&st);
|
*stime = filetime_msecs(&st);
|
||||||
PROCESS_MEMORY_COUNTERS info;
|
PROCESS_MEMORY_COUNTERS info;
|
||||||
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
|
|
||||||
*current_rss = (size_t)info.WorkingSetSize;
|
if (!GetProcessMemoryInfo_is_initialized) {
|
||||||
*peak_rss = (size_t)info.PeakWorkingSetSize;
|
HINSTANCE hDll;
|
||||||
*current_commit = (size_t)info.PagefileUsage;
|
hDll = LoadLibrary(TEXT("psapi.dll"));
|
||||||
*peak_commit = (size_t)info.PeakPagefileUsage;
|
if (hDll != NULL) {
|
||||||
*page_faults = (size_t)info.PageFaultCount;
|
pGetProcessMemoryInfo = (PGetProcessMemoryInfo)(void (*)(void))GetProcAddress(hDll, "GetProcessMemoryInfo");
|
||||||
|
}
|
||||||
|
GetProcessMemoryInfo_is_initialized = 1;
|
||||||
|
}
|
||||||
|
if (pGetProcessMemoryInfo) {
|
||||||
|
pGetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
|
||||||
|
*current_rss = (size_t)info.WorkingSetSize;
|
||||||
|
*peak_rss = (size_t)info.PeakWorkingSetSize;
|
||||||
|
*current_commit = (size_t)info.PagefileUsage;
|
||||||
|
*peak_commit = (size_t)info.PeakPagefileUsage;
|
||||||
|
*page_faults = (size_t)info.PageFaultCount;
|
||||||
|
} else {
|
||||||
|
*current_rss = *peak_rss = *current_commit = *peak_commit = *page_faults = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif !defined(__wasi__) && (defined(__unix__) || defined(__unix) || defined(unix) || defined(__APPLE__) || defined(__HAIKU__))
|
#elif !defined(__wasi__) && (defined(__unix__) || defined(__unix) || defined(unix) || defined(__APPLE__) || defined(__HAIKU__))
|
||||||
|
@ -589,4 +617,3 @@ mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, s
|
||||||
if (peak_commit!=NULL) *peak_commit = peak_commit0;
|
if (peak_commit!=NULL) *peak_commit = peak_commit0;
|
||||||
if (page_faults!=NULL) *page_faults = page_faults0;
|
if (page_faults!=NULL) *page_faults = page_faults0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,4 +383,3 @@ static void mi_bins(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue