`CREATE INDEX` keeps its build memory while the vamana worker loads a second copy of the index, which can OOM large builds

Open
#112 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, postgresql
Domain
backend, databases

Research direction

Start by reading vamanabuild(), its cleanup: block, SerializeIndexToPages(), and FreeBuildState() to trace when the index handle and raw vector buffer are released. Confirm which values are still needed after serialization and warm-up, then check the relevant build and serialization tests. Done means both allocations are freed as soon as the issue describes and the resulting index build still passes those tests.

Written by the indexing model from the issue text.

Description

Problem

At the end of a vamana CREATE INDEX, the backend serializes the index to disk and then waits for the vamana worker to load it (the synchronous warm-up in vamanabuild()). For the whole of that load, the backend still holds its two large build allocations:

  • its own in-memory copy of the index, freed only after the warm-up (SVSFreeIndex in the cleanup: block);
  • the raw float vector buffer (rows × dims × 4 bytes), freed later still in FreeBuildState().

Neither is needed once the index is on disk. While the worker loads its own copy, though, the machine holds the full build footprint plus a second copy of the index. The peak memory of CREATE INDEX is therefore build + residency rather than max(build, residency).

This memory isn't accounted for either: SvsMemoryConfirmBuild() releases the build's reservation before serialization, so from then on nothing is reserved against the memory the backend still holds.

For large indexes this handoff is the highest-memory point of the build. Peak machine-wide memory usage during the handoff can noticeably exceed the peak observed during the build phase itself. In some cases, a build that completes successfully within available memory is then OOM-killed while the worker loads the resulting index.

Steps to reproduce

  1. Build a large vamana index with svs.max_build_memory high enough that the gate admits it.
  2. During CREATE INDEX, sample the RSS of both the build backend and the vamana worker process every second.
  3. After SVS index built successfully, both processes hold their full footprint at the same time until the worker finishes loading. If the build footprint and the index together exceed available memory, the OOM killer fires during this window.

Recommendations

  1. Free the raw vector buffer as soon as the SVS build returns. The SVS dynamic build copies its input into the index's own dataset, so the buffer isn't needed afterwards. Keep vectors.count, which serialization and the build result still read.
  2. Free the backend's index handle right after SerializeIndexToPages(), before the warm-up. The worker loads its own copy from disk, and nothing after serialization uses the backend's copy.

With both changes the peak becomes max(build, residency), and releasing the reservation at confirm time becomes accurate.

Dominant language
Perl
Stars
3
Forks
3
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from intel/SVS-Extension-for-PostgreSQL

All issues in intel/SVS-Extension-for-PostgreSQL

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.