Re: Using per-transaction memory contexts for storing decoded tuples
Amit Kapila <amit.kapila16@gmail.com>
From: Amit Kapila <amit.kapila16@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-09-20T05:46:05Z
Lists: pgsql-hackers
On Fri, Sep 20, 2024 at 5:13 AM David Rowley <dgrowleyml@gmail.com> wrote: > > On Fri, 20 Sept 2024 at 05:03, Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > I've done other benchmarking tests while changing the memory block > > sizes from 8kB to 8MB. I measured the execution time of logical > > decoding of one transaction that inserted 10M rows. I set > > logical_decoding_work_mem large enough to avoid spilling behavior. In > > this scenario, we allocate many memory chunks while decoding the > > transaction and resulting in calling more malloc() in smaller memory > > block sizes. Here are results (an average of 3 executions): > > I was interested in seeing the memory consumption with the test that > was causing an OOM due to the GenerationBlock fragmentation. > +1. That test will be helpful. > > The fact that we're using rb->size and txn->size to choose the > > transactions to evict could make this idea less attractive. Even if we > > defragment transactions, rb->size and txn->size don't change. > > Therefore, it doesn't mean we can avoid evicting transactions due to > > full of logical_decoding_work_mem, but just mean the amount of > > allocated memory might have been reduced. > > I had roughly imagined that you'd add an extra field to store > txn->size when the last fragmentation was done and only defrag the > transaction when the ReorderBufferTXN->size is, say, double the last > size when the changes were last defragmented. Of course, if the first > defragmentation was enough to drop MemoryContextMemAllocated() below > the concerning threshold above logical_decoding_work_mem then further > defrags wouldn't be done, at least, until such times as the > MemoryContextMemAllocated() became concerning again. If you didn't > want to a full Size variable for the defragmentation size, you could > just store a uint8 to store which power of 2 ReorderBufferTXN->size > was when it was last defragmented. There are plenty of holds in that > struct that could be filled without enlarging the struct. > > In general, it's a bit annoying to have to code around this > GenerationContext fragmentation issue. > Right, and I am also slightly afraid that this may not cause some regression in other cases where defrag wouldn't help. -- With Regards, Amit Kapila.
Commits
-
Reduce memory block size for decoded tuple storage to 8kB.
- 1b9b6cc3456b 18.0 landed
- eef9cc4dc28f 17.1 landed
- 05e982cdc4df 16.5 landed
- 4a675f31868a 15.9 landed
- 5c1ed0a51681 14.14 landed
- cb988b04d063 13.17 landed
- 53fa68b3bc3a 12.21 landed
-
Generational memory allocator
- a4ccc1cef5a0 11.0 cited