Skip to content

Commit 59b1fa2

Browse files
committed
Disable memory poisoning in DisjointPool by default
ASan throws an error whenever the memory poison is called for the memory allocated on GPU: "AddressSanitizer: CHECK failed: asan_mapping.h:359 "((AddrIsInMem(p))) != (0)" (0x0, 0x0)". This commit disables poisoning by default and adds a new parameter to Disjoint Pool params struct that allows to enable the poisoning.
1 parent 5af717e commit 59b1fa2

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

include/umf/pools/pool_disjoint.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ typedef struct umf_disjoint_pool_params_t {
5858

5959
/// Name used in traces
6060
const char *Name;
61+
62+
/// Whether the pool is limited to host memory
63+
int HostMemory;
6164
} umf_disjoint_pool_params_t;
6265

6366
umf_memory_pool_ops_t *umfDisjointPoolOps(void);
@@ -72,7 +75,8 @@ static inline umf_disjoint_pool_params_t umfDisjointPoolParamsDefault(void) {
7275
0, /* CurPoolSize */
7376
0, /* PoolTrace */
7477
NULL, /* SharedLimits */
75-
"disjoint_pool" /* Name */
78+
"disjoint_pool", /* Name */
79+
0, /* HostMemory */
7680
};
7781

7882
return params;

src/pool/pool_disjoint.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,16 @@ class DisjointPool::AllocImpl {
394394
};
395395

396396
static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
397-
size_t size, size_t alignment = 0) {
397+
bool hostMemory, size_t size,
398+
size_t alignment = 0) {
398399
void *ptr;
399400
auto ret = umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
400401
if (ret != UMF_RESULT_SUCCESS) {
401402
throw MemoryProviderError{ret};
402403
}
403-
utils_annotate_memory_inaccessible(ptr, size);
404+
if (hostMemory) {
405+
utils_annotate_memory_inaccessible(ptr, size);
406+
}
404407
return ptr;
405408
}
406409

@@ -438,7 +441,8 @@ Slab::Slab(Bucket &Bkt)
438441
Chunks(Bkt.SlabMinSize() / Bkt.getSize()), NumAllocated{0},
439442
bucket(Bkt), SlabListIter{}, FirstFreeChunkIdx{0} {
440443
auto SlabSize = Bkt.SlabAllocSize();
441-
MemPtr = memoryProviderAlloc(Bkt.getMemHandle(), SlabSize);
444+
MemPtr = memoryProviderAlloc(
445+
Bkt.getMemHandle(), Bkt.getAllocCtx().getParams().HostMemory, SlabSize);
442446
regSlab(*this);
443447
}
444448

@@ -821,8 +825,10 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
821825

822826
FromPool = false;
823827
if (Size > getParams().MaxPoolableSize) {
824-
Ptr = memoryProviderAlloc(getMemHandle(), Size);
825-
utils_annotate_memory_undefined(Ptr, Size);
828+
Ptr = memoryProviderAlloc(getMemHandle(), getParams().HostMemory, Size);
829+
if (getParams().HostMemory) {
830+
utils_annotate_memory_undefined(Ptr, Size);
831+
}
826832
return Ptr;
827833
}
828834

@@ -839,7 +845,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
839845
}
840846

841847
VALGRIND_DO_MEMPOOL_ALLOC(this, Ptr, Size);
842-
utils_annotate_memory_undefined(Ptr, Bucket.getSize());
848+
if (getParams().HostMemory) {
849+
utils_annotate_memory_undefined(Ptr, Bucket.getSize());
850+
}
843851

844852
return Ptr;
845853
} catch (MemoryProviderError &e) {
@@ -876,8 +884,11 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
876884
// If not, just request aligned pointer from the system.
877885
FromPool = false;
878886
if (AlignedSize > getParams().MaxPoolableSize) {
879-
Ptr = memoryProviderAlloc(getMemHandle(), Size, Alignment);
880-
utils_annotate_memory_undefined(Ptr, Size);
887+
Ptr = memoryProviderAlloc(getMemHandle(), getParams().HostMemory, Size,
888+
Alignment);
889+
if (getParams().HostMemory) {
890+
utils_annotate_memory_undefined(Ptr, Size);
891+
}
881892
return Ptr;
882893
}
883894

@@ -894,8 +905,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
894905
}
895906

896907
VALGRIND_DO_MEMPOOL_ALLOC(this, AlignPtrUp(Ptr, Alignment), Size);
897-
utils_annotate_memory_undefined(AlignPtrUp(Ptr, Alignment), Size);
898-
908+
if (getParams().HostMemory) {
909+
utils_annotate_memory_undefined(AlignPtrUp(Ptr, Alignment), Size);
910+
}
899911
return AlignPtrUp(Ptr, Alignment);
900912
} catch (MemoryProviderError &e) {
901913
umf::getPoolLastStatusRef<DisjointPool>() = e.code;
@@ -962,8 +974,9 @@ void DisjointPool::AllocImpl::deallocate(void *Ptr, bool &ToPool) {
962974
}
963975

964976
VALGRIND_DO_MEMPOOL_FREE(this, Ptr);
965-
utils_annotate_memory_inaccessible(Ptr, Bucket.getSize());
966-
977+
if (getParams().HostMemory) {
978+
utils_annotate_memory_inaccessible(Ptr, Bucket.getSize());
979+
}
967980
if (Bucket.getSize() <= Bucket.ChunkCutOff()) {
968981
Bucket.freeChunk(Ptr, Slab, ToPool);
969982
} else {

0 commit comments

Comments
 (0)