Re: Memory Accounting

2019-10-04 Thread Robert Haas
On Tue, Sep 24, 2019 at 2:47 PM Melanie Plageman wrote: > I think it would be helpful if we could repeat the performance tests > Robert did on that machine with the current patch (unless this version > of the patch is exactly the same as the ones he tested previously). I still have access to a PO

Re: Memory Accounting

2019-10-04 Thread Tom Lane
Peter Geoghegan writes: > On Fri, Oct 4, 2019 at 7:32 AM Jeff Davis wrote: >> The patch has been floating around for a very long time, so I don't >> remember exactly why I chose a signed value. Sorry. > I am reminded of the fact that int64 is used to size buffers within > tuplesort.c, because it

Re: Memory Accounting

2019-10-04 Thread Peter Geoghegan
On Fri, Oct 4, 2019 at 7:32 AM Jeff Davis wrote: > The patch has been floating around for a very long time, so I don't > remember exactly why I chose a signed value. Sorry. I am reminded of the fact that int64 is used to size buffers within tuplesort.c, because it needs to support negative availM

Re: Memory Accounting

2019-10-04 Thread Tom Lane
I wrote: > Just to make things even more mysterious, prairiedog finally showed > the Assert failure on its fourth run with c477f3e449 included: > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=prairiedog&dt=2019-10-04%2012%3A35%3A41 > It's also now apparent that lapwing and locust were fai

Re: Memory Accounting

2019-10-04 Thread Tom Lane
Tomas Vondra writes: > On Fri, Oct 04, 2019 at 12:36:01AM -0400, Tom Lane wrote: >> What I think is happening is that c477f3e449 allowed this bit in >> AllocSetRealloc: >> context->mem_allocated += blksize - oldblksize; >> to be executed in situations where blksize < oldblksize, where before >> th

Re: Memory Accounting

2019-10-04 Thread Tom Lane
Jeff Davis writes: > On Fri, 2019-10-04 at 10:26 +0200, Tomas Vondra wrote: >> Yeah, I think that's an oversight. Maybe there's a reason why Jeff >> used int64, but I can't think of any. > I had chosen a 64-bit value to account for the situation Tom mentioned: > that, in theory, Size might not be

Re: Memory Accounting

2019-10-04 Thread Jeff Davis
On Fri, 2019-10-04 at 10:26 +0200, Tomas Vondra wrote: > On Fri, Oct 04, 2019 at 12:36:01AM -0400, Tom Lane wrote: > > So ... why exactly did this patch define > > MemoryContextData.mem_allocated > > as int64? That seems to me to be doubly wrong: it is not the right > > width > > on 32-bit machine

Re: Memory Accounting

2019-10-04 Thread Tomas Vondra
On Fri, Oct 04, 2019 at 10:26:44AM +0200, Tomas Vondra wrote: On Fri, Oct 04, 2019 at 12:36:01AM -0400, Tom Lane wrote: I haven't chased down exactly what else would need to change. It might be that s/int64/Size/g throughout the patch is sufficient, but I haven't analyzed it. I think so too,

Re: Memory Accounting

2019-10-04 Thread Tomas Vondra
On Fri, Oct 04, 2019 at 12:36:01AM -0400, Tom Lane wrote: So ... why exactly did this patch define MemoryContextData.mem_allocated as int64? That seems to me to be doubly wrong: it is not the right width on 32-bit machines, and it is not the right signedness anywhere. I think that field ought t

Re: Memory Accounting

2019-10-03 Thread Tom Lane
So ... why exactly did this patch define MemoryContextData.mem_allocated as int64? That seems to me to be doubly wrong: it is not the right width on 32-bit machines, and it is not the right signedness anywhere. I think that field ought to be of type Size (a/k/a size_t, but memnodes.h always calls

Re: Memory Accounting

2019-09-30 Thread Tomas Vondra
On Mon, Sep 30, 2019 at 01:34:13PM -0700, Jeff Davis wrote: On Sun, 2019-09-29 at 00:22 +0200, Tomas Vondra wrote: Notice that when CLOBBER_FREED_MEMORY is defined, the code first > calls > wipe_mem and then accesses fields of the (wiped) block. > Interesringly > enough, the regression tests don

Re: Memory Accounting

2019-09-30 Thread Jeff Davis
On Sun, 2019-09-29 at 00:22 +0200, Tomas Vondra wrote: > Notice that when CLOBBER_FREED_MEMORY is defined, the code first > > calls > > wipe_mem and then accesses fields of the (wiped) block. > > Interesringly > > enough, the regression tests don't seem to exercise these bits - > > I've > > tried a

Re: Memory Accounting

2019-09-28 Thread Tomas Vondra
On Sun, Sep 29, 2019 at 12:12:49AM +0200, Tomas Vondra wrote: On Thu, Sep 26, 2019 at 01:36:46PM -0700, Jeff Davis wrote: On Thu, 2019-09-26 at 21:22 +0200, Tomas Vondra wrote: It's worth mentioning that those bechmarks (I'm assuming we're talking about the numbers Rober shared in [1]) were don

Re: Memory Accounting

2019-09-28 Thread Tomas Vondra
On Thu, Sep 26, 2019 at 01:36:46PM -0700, Jeff Davis wrote: On Thu, 2019-09-26 at 21:22 +0200, Tomas Vondra wrote: It's worth mentioning that those bechmarks (I'm assuming we're talking about the numbers Rober shared in [1]) were done on patches that used the eager accounting approach (i.e. walk

Re: Memory Accounting

2019-09-26 Thread Jeff Davis
On Thu, 2019-09-26 at 21:22 +0200, Tomas Vondra wrote: > It's worth mentioning that those bechmarks (I'm assuming we're > talking > about the numbers Rober shared in [1]) were done on patches that used > the eager accounting approach (i.e. walking all parent contexts and > updating the accounting f

Re: Memory Accounting

2019-09-26 Thread Tomas Vondra
On Tue, Sep 24, 2019 at 11:46:49AM -0700, Melanie Plageman wrote: On Thu, Sep 19, 2019 at 11:00 AM Jeff Davis wrote: On Wed, 2019-09-18 at 13:50 -0700, Soumyadeep Chakraborty wrote: > Hi Jeff, Hi Soumyadeep and Melanie, Thank you for the review! > max_stack_depth max level lazy

Re: Memory Accounting

2019-09-24 Thread Michael Paquier
On Tue, Sep 24, 2019 at 02:05:51PM +0200, Tomas Vondra wrote: > The way I see it we can do either eager or lazy accounting. Eager might > work better for aggregates with many contexts, but it does increase the > overhead for the "regular" aggregates with just one or two contexts. > Considering how

Re: Memory Accounting

2019-09-24 Thread Melanie Plageman
On Thu, Sep 19, 2019 at 11:00 AM Jeff Davis wrote: > On Wed, 2019-09-18 at 13:50 -0700, Soumyadeep Chakraborty wrote: > > Hi Jeff, > > Hi Soumyadeep and Melanie, > > Thank you for the review! > > > max_stack_depth max level lazy (ms) eager (ms) > (eage > > r/lazy) > > 2MB 82

Re: Memory Accounting

2019-09-24 Thread Tomas Vondra
On Tue, Sep 24, 2019 at 02:21:40PM +0900, Michael Paquier wrote: On Wed, Jul 24, 2019 at 11:52:28PM +0200, Tomas Vondra wrote: I think Heikki was asking about places with a lot of sub-contexts, which a completely different issue. It used to be the case that some aggregates created a separate con

Re: Memory Accounting

2019-09-23 Thread Michael Paquier
On Wed, Jul 24, 2019 at 11:52:28PM +0200, Tomas Vondra wrote: > I think Heikki was asking about places with a lot of sub-contexts, which a > completely different issue. It used to be the case that some aggregates > created a separate context for each group - like array_agg. That would > make Jeff's

Re: Memory Accounting

2019-09-19 Thread Jeff Davis
On Wed, 2019-09-18 at 13:50 -0700, Soumyadeep Chakraborty wrote: > Hi Jeff, Hi Soumyadeep and Melanie, Thank you for the review! > max_stack_depth max level lazy (ms) eager (ms) (eage > r/lazy) > 2MB 82 302.715 427.554 1.4123978 > 3MB 3474567.829 896.143 1.578

Re: Memory Accounting

2019-09-18 Thread Melanie Plageman
I wanted to address a couple of questions Jeff asked me off-list about Greenplum's implementations of Memory Accounting. Greenplum has two memory accounting sub-systems -- one is the MemoryContext-based system proposed here. The other memory accounting system tracks "logical" memory owners in glob

Re: Memory Accounting

2019-07-24 Thread Tomas Vondra
On Tue, Jul 23, 2019 at 06:18:26PM -0700, Melanie Plageman wrote: On Thu, Jul 18, 2019 at 11:24 AM Jeff Davis wrote: Previous discussion: https://postgr.es/m/1407012053.15301.53.camel%40jeff-desktop This patch introduces a way to ask a memory context how much memory it currently has allocated

Re: Memory Accounting

2019-07-23 Thread Melanie Plageman
On Thu, Jul 18, 2019 at 11:24 AM Jeff Davis wrote: > Previous discussion: > https://postgr.es/m/1407012053.15301.53.camel%40jeff-desktop > > This patch introduces a way to ask a memory context how much memory it > currently has allocated. Each time a new block (not an individual > chunk, but a ne

Re: Memory Accounting

2019-07-22 Thread Jeff Davis
On Mon, 2019-07-22 at 18:16 +0200, Tomas Vondra wrote: > * I changed it to only update mem_allocated for the current > > > context, > > > not recursively for all parent contexts. It's now up to the > > > function > > > that reports memory usage to recurse or not (as needed). > > > > Is that OK for

Re: Memory Accounting

2019-07-22 Thread Tomas Vondra
On Mon, Jul 22, 2019 at 11:30:37AM +0300, Heikki Linnakangas wrote: On 18/07/2019 21:24, Jeff Davis wrote: Previous discussion: https://postgr.es/m/1407012053.15301.53.camel%40jeff-desktop This patch introduces a way to ask a memory context how much memory it currently has allocated. Each time

Re: Memory Accounting

2019-07-22 Thread Heikki Linnakangas
On 18/07/2019 21:24, Jeff Davis wrote: Previous discussion: https://postgr.es/m/1407012053.15301.53.camel%40jeff-desktop This patch introduces a way to ask a memory context how much memory it currently has allocated. Each time a new block (not an individual chunk, but a new malloc'd block) is al