diff options
author | Andrew Stubbs <ams@baylibre.com> | 2025-04-18 21:56:19 +0000 |
---|---|---|
committer | Sandra Loosemore <sloosemore@baylibre.com> | 2025-05-15 20:25:47 +0000 |
commit | 59ebc6007887151cdb0f7d00108b86a5921ec5a4 (patch) | |
tree | 5199637845ccc925c370afae1df231e440ef26a0 /gcc | |
parent | 86086c93cddee91aa5a5deda1f1a0ade0d868d66 (diff) | |
download | gcc-59ebc6007887151cdb0f7d00108b86a5921ec5a4.zip gcc-59ebc6007887151cdb0f7d00108b86a5921ec5a4.tar.gz gcc-59ebc6007887151cdb0f7d00108b86a5921ec5a4.tar.bz2 |
libgomp: fine-grained pinned memory allocator
https://patchwork.sourceware.org/project/gcc/list/?series=35022
This patch introduces a new custom memory allocator for use with pinned
memory (in the case where the Cuda allocator isn't available). In future,
this allocator will also be used for Unified Shared Memory. Both memories
are incompatible with the system malloc because allocated memory cannot
share a page with memory allocated for other purposes.
This means that small allocations will no longer consume an entire page of
pinned memory. Unfortunately, it also means that pinned memory pages will
never be unmapped (although they may be reused).
The implementation is not perfect; there are various corner cases (especially
related to extending onto new pages) where allocations and reallocations may
be sub-optimal, but it should still be a step forward in support for small
allocations.
I have considered using libmemkind's "fixed" memory but rejected it for three
reasons: 1) libmemkind may not always be present at runtime, 2) there's no
currently documented means to extend a "fixed" kind one page at a time
(although the code appears to have an undocumented function that may do the
job, and/or extending libmemkind to support the MAP_LOCKED mmap flag with its
regular kinds would be straight-forward), 3) USM benefits from having the
metadata located in different memory and using an external implementation makes
it hard to guarantee this.
libgomp/ChangeLog:
* Makefile.am (libgomp_la_SOURCES): Add usmpin-allocator.c.
* Makefile.in: Regenerate.
* config/linux/allocator.c: Include unistd.h.
(pin_ctx): New variable.
(ctxlock): New variable.
(linux_init_pin_ctx): New function.
(linux_memspace_alloc): Use usmpin-allocator for pinned memory.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.h (usmpin_init_context): New prototype.
(usmpin_register_memory): New prototype.
(usmpin_alloc): New prototype.
(usmpin_free): New prototype.
(usmpin_realloc): New prototype.
* testsuite/libgomp.c/alloc-pinned-8.c: New test.
* usmpin-allocator.c: New file.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions