Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store real end of stack when thread suspends for amd64 #2640

Merged
merged 1 commit into from
Mar 5, 2025
Merged

Conversation

seven1m
Copy link
Member

@seven1m seven1m commented Mar 4, 2025

This reduces the amount of memory the GC needs to scan during pauses. Before, we were scanning the full 8 Mb or whatever of stack space for each thread; now we just scan what is actually in use.

Using this code as a benchmark:

threads = 1000.times.map do
  Thread.new do
    sleep
  end
end

Thread.pass until threads.all?(&:stop?)

10.times do
  print '.'
  GC.start
end

puts 'GC done'

threads.each(&:wakeup)
threads.each(&:join)

The results are dramatic:

time ./t1
..........GC done
./t1  13.95s user 1.26s system 101% cpu 14.956 total

→ time ./t2
..........GC done
./t2  0.09s user 0.22s system 210% cpu 0.147 total

Caveats:

This doesn't help on Darwin, as we use a different technique to suspend Darwin threads.

I don't have an Arm processor with Linux, so I'm not sure what kind of code we'd need for that. We can add other architectures later.

This reduces the amount of memory the GC needs to scan during pauses.

This doesn't affect Darwin, as we use a different technique to suspend
Darwin threads.

I don't have an Arm processor with Linux, so I'm not sure what kind of
code we'd need for that. We can add other architectures later.
@seven1m seven1m marked this pull request as ready for review March 4, 2025 14:18
@seven1m seven1m merged commit e1c115e into master Mar 5, 2025
19 checks passed
@seven1m seven1m deleted the gc-thread-sp branch March 5, 2025 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant