mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Hardened shared memory allocator
Co-authored-by: chungkn from OneMount Group <kimngocchung.k2a@gmail.com>
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user