From: | Jingtang Zhang <mrdrivingduck(at)gmail(dot)com> |
---|---|
To: | Thomas Munro <thomas(dot)munro(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Memory leak of SMgrRelation object on standby |
Date: | 2025-08-19 03:37:44 |
Message-ID: | CEB61634-6090-49C3-9749-E48F83795E90@gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi~
Thanks for looking.
> DropRelationFiles() is also called by FinishPreparedTransaction(). At
> first I thought that might be a problem too, but looking a bit more
> closely and trying it out... if a prepared transaction dropped a
> table, then it called RelationDropStorage(), RelationCloseSmgr(),
> smgrunpin(), and I can't immediately think of any way to repin it
> while the relation is locked, so you can't break the assertion about
> that in smgrdestroy(), where we make sure there are no Relation
> objects with dangling references. It's already left unpinned or never
> pinned and later destroyed in both DROP; PREPARE TRANSACTION; ...
> COMMIT PREPARED; and CREATE; PREPARE TRANSACTION; ... ROLLBACK
> PREPARED sequences, with different details.
Another call of DropRelationFiles seems to have been handled by AtEOXact_SMgr,
so there is no leak w/o patch. I have pgbench'ed in one connection for 10 min
with CREATE; PREPARE TRANSACTION; ... ROLLBACK PREPARED; sequence and there
is no rising of RES.
> Now I'm left wondering if two-phase commit should do this explicitly
> or not. For the isRedo case it seems clear, it was the intention of
> 21d9c3ee to destroy it on commit/abort, which must be here I think.
> The following description from the commit message *probably* also fits
> the two-phase case, even though it already doesn't leak without it.
> It would be good to get a comment explaining the new smgrdestroy()
> call, and point to where our tests exercise all relevant cases.
Explicit call seems to be a duplication if AtEOXact_SMgr can already handle?
Should be do it only for redo?
Some comment has been added to smgrdestroy() to define when it should be
called inside v2 patch.
> it's not immediately obvious how to introspect the cached state to
> verify that the memory isn't leaked.
It sure is...The way I'm using is benching for a long time to see if RES is
rising…
—
Regards, Jingtang
Attachment | Content-Type | Size |
---|---|---|
v2-0001-Fix-SMgrRelation-object-memory-leak-in-DropRelationF.patch | application/octet-stream | 2.7 KB |
unknown_filename | text/plain | 2 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Daniil Davydov | 2025-08-19 03:57:42 | Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue |
Previous Message | jian he | 2025-08-19 03:36:49 | Re: CREATE SCHEMA ... CREATE DOMAIN support |