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

Implement fixed heap size for Julia #38

Merged
merged 6 commits into from
Mar 26, 2024

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented Feb 27, 2024

This PR introduces fixed heap size for stock Julia. With the build time option WITH_GC_FIXED_HEAP=1 and using --fixed-heap-size=..., it will bypass all the existing GC triggering heuristics, and only do GC when the heap size reaches the defined heap size, and will only do a full heap GC if the free memory after a GC is less than 20% of the heap size.

This PR also introduces a global counter for mallocd bytes. This will slow down the performance of malloc. For MMTK Julia, we also use such a counter (see mmtk/mmtk-julia#141). I plan to do another PR to fix this for both MMTK Julia and stock Julia.

Copy link

@d-netto d-netto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly SGTM.

The global counter for malloc may introduce too much contention on the corresponding cache line on allocation-heavy multithreaded workloads which increment this counter at a high rate.

If MMTk also does that then it's probably an apples-to-apples comparison.

@qinsoon
Copy link
Member Author

qinsoon commented Mar 6, 2024

The global counter for malloc may introduce too much contention on the corresponding cache line on allocation-heavy multithreaded workloads which increment this counter at a high rate.

If MMTk also does that then it's probably an apples-to-apples comparison.

Thanks for reviewing the PR. Yeah. I was concerned about this as well. MMTk/Julia uses a global counter like this, so for comparison, it is fine. But I will try measure the overhead. If this is a source of slowdown for MMTk/Julia, we should know about it.

@qinsoon
Copy link
Member Author

qinsoon commented Mar 11, 2024

The global counter for malloc may introduce too much contention on the corresponding cache line on allocation-heavy multithreaded workloads which increment this counter at a high rate.
If MMTk also does that then it's probably an apples-to-apples comparison.

Thanks for reviewing the PR. Yeah. I was concerned about this as well. MMTk/Julia uses a global counter like this, so for comparison, it is fine. But I will try measure the overhead. If this is a source of slowdown for MMTk/Julia, we should know about it.

It does have some measurable overhead. See mmtk/mmtk-julia#141.

@qinsoon qinsoon marked this pull request as ready for review March 21, 2024 23:03
@qinsoon
Copy link
Member Author

qinsoon commented Mar 21, 2024

@udesou Should we get this merged? Also let me know if you think we should have this change in master.

@qinsoon qinsoon requested a review from udesou March 21, 2024 23:04
@udesou
Copy link

udesou commented Mar 25, 2024

@udesou Should we get this merged? Also let me know if you think we should have this change in master.

I think so. I believe it doesn't impact stock if we don't have a fixed heap limit set, right? As in, standard stock remains the same. It would be nice to have it merged to make it more available and integrated with future changes we have, when we're testing it.

@qinsoon
Copy link
Member Author

qinsoon commented Mar 25, 2024

@udesou Should we get this merged? Also let me know if you think we should have this change in master.

I think so. I believe it doesn't impact stock if we don't have a fixed heap limit set, right? As in, standard stock remains the same. It would be nice to have it merged to make it more available and integrated with future changes we have, when we're testing it.

This impacts stock even if we don't use a fixed heap limit: 1. it adds a global counter for malloc, and it will slow down workloads that use malloc frequently. 2. it adds a check in the maybe_collect() to see if we have jl_options.fixed_heap_size set. This may introduce an overhead.

I can turn fixed heap size into a build-time option. In that case, there will be no overhead if we don't enable it in the build.

@qinsoon
Copy link
Member Author

qinsoon commented Mar 25, 2024

@udesou I have added a build-time flag WITH_GC_FIXED_HEAP. Can you review this PR again? Also let me know if I should open a PR to master as well.

@@ -574,6 +584,18 @@ void gc_setmark_buf(jl_ptls_t ptls, void *o, uint8_t mark_mode, size_t minsz) JL

inline void maybe_collect(jl_ptls_t ptls)
{
#ifdef GC_FIXED_HEAP
if (jl_options.fixed_heap_size) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need these internal ifs if you have defined GC_FIXED_HEAP? Aren't they redundant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a build with GC_FIXED_HEAP, you can still run with the stock heuristics if fixed_heap_size is not set. If you think it is a better idea to force using fixed_heap_size, I can change that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you're building fixed heap support when you use GC_FIXED_HEAP.
But if you do build with GC_FIXED_HEAP and use the stock heuristics you would pay the performance overhead you mentioned above right? Then you probably want to force using fixed_heap_size when you build with GC_FIXED_HEAP, or even add a warning to make it clear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a warning. I tried to make it a hard error. But the building process uses julia without setting a heap size. So better also keep the stock heuristics in place.

@qinsoon qinsoon merged commit bc23a6d into mmtk:v1.9.2+RAI Mar 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants