On Sun, Feb 19, 2017 at 7:44 PM, Robert Haas <robertmh...@gmail.com> wrote: > It's probably OK if tbm_free() doesn't free the memory allocated from > DSA, and we just let cleanup at end of query do it. However, that > could cause some trouble if the Parallel Bitmap Heap Scan gets > executed over and over and keeps allocating more and more memory from > DSA.
Is it possible that Parallel Bitmap Heap Scan will be executed multiple time without shutting down the Workers? I can imagine it can get executed over and over if plan is something like below. NestLoopJoin -> SeqScan -> Gather -> Parallel Bitmap Heap Scan But in such case every time the Inner node of the NLJ will be rescanned i.e. Gather will be rescanned which in turn shutdown workers. So basically, what I want to propose is that Only during ExecReScanBitmapHeapScan we can free all the DSA pointers because at that time we can be sure that all the workers have completed there task and we are safe to free. (And we don't free any DSA memory at ExecEndBitmapHeapScan). I think the way to fix that would be to maintain a reference > count that starts at 1 when the iterator arrays are created and gets > incremented every time a TBMSharedIteratorState is created. It gets > decremented when the TIDBitmap is destroyed that has iterator arrays > is destroyed, and each time a TBMSharedIteratorState is destroyed. > When it reaches 0, the process that reduces the reference count to 0 > calls dsa_free on the DSA pointers for pagetable, spages, and schunks. > (Also, if a TIDBitmap is freed before iteration begins, it frees the > DSA pointer for the pagetable only; the others won't have values yet.) -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers