Hardened shared memory allocator

Co-authored-by: chungkn from OneMount Group <kimngocchung.k2a@gmail.com>
This commit is contained in:
Andrew Kane
2026-02-25 10:39:01 -08:00
parent b7e680d41a
commit 9ed39fb94b

View File

@@ -658,9 +658,17 @@ static void *
HnswSharedMemoryAlloc(Size size, void *state) HnswSharedMemoryAlloc(Size size, void *state)
{ {
HnswBuildState *buildstate = (HnswBuildState *) state; HnswBuildState *buildstate = (HnswBuildState *) state;
void *chunk = buildstate->hnswarea + buildstate->graph->memoryUsed; Size alignedSize = MAXALIGN(size);
void *chunk;
buildstate->graph->memoryUsed += MAXALIGN(size); if (alignedSize > 1024 * 1024)
elog(ERROR, "hnsw allocation too large");
if (buildstate->graph->memoryUsed + alignedSize > buildstate->graph->memoryTotal)
elog(ERROR, "hnsw allocator out of memory");
chunk = buildstate->hnswarea + buildstate->graph->memoryUsed;
buildstate->graph->memoryUsed += alignedSize;
return chunk; return chunk;
} }