From 2f9371516df8fb00724e8b76dc5753a3a51136b1 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 15 Jan 2024 19:17:50 -0800 Subject: [PATCH] Leave space for other objects in shared memory --- src/hnswbuild.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index b92bdc9..b683b24 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -931,6 +931,7 @@ HnswBeginParallel(HnswBuildState * buildstate, bool isconcurrent, int request) Snapshot snapshot; Size esthnswshared; Size esthnswarea; + Size estother; HnswShared *hnswshared; char *hnswarea; HnswLeader *hnswleader = (HnswLeader *) palloc0(sizeof(HnswLeader)); @@ -961,7 +962,15 @@ HnswBeginParallel(HnswBuildState * buildstate, bool isconcurrent, int request) /* Estimate size of workspaces */ esthnswshared = ParallelEstimateShared(buildstate->heap, snapshot); shm_toc_estimate_chunk(&pcxt->estimator, esthnswshared); + + /* Leave space for other objects in shared memory */ + /* Docker has a default limit of 64 MB for shm_size */ + /* which happens to be the default value of maintenance_work_mem */ esthnswarea = maintenance_work_mem * 1024L; + estother = 2 * 1024 * 1024; + if (esthnswarea > estother) + esthnswarea -= estother; + shm_toc_estimate_chunk(&pcxt->estimator, esthnswarea); shm_toc_estimate_keys(&pcxt->estimator, 2);