Sweeping with single-threaded GC

17 views
Skip to first unread message

Erik Corry

unread,
Nov 13, 2024, 10:42:30 AM11/13/24
to v8-...@googlegroups.com
We run with --single-threaded-gc.  It looks like no sweeping of old space takes place until the next old-space GC starts up.  Does this sound likely?  I'm putting a breakpoint in Sweeper::RawSweep, and it's not hit between old-space-GCs, even though the GC state is SWEEPING.  Is there
a different place that does the sweeping work?

Omer Katz (chromium.org)

unread,
Nov 13, 2024, 10:56:59 AM11/13/24
to v8-...@googlegroups.com
Sweeping happens either concurrently (disabled by --single-threaded-gc) or on allocation if we will otherwise run out of memory.
It's possible that you don't hit the cases that would require sweeping on allocation.

On Wed, Nov 13, 2024 at 4:49 PM Erik Corry <erik...@chromium.org> wrote:
We run with --single-threaded-gc.  It looks like no sweeping of old space takes place until the next old-space GC starts up.  Does this sound likely?  I'm putting a breakpoint in Sweeper::RawSweep, and it's not hit between old-space-GCs, even though the GC state is SWEEPING.  Is there
a different place that does the sweeping work?

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/v8-dev/CAHZxHpiAZ0EQNJFmubnwvVxtVAu1vJTFg-1AXNEXeX8ojMqazg%40mail.gmail.com.

Erik Corry

unread,
Nov 14, 2024, 3:30:43 PM11/14/24
to v8-...@googlegroups.com
I see.  I was just confused because the GC state stays in SWEEPING until the next big GC, even when all pages have been swept.

Omer Katz (chromium.org)

unread,
Nov 15, 2024, 4:10:15 AM11/15/24
to v8-...@googlegroups.com
Hi Erik,

Yeah, I see how that can be confusing.
In my previous answer I assumed you meant there are pages that are only swept when we start the next GC, which is uncommon but possible.
What you're describing now, where all pages are swept but the GC remains in a sweeping state, is very likely and intentional.

Sweeping the pages can happen either concurrently or during allocations.
Switching state happens after all pages are swept but can be delayed.
Finalizing sweeping, and the state change that goes with it, requires some accounting work which, for performance reasons, we don't want to do during an allocation (it also has to happen on the main thread so can be concurrent).
Therefore the state remains as is until we can "safely" (i.e. without incurring an unnecessary performance cost) finalize sweeping, which is usually when we start the next GC (minor or major).

I hope that clarifies things.

Omer

Erik Corry

unread,
Nov 15, 2024, 4:23:48 AM11/15/24
to v8-...@googlegroups.com
Thanks for the clarification, but the state doesn't flip on the next minor GC, it has to wait for the next major GC.

On a minor GC the state is saved in previous_ and after the minor GC it is restored, so nothing that happens in the minor GC can change the state from SWEEPING to NOT_RUNNING.

It probably doesn't matter.  Presumably the distinction between SWEEPING and NOT_RUNNING doesn't affect performance?

Omer Katz (chromium.org)

unread,
Nov 15, 2024, 4:27:53 AM11/15/24
to v8-...@googlegroups.com
The state can change on minor GC (before it the GC is even started) if all pages are already swept.
Since you disable concurrent sweeping, most likely not all pages are swept, thus the state does not change.

Reply all
Reply to author
Forward
0 new messages