pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: hlinnaka (@hlinnaka) <noreply+hlinnaka@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #434: Limit HNSW build's shared memory size for small tables
Date: Mon, 19 Feb 2024 11:53:03 +0000
Message-ID: <gh-pgvector-pgvector-434-c1952290687@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-434@github.com>
References: <gh-pgvector-pgvector-434@github.com>

> I tried using DSA in https://github.com/pgvector/pgvector/issues/409#issuecomment-1894993783 ([hnsw-fast-build-dsa branch](https://github.com/pgvector/pgvector/compare/hnsw-fast-build...hnsw-fast-build-dsa)), but DSA_ALLOC_NO_OOM still throws an error when running out of shared memory (at least in Docker).

Huh, yeah, that's a bug. I started a thread on that on pgsql-hackers: https://www.postgresql.org/message-id/5efa4a5e-2b8b-42dd-80ed-f920718cf5c0%40iki.fi. I'll try to fix that.

Even if DSA_ALLOC_NO_OOM doesn't work, it would be more friendly to the rest of the system to allocate the memory as you go, instead of one giant allocation. Creating a large DSM segment which is largely unused, can blow away the OS caches.

(We ran into this with Neon, where we start with a small compute VM with little RAM, and hot-plug memory to scale it up as needed. When pgvector makes one large allocation, it fails because /dev/shm is too small. We could scale it up, but if the allocation has already failed, it's too late. We'll find some neon-specific workaround to this, but it seems that growing the allocation slowly would be better for everyone.)

So I resurrected the DSA approach, on top of current 'master': https://github.com/pgvector/pgvector/compare/master...hlinnaka:pgvector:use-dsa?expand=1.  In my quick testing, the get_dsa_address() calls do show up in profile, using up to 4% of CPU time. We don't need all the bookkeeping of freed pages and segment in DSA code, so we could build something faster on top of DSA, or directly on top of DSM.

Before I spend more time polishing that, what do you think of switching to DSA in general, assuming the overhead is tolerable and the upstream bug with `DSA_ALLOC_NO_OOM` is fixed?


view thread (12+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-434-c1952290687@github.com>
Permalink:  ../gh-pgvector-pgvector-434-c1952290687@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox