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

Move heap ownership info from chunk to pagemap #4368

Merged
merged 4 commits into from
Aug 1, 2023

Conversation

dipinhora
Copy link
Contributor

Prior to this commit, the chunk kept track of the heap ownership info in the chunk->actor field. This worked but was not ideal as noted in the ponyint_heap_owner function that this is a case of false sharing where the chunk owner needs the chunk but all other actors only need the chunk owner only. This led to lots of pointer chasing as the pagemap was used to retrieve the chunk pointerand then the chunk had to be loaded to retrieve the owning actor pointer.

This commit removes the chunk->actor field further slimming down both the small_chunk and large_chunk so both now fit within 32 bytes (on 64 bit architectures). The chunk ownership information is now kept in the lowest level of the pagemap next to the chunk information. This removes the previous pointer chasing because the chunk owning actor pointer is retrieved at the same time as the chunk pointer without needing to load the chunk itself. This is a fairly standard tradeoff of memory for performance where we're now storing more data in the pagemap to minimize pointer chasing. The expectation is that this will have a net positive impact on performance but no benchmarks have been run to validate this assumption.

Prior to this commit, the chunk kept track of the heap ownership
info in the `chunk->actor` field. This worked but was not ideal
as noted in the `ponyint_heap_owner` function that this is a case
of false sharing where the chunk owner needs the chunk but
all other actors only need the chunk owner only. This led to lots
of pointer chasing as the pagemap was used to retrieve the chunk
pointerand then the chunk had to be loaded to retrieve the owning
actor pointer.

This commit removes the `chunk->actor` field further slimming down
both the `small_chunk` and `large_chunk` so both now fit within
32 bytes (on 64 bit architectures). The chunk ownership information
is now kept in the lowest level of the pagemap next to the chunk
information. This removes the previous pointer chasing because
the chunk owning actor pointer is retrieved at the same time as the
chunk pointer without needing to load the chunk itself. This is a
fairly standard tradeoff of memory for performance where we're now
storing more data in the pagemap to minimize pointer chasing. The
expectation is that this will have a net positive impact on
performance but no benchmarks have been run to validate this
assumption.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jul 22, 2023
@SeanTAllen SeanTAllen added the changelog - changed Automatically add "Changed" CHANGELOG entry on merge label Jul 25, 2023
@ponylang-main
Copy link
Contributor

Hi @dipinhora,

The changelog - changed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 4368.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

return chunk;
}

chunk_t* ponyint_pagemap_get(const void* addr, pony_actor_t** actor)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should get a bit of documentation that actor is being set. It took me a bit to figure that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment.. let me know if it's not clear enough..

return chunk;
}

chunk_t* ponyint_pagemap_get(const void* addr, pony_actor_t** actor)
Copy link
Member

Choose a reason for hiding this comment

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

I think noting why we have a return chunk_t and and out parameter actor rather than two out parameters, would be good documentation for this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment.. let me know if it's not clear enough..

pony_assert(ix <= (uintptr_t)level[PAGEMAP_LEVELS - 1].size);
pony_assert(ix/2 <= (uintptr_t)level[PAGEMAP_LEVELS - 1].mask);
next_node = &(((PONY_ATOMIC_RVALUE(void*)*)node)[ix]);
atomic_store_explicit(next_node, actor, memory_order_release);
Copy link
Member

Choose a reason for hiding this comment

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

note from sync: please document your understanding of the atomics and their safety here as you stated in the sync call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment.. let me know if it's not clear enough..

@dipinhora
Copy link
Contributor Author

release notes added

.release-notes/4368.md Outdated Show resolved Hide resolved
Copy link
Member

@SeanTAllen SeanTAllen left a comment

Choose a reason for hiding this comment

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

With the small change to fix the release notes format (we only do newlines for new paragraphs), I'm good with this. @jemc, can you also give another review with an eye towards comments and "documentation"?

@SeanTAllen SeanTAllen requested review from jemc and a team July 30, 2023 16:01
@SeanTAllen SeanTAllen added the do not merge This PR should not be merged at this time label Aug 1, 2023
@jemc jemc merged commit afb94f6 into ponylang:main Aug 1, 2023
20 checks passed
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Aug 1, 2023
github-actions bot pushed a commit that referenced this pull request Aug 1, 2023
github-actions bot pushed a commit that referenced this pull request Aug 1, 2023
jemc added a commit that referenced this pull request Aug 1, 2023
jemc added a commit that referenced this pull request Aug 1, 2023
SeanTAllen added a commit that referenced this pull request Aug 1, 2023
SeanTAllen added a commit that referenced this pull request Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - changed Automatically add "Changed" CHANGELOG entry on merge do not merge This PR should not be merged at this time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants