Open ccleve opened 11 months ago
Just before I call the function I switch to a custom memory context, call the func, switch back, and reset() the context. I get the leak whether I do that or not.
Can you show us this code?
ZDB takes a similar approach in the build callback function for the same general reason and it's fine.
I used code that is almost identical to that in ZDB. Literally identical.
On Wed, Oct 11, 2023, 2:47 PM Eric Ridge @.***> wrote:
Just before I call the function I switch to a custom memory context, call the func, switch back, and reset() the context. I get the leak whether I do that or not.
Can you show us this code?
ZDB takes a similar approach in the build callback function for the same general reason and it's fine.
— Reply to this email directly, view it on GitHub https://github.com/pgcentralfoundation/pgrx/issues/1330#issuecomment-1758424604, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITHKUH4MJKZ56YDMBWBN3X63ZVVANCNFSM6AAAAAA54OJ4XU . You are receiving this because you authored the thread.Message ID: @.***>
I used code that is almost identical to that in ZDB. Literally identical.
I'm that guy that tends to blindly believe what he reads on the internet, but in this case, can you please show us exactly what your code is doing? The code I see when I close my eyes seems to work just fine.
There's a lot of intervening code. Let me make a small example that reproduces the problem.
On Fri, Oct 13, 2023 at 10:58 AM Eric Ridge @.***> wrote:
I used code that is almost identical to that in ZDB. Literally identical.
I'm that guy that tends to blindly believe what he reads on the internet, but in this case, can you please show us exactly what your code is doing? The code I see when I close my eyes seems to work just fine.
— Reply to this email directly, view it on GitHub https://github.com/pgcentralfoundation/pgrx/issues/1330#issuecomment-1761662008, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITHKU56QFN63BFNEBASF3X7FJI5ANCNFSM6AAAAAA54OJ4XU . You are receiving this because you authored the thread.Message ID: @.***>
I'm developing an index access method. In the ambuild method / build_callback I call a pg_extern function to process a string column that is coming from the table getting indexed.
If I hard-code the function and call it directly, there is no problem. If I store a reference to the function and call it dynamically, I get a leak. The function is a support function defined in an op class.
Here is the simplified code:
This works, but there's a memory leak that grows to gigabytes and then goes away when indexing is done.
Large numbers of 8k blocks are getting allocated and not released. I used Instruments to track the allocations. Here's the call stack for one of the allocations:
My support function is std_index_pipe(s: &str):
Just before I call the function I switch to a custom memory context, call the func, switch back, and reset() the context. I get the leak whether I do that or not.
I ran
select * from pg_backend_memory_contexts;
to see if there was a context getting filled up. The sumtotal_bytes
across all contexts was far less than the amount of data piling up in memory. This I don't understand; palloc() should do the allocation in some memory context somewhere, right? All this memory does get cleared when the build is complete, which means that it is in a context, I just can't see it. Odd.Any idea how to track this problem down?