[PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
[PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
Hi, GIN asks a manual VACUUM to empty the pending list. Autovacuum instead stops after processing the part of the list that existed when cleanup started. This prevents concurrent insertions from extending cleanup indefinitely. It is safe because those insertions cannot contain TIDs that this VACUUM needs to remove. Parallel autovacuum workers are regular background workers, so AmAutoVacuumWorkerProcess() returns false for them. A GIN index handled by such a worker is therefore treated as if it were processed by a manual VACUUM, and its pending-list cleanup is not bounded. The attached patch adds is_autovacuum to IndexVacuumInfo and passes the leader's state to parallel workers. GIN uses that state when deciding whether the pending list must be emptied. Manual VACUUM behavior is unchanged. Any thoughts? --- Best regards, Jingtang Zhang
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Hi Jingtang, On Sep 20, 2026, Jingtang Zhang wrote: > The attached patch adds is_autovacuum to IndexVacuumInfo and passes > the leader's state to parallel workers. I read v1 and think this is the right approach. The cleanup policy should belong to the VACUUM operation, not depend on which process happens to pick up an index. Passing it through IndexVacuumInfo keeps that distinction explicit. I checked the core callers and did not find a missing initialization of the new field. I also reviewed the other uses of AmAutoVacuumWorkerProcess() and found no other cases of this confusion. The check in ginInsertCleanup() is OK: parallel_vacuum_main() sets maintenance_work_mem to the worker's share of the leader's budget. We cannot assert !IsParallelWorker() in the macro, since callers such as vacuum_delay_point() need to distinguish the leader from its workers. Perhaps a comment at the macro definition noting that autovacuum's parallel workers return false would help prevent similar mistakes. I also checked this against 8637383f5ff, the recent fix for pending-list cleanup during multiple index-vacuum passes. The requirement there is to process the existing pending entries before each ginbulkdelete() pass. This patch preserves that, including forceCleanup=true so that we wait for a concurrent cleanup. Extending the existing bounded behavior to the parallel workers does not weaken that guarantee. Could we cover the parallel-worker path with a test? One possible scenario is to pause cleanup while flushing the old tail into the main index, append new pending pages, and verify that cleanup leaves those new pages behind. The test would need to ensure that a parallel worker, not the leader, handles the index; otherwise it could pass without the fix. I have not tried this scenario yet. Thank you! Best regards, Andrey Borodin.
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
Hi Andrey, Thanks for the review! > distinguish the leader from its workers. Perhaps a comment at the > macro definition noting that autovacuum's parallel workers return > false would help prevent similar mistakes. Attached is v2 with the comment you suggested for AmAutoVacuumWorkerProcess(). > Could we cover the parallel-worker path with a test? One possible > scenario is to pause cleanup while flushing the old tail into the main > index, append new pending pages, and verify that cleanup leaves those > new pages behind. The test would need to ensure that a parallel worker, > not the leader, handles the index; otherwise it could pass without > the fix. I have not tried this scenario yet. For the test, I haven't found a reliable way to control the timing without adding injection points. We need to ensure that a parallel worker handles the index, and append new pending pages while cleanup is flushing the old tail into the main index. Do you have any ideas for a simpler way to test this? --- Best regards, Jingtang Zhang
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
От:
Yuhang Qiu <iamqyh@gmail.com>
Дата:
Hi Jingtang, The fix in v2 LGTM. I used local injection points to test both ginbulkdelete() and the ginvacuumcleanup() path where bulk deletion was not performed. The test ensures that a parallel worker handles the GIN index. It pauses cleanup at the original tail page, after releasing the buffer content lock, then appends new pending pages from another session. Without the fix, both paths continue until the pending list is empty. With v2, both leave new pending pages behind, matching serial autovacuum. Manual parallel VACUUM still empties the pending list. > Do you have any ideas for a simpler way to test this? I haven't found a simpler, reliable way to test this without adding injection points either. Given the extra machinery needed to test such a small fix, I'd lean toward leaving it without a regression test. Best regards, Yuhang Qiu
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Mon, Sep 21, 2026 at 6:34 AM Jingtang Zhang wrote:
>
> Hi Andrey,
>
> Thanks for the review!
>
> > distinguish the leader from its workers. Perhaps a comment at the
> > macro definition noting that autovacuum's parallel workers return
> > false would help prevent similar mistakes.
>
> Attached is v2 with the comment you suggested for
> AmAutoVacuumWorkerProcess().
Thank you for the report and the patch! I think the following comment
should also be updated:
* When running in an autovacuum worker, we won't necessarily _fully_
* empty the pending list. This is still safe; concurrent inserters
* cannot insert new tuples whose TIDs VACUUM needs us to remove.
How about something like this:
* When called by autovacuum, we won't necessarily _fully_ empty the
* pending list. This is still safe; concurrent inserters cannot insert
* new tuples whose TIDs VACUUM needs us to remove.
The reset looks good to me.
>
> > Could we cover the parallel-worker path with a test? One possible
> > scenario is to pause cleanup while flushing the old tail into the main
> > index, append new pending pages, and verify that cleanup leaves those
> > new pages behind. The test would need to ensure that a parallel worker,
> > not the leader, handles the index; otherwise it could pass without
> > the fix. I have not tried this scenario yet.
>
> For the test, I haven't found a reliable way to control the timing
> without adding injection points. We need to ensure that a parallel
> worker handles the index, and append new pending pages while cleanup
> is flushing the old tail into the main index.
>
> Do you have any ideas for a simpler way to test this?
Having a reliable test at a convenient cost seems challenging to me,
and doesn't justify its benefit. I think we can push it without a
test.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
Hi, Masahiko Sawada and Yuhang. Thanks for the review! Attached is v3 with the comment updated as suggested, rebased on current master. > Having a reliable test at a convenient cost seems challenging to me, > and doesn't justify its benefit. I think we can push it without a > test. I've left out the regression test, as discussed. --- Best regards, Jingtang
Re: [PATCH] Use bounded GIN pending-list cleanup in parallel autovacuum
От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Thu, Sep 24, 2026 at 1:20 AM Jingtang Zhang wrote: > > Hi, Masahiko Sawada and Yuhang. > > Thanks for the review! Attached is v3 with the comment updated as > suggested, rebased on current master. > > > Having a reliable test at a convenient cost seems challenging to me, > > and doesn't justify its benefit. I think we can push it without a > > test. > > I've left out the regression test, as discussed. Thank you for updating the patch! I've pushed it. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com