Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpazu-0003cH-H0 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jul 2019 16:17:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hpazs-0001Ux-VO for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jul 2019 16:17:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpazs-0001TT-IS for pgsql-hackers@lists.postgresql.org; Mon, 22 Jul 2019 16:17:08 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpazp-0001Fy-KH for pgsql-hackers@postgresql.org; Mon, 22 Jul 2019 16:17:08 +0000 Received: by mail-wr1-x441.google.com with SMTP id c2so36849266wrm.8 for ; Mon, 22 Jul 2019 09:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UGp9P3nBgZd3K5rrFx3qbd5oGyscJpusm/3redcVz0k=; b=TZew1z5aoF/6k8/hEuybLOHi1jli12+oOB04srPo2+PGcmWrEucoTPJGsXmkJ+IZQq 6IFBnh+MBGBQ+nKVWDT7IvAVhk4IIGjOdoOXuaTCBLhNBRWq+7+8cVJIgg7+/yTcPKoA 01PcERw7U7o5PMT0RaCYkNX07oM5HC0KtD8zx6V0PtqaNXvkUYmSSWAKZH5aXHEN4l8M MpxPFZsGJ7/FPqS8GgDvdXjmxuHAOt4mDdFbMFZJCcDUDVTLISg8D/kkLVmEjkNBooPo KbGC4qLam9gDvueqPZt6VaN+UEt0FlkeZ4A6qRa+N6DqHzAHRmcmBAZxlFIYwTQT4wHO FVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UGp9P3nBgZd3K5rrFx3qbd5oGyscJpusm/3redcVz0k=; b=uP15iNtEfgqFquKqRMD+4Z6Ttpl4FBdUwEkyTX1oaAZwitvIDKXLUKidvmalqfD8GK 0a1c7+gsKVO7+N2z5Ae43sPqcx7+owjoMxLBdwu1AoY+pICw/b/BqwGLmzpTFBhFfA90 9zb2A+MnNKFFXBEDwVUs5MWeeTNhnx7su2mpZu2cGurypYXA92Rf3e1NIIjtghl7oQEz Kr+cDgN1UBe7+GdBYGmATCgrLa3OXe+KojxBFxnqBZW88XSPFGCRGwsYIOKYYmqt3sjF b4U6gNqvRhqokNpxS3Ee5V9gBBexbZP7zXT6YDnNRJ/T4zUFtCIQlKs9L5GyZmPlkmWp VGJw== X-Gm-Message-State: APjAAAU21nEAdY6o02C4QV0B/XSdjDmFaI8B7RPBputrj9PET6u41IUC qyNzwTvJd55omyaI8fyQoweYIA== X-Google-Smtp-Source: APXvYqzMLM9kk4A29tZf6bzl2bMIiZi8uM23SenC2czYZdJ487/ckA3aEDjH9w/0vYFuFMVARR4p4Q== X-Received: by 2002:a05:6000:187:: with SMTP id p7mr70424068wrx.189.1563812223581; Mon, 22 Jul 2019 09:17:03 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id t15sm34447333wrx.84.2019.07.22.09.17.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 22 Jul 2019 09:17:00 -0700 (PDT) Date: Mon, 22 Jul 2019 18:16:58 +0200 From: Tomas Vondra To: Heikki Linnakangas Cc: Jeff Davis , pgsql-hackers@postgresql.org Subject: Re: Memory Accounting Message-ID: <20190722161658.ryo6lbgead2tijew@development> References: <027a129b8525601c6a680d27ce3a7172dab61aab.camel@j-davis.com> <8456dbe6-2245-6a6d-03af-bb62d1615782@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <8456dbe6-2245-6a6d-03af-bb62d1615782@iki.fi> User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 a new block (not an individual >>chunk, but a new malloc'd block) is allocated, it increments a struct >>member; and each time a block is free'd, it decrements the struct >>member. So it tracks blocks allocated by malloc, not what is actually >>used for chunks allocated by palloc. >> >>The purpose is for Memory Bounded Hash Aggregation, but it may be >>useful in more cases as we try to better adapt to and control memory >>usage at execution time. > >Seems handy. > Indeed. >>* 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 memory bounded hash aggregation? Might there be a lot >of sub-contexts during hash aggregation? > There shouldn't be, at least not since b419865a814abbc. There might be cases where custom aggregates still do that, but I think that's simply a design we should discourage. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services