diff options
author | Cheng Shao <terrorjack@type.dance> | 2023-02-11 17:24:02 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-02-15 00:17:53 -0500 |
commit | 9ca51f9e84abc41ba590203d8bc8df8d6af86db2 (patch) | |
tree | 15920fff710ab7b5651f5728ea65dbcacd363016 /rts/sm/Storage.c | |
parent | 79d8fd6581af62e72727337001029533bf55e64f (diff) | |
download | haskell-9ca51f9e84abc41ba590203d8bc8df8d6af86db2.tar.gz |
rts: add the rts_clearMemory function
This patch adds the rts_clearMemory function that does its best to
zero out unused RTS memory for a wasm backend use case. See the
comment above rts_clearMemory() prototype declaration for more
detailed explanation. Closes #22920.
Diffstat (limited to 'rts/sm/Storage.c')
-rw-r--r-- | rts/sm/Storage.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index 40d8a45806..986f6dd15a 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -1924,3 +1924,46 @@ The compacting collector does nothing to improve megablock level fragmentation. The role of the compacting GC is to remove object level fragmentation and to use less memory when collecting. - see #19248 */ + +void rts_clearMemory(void) { + ACQUIRE_SM_LOCK; + + clear_free_list(); + + for (uint32_t i = 0; i < n_nurseries; ++i) { + for (bdescr *bd = nurseries[i].blocks; bd; bd = bd->link) { + clear_blocks(bd); + } + } + + for (unsigned int i = 0; i < getNumCapabilities(); ++i) { + for (bdescr *bd = getCapability(i)->pinned_object_empty; bd; bd = bd->link) { + clear_blocks(bd); + } + + for (bdescr *bd = gc_threads[i]->free_blocks; bd; bd = bd->link) { + clear_blocks(bd); + } + } + + if (RtsFlags.GcFlags.useNonmoving) + { + for (struct NonmovingSegment *seg = nonmovingHeap.free; seg; seg = seg->link) { + clear_segment(seg); + } + + for (int i = 0; i < NONMOVING_ALLOCA_CNT; ++i) { + struct NonmovingAllocator *alloc = nonmovingHeap.allocators[i]; + + for (struct NonmovingSegment *seg = alloc->active; seg; seg = seg->link) { + clear_segment_free_blocks(seg); + } + + for (unsigned int j = 0; j < getNumCapabilities(); ++j) { + clear_segment_free_blocks(alloc->current[j]); + } + } + } + + RELEASE_SM_LOCK; +} |