[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Hybird GC issues in lua 5.4
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Mon, 21 Dec 2020 15:20:12 +0800
We switched to lua 5.4 in our new online game project , and tried
1. Major cycle is too slow to accept. （More than 1 second stop-the-world)
2. Minor cycle is good, it's fast and it reduces the rate of memory
growth and the peak memory usage.
We tried a hybird mode between incremental gc and generational gc.
1. Stop the automatic collector. Memory allocate driven collector is
not suitable in our case.
2. We use a timer to call gc step manually. Every time we call lua_gc
with LUA_GCSTEP, we measure the time the collector cost, and do not
let the time too long. That is to say, we use a time-driven collector
rather than allocate-driven collector.
3. We use generational mode at start, run some minor/young cycles, and
when the total memory increased to a threshold value, we switch it to
incremental mode, and switch back after a full cycle (It goes through
a number of steps).
They works fine except enterinc(). When switching from generational to
incremental , it stop-the-world about 100ms~400ms / 1GB memory.
I guess the reason is `whitelist(g, g->allgc)`. It traverses all the
object. Is it possible to improved this in future ? I think it's not
very diffcult, we can add a stage something like GCSenterinc before
Another issue is about the memory layout of TString.
I think using a pointer to hold the string data would be better the
putting the data into a continuous TString structure.
Although an additonal pointer would waste 4/8 bytes memory, but
TString object can be a small fixed size object. It's more
cache-friendly to GC , and many general purpose allocator could manage
small objects more efficiently.