mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-03 14:09:31 +03:00
possible fix for wrong accounting of committed bytes (issue #1035)
This commit is contained in:
parent
f11732acdf
commit
9a35bca556
1 changed files with 5 additions and 4 deletions
|
@ -648,15 +648,16 @@ void _mi_arena_free(void* p, size_t size, size_t committed_size, mi_memid_t memi
|
||||||
if (p==NULL) return;
|
if (p==NULL) return;
|
||||||
if (size==0) return;
|
if (size==0) return;
|
||||||
const bool all_committed = (committed_size == size);
|
const bool all_committed = (committed_size == size);
|
||||||
|
const bool decommitted_size = (committed_size <= size ? size - committed_size : 0);
|
||||||
|
|
||||||
// need to set all memory to undefined as some parts may still be marked as no_access (like padding etc.)
|
// need to set all memory to undefined as some parts may still be marked as no_access (like padding etc.)
|
||||||
mi_track_mem_undefined(p,size);
|
mi_track_mem_undefined(p,size);
|
||||||
|
|
||||||
if (mi_memkind_is_os(memid.memkind)) {
|
if (mi_memkind_is_os(memid.memkind)) {
|
||||||
// was a direct OS allocation, pass through
|
// was a direct OS allocation, pass through
|
||||||
if (!all_committed && committed_size > 0) {
|
if (!all_committed && decommitted_size > 0) {
|
||||||
// if partially committed, adjust the committed stats (as `_mi_os_free` will increase decommit by the full size)
|
// if partially committed, adjust the committed stats (as `_mi_os_free` will decrease commit by the full size)
|
||||||
_mi_stat_decrease(&_mi_stats_main.committed, committed_size);
|
_mi_stat_increase(&_mi_stats_main.committed, decommitted_size);
|
||||||
}
|
}
|
||||||
_mi_os_free(p, size, memid);
|
_mi_os_free(p, size, memid);
|
||||||
}
|
}
|
||||||
|
@ -695,7 +696,7 @@ void _mi_arena_free(void* p, size_t size, size_t committed_size, mi_memid_t memi
|
||||||
mi_track_mem_noaccess(p,size);
|
mi_track_mem_noaccess(p,size);
|
||||||
if (committed_size > 0) {
|
if (committed_size > 0) {
|
||||||
// if partially committed, adjust the committed stats (is it will be recommitted when re-using)
|
// if partially committed, adjust the committed stats (is it will be recommitted when re-using)
|
||||||
// in the delayed purge, we now need to not count a decommit if the range is not marked as committed.
|
// in the delayed purge, we do no longer decrease the commit if the range is not marked entirely as committed.
|
||||||
_mi_stat_decrease(&_mi_stats_main.committed, committed_size);
|
_mi_stat_decrease(&_mi_stats_main.committed, committed_size);
|
||||||
}
|
}
|
||||||
// note: if not all committed, it may be that the purge will reset/decommit the entire range
|
// note: if not all committed, it may be that the purge will reset/decommit the entire range
|
||||||
|
|
Loading…
Add table
Reference in a new issue