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

Improve the Arena allocator to reduce memory fragmentation #916

Merged
merged 46 commits into from
Jan 12, 2022

Conversation

rongou
Copy link
Contributor

@rongou rongou commented Nov 12, 2021

Currently the arena allocator divides GPU memory into a global arena and per-thread arenas. For smaller allocations, a per-thread arena allocates large chunks of memory (superblocks) from the global arena and divides them up for individual allocations. However, when deallocating from another arena (producer/consumer pattern), or when we run out of memory and return everything to the global arena, the superblock boundaries are broken. Overtime, this could cause the memory to get more and more fragmented.

This PR makes superblocks concrete objects, not just virtual boundaries, and the only units of exchange between the global arena and per-thread arenas. This should make the allocator more resistant to memory fragmentation, especially for long running processes under constant memory pressure.

Other notable changes:

  • The allocator now allocates a fixed but configurable amount of memory from CUDA. This introduces less fragmentation comparing to growing the pool size gradually.
  • Switched to C++17 std::shared_mutex.
  • Added a bunch of unit tests.

fixes #919
fixes #906

@rongou rongou added 2 - In Progress Currently a work in progress non-breaking Non-breaking change 5 - DO NOT MERGE Hold off on merging; see PR for details improvement Improvement / enhancement to an existing function cpp Pertains to C++ code labels Nov 12, 2021
@rongou rongou self-assigned this Nov 12, 2021
@rongou rongou requested review from a team as code owners November 12, 2021 18:04
@github-actions github-actions bot added the CMake label Nov 12, 2021
@harrism
Copy link
Member

harrism commented Nov 15, 2021

Please use draft PRs instead of "WIP" titles.

@rongou rongou removed the 5 - DO NOT MERGE Hold off on merging; see PR for details label Dec 9, 2021
@rongou
Copy link
Contributor Author

rongou commented Dec 14, 2021

rerun tests

@rongou rongou requested review from jrhemstad and harrism and removed request for cwharris and codereport December 14, 2021 18:42
@harrism
Copy link
Member

harrism commented Dec 14, 2021

rerun tests

@rongou
Copy link
Contributor Author

rongou commented Jan 5, 2022

@harrism @jrhemstad I think this is ready to be merged. Please take another look. Thanks!

Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

Looks good. A few really minor cleanup requests.

benchmarks/random_allocations/random_allocations.cpp Outdated Show resolved Hide resolved
tests/mr/device/arena_mr_tests.cpp Outdated Show resolved Hide resolved
tests/mr/device/arena_mr_tests.cpp Show resolved Hide resolved
@rongou rongou requested a review from harrism January 12, 2022 03:05
@harrism
Copy link
Member

harrism commented Jan 12, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit ea807e8 into rapidsai:branch-22.02 Jan 12, 2022
@rongou rongou deleted the arena-superblock branch January 21, 2022 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for review Ready for review by team cpp Pertains to C++ code improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
3 participants