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

issue: 3884801 Check for resident hugepages to avoid SIGBUS #204

Open
wants to merge 1 commit into
base: vNext
Choose a base branch
from

Conversation

pasis
Copy link
Member

@pasis pasis commented Jul 29, 2024

Description

In a containerized environment mmap() beyond the hugepages limit can be successful, but a further memory access triggers SIGBUS and terminates the process. Check that all the allocated hugepages are resident with mincore() to avoid the SIGBUS issue.

Cost of the feature depends on the allocation size and hugepage size:

  • 32GB with 2MB pages takes 4400 us
  • 32GB with 1GB pages takes 11 us
  • 32MB with 2MB pages takes 5-6 us

We expect a big memory preallocation at the start (2GB by default) and
rare 32MB allocations during warmup period. Therefore, this feature can
add several additional 5us latency spikes during warmup period.

What

Check for resident hugepages after allocation.

Why ?

Avoid SIGBUS in containerized environments.

Change type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Check list

  • Code follows the style de facto guidelines of this project
  • Comments have been inserted in hard to understand places
  • Documentation has been updated (if necessary)
  • Test has been added (if possible)

@pasis pasis added the draft Not to review yet label Jul 29, 2024
@pasis pasis changed the title issue: Check for resident hugepages to avoid SIGBUS issue: 3884801 Check for resident hugepages to avoid SIGBUS Jul 29, 2024
@pasis pasis added enhancement New feature or request and removed draft Not to review yet labels Jul 29, 2024
if (rc < 0) {
__log_info_dbg("mincore() failed to verify hugepages (errno=%d)", errno);
} else if (resident_nr != pages_nr) {
__log_info_dbg("Not all hugepages are resident (allocated=%zu resident=%zu)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we need to add it as info or at least some information that hugepages will not be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

higher level logic (xlio_allocator) iterates over available and suitable hugepage sizes in some order until allocation succeeds or all the hugepages fail. The warning message about falling back to regular pages is printed by xlio_allocator. So it's completely ok to fail here and try the next hugepage size.

In a containerized environment mmap() beyond the hugepages limit can be
successful, but a further memory access triggers SIGBUS and terminates
the process. Check that all the allocated hugepages are resident with
mincore() to avoid the SIGBUS issue.

Cost of the feature depends on the allocation size and hugepage size:
 - 32GB with 2MB pages takes 4400 us
 - 32GB with 1GB pages takes 11 us
 - 32MB with 2MB pages takes 5-6 us

We expect a big memory preallocation at the start (2GB by default) and
rare 32MB allocations during warmup period. Therefore, this feature can
add several additional 5us latency spikes during warmup period.

Signed-off-by: Dmytro Podgornyi <[email protected]>
@pasis pasis removed the draft Not to review yet label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request to_merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants