diff options
author | Sverker Eriksson <[email protected]> | 2015-06-10 20:59:05 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2015-06-15 15:24:16 +0200 |
commit | f5138184479bd16c0ee0a5e583479378451401c8 (patch) | |
tree | 85d32701fb3dde71fa74bbbb5c6b0087d7f399be /erts/emulator/beam/erl_message.c | |
parent | 7c1ed37b4aa173181c4d45a2108f5eef4c36c41e (diff) | |
download | otp-f5138184479bd16c0ee0a5e583479378451401c8.tar.gz otp-f5138184479bd16c0ee0a5e583479378451401c8.tar.bz2 otp-f5138184479bd16c0ee0a5e583479378451401c8.zip |
erts: Add erts_factory_trim_and_close
Diffstat (limited to 'erts/emulator/beam/erl_message.c')
-rw-r--r-- | erts/emulator/beam/erl_message.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/erts/emulator/beam/erl_message.c b/erts/emulator/beam/erl_message.c index 13e084ce10..f806d2c498 100644 --- a/erts/emulator/beam/erl_message.c +++ b/erts/emulator/beam/erl_message.c @@ -93,9 +93,6 @@ erts_resize_message_buffer(ErlHeapFragment *bp, Uint size, #endif ErlHeapFragment* nbp; - /* ToDo: Make use of 'used_size' to avoid realloc - when shrinking just a few words */ - #ifdef DEBUG { Uint off_sz = size < bp->used_size ? size : bp->used_size; @@ -110,8 +107,10 @@ erts_resize_message_buffer(ErlHeapFragment *bp, Uint size, } #endif - if (size == bp->used_size) + if (size >= (bp->used_size - bp->used_size / 16)) { + bp->used_size = size; return bp; + } #ifdef HARD_DEBUG dbg_brefs = erts_alloc(ERTS_ALC_T_UNDEF, sizeof(Eterm *)*brefs_size); @@ -1288,6 +1287,24 @@ void erts_factory_close(ErtsHeapFactory* factory) factory->mode = FACTORY_CLOSED; } +void erts_factory_trim_and_close(ErtsHeapFactory* factory, + Eterm *brefs, Uint brefs_size) +{ + if (factory->mode == FACTORY_HEAP_FRAGS) { + ErlHeapFragment* bp = factory->heap_frags; + if (bp->next == NULL) { + Uint used_sz = factory->hp - bp->mem; + ASSERT(used_sz <= bp->alloc_size); + factory->heap_frags = erts_resize_message_buffer(bp, used_sz, + brefs, brefs_size); + factory->mode = FACTORY_CLOSED; + return; + } + /*else we don't trim multi fragmented messages for now */ + } + erts_factory_close(factory); +} + void erts_factory_undo(ErtsHeapFactory* factory) { ErlHeapFragment* bp; |