[PATCH] Free BufFile metadata in close and append paths

From: DaeMyung Kang <charsyam(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: DaeMyung Kang <charsyam(at)gmail(dot)com>
Subject: [PATCH] Free BufFile metadata in close and append paths
Date: 2026-04-29 15:46:59
Message-ID: 20260429154659.1828869-1-charsyam@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi, Hackers,

Continuing the storage/file audit, I found two small but consistent
metadata leaks in BufFile. BufFileClose() does not release the
pstrdup'd name on FileSet-based BufFiles, and BufFileAppend()
silently retains the source wrapper (including its BLCKSZ buffer)
even though the function semantics already say the source must not
be touched after the call.

Details and the parallel-sort motivation are in the commit message.

Thanks,
DaeMyung

---

FileSet-based BufFiles duplicate their logical name, but BufFileClose()
did not release it. Release that metadata along with the other
palloc'd state owned by the BufFile.

BufFileAppend() transfers only the underlying file handles to the
target while telling callers not to use the source again. Free the
consumed source wrapper and metadata after the transfer so repeated
appends do not retain a BLCKSZ-sized BufFile wrapper until context
reset.

This matters most for parallel sort workflows that issue many
BufFileAppend() calls in a single context: each retained source
wrapper holds a BLCKSZ-sized buffer until context reset, which can
run into hundreds of KB at high DOP.
---
src/backend/storage/file/buffile.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

Attachment Content-Type Size
0001-Free-BufFile-metadata-in-close-and-append-paths.patch text/x-patch 2.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-04-29 15:49:53 Bogus recovery conflicts due to outdated XLogReceiptTime
Previous Message Tom Lane 2026-04-29 15:44:14 Re: [BUG?] macOS (Intel) build warnings: "ranlib: file … has no symbols" for aarch64 objects