Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckxi5-0003Re-LB for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Mar 2017 18:50:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ckxi5-0005gx-7z for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Mar 2017 18:50:17 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ckxi4-0005eh-FF for pgsql-hackers@postgresql.org; Mon, 06 Mar 2017 18:50:16 +0000 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ckxi2-0001hq-7o for pgsql-hackers@postgresql.org; Mon, 06 Mar 2017 18:50:15 +0000 Received: by mail-wr0-x22c.google.com with SMTP id u48so123422386wrc.0 for ; Mon, 06 Mar 2017 10:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=s8T+9YQtDd9tVrqkqWpwV7uqMTt7CIPACjTR7IIlLwc=; b=bxTh4KIJ3uStkm2GGEL5siCI5516waMxWZXUQDb55k4JNjMMw15zuE0i/Qd/MvP8RU FcW+G7K6olT7Kl+/kEI2Xn9XT7I1K3JM88gAY1knLIrXvCb1Ei7L4RCy2VVAQfehkSx+ hQm+QPBL7Ryv7B/X0zMj7hs+L0ZXzObp2RMiNaQjRyNcN1vs8KlMBamx0VZ7TOCQ9zrk VO6ExEQnObxZw/ixOdNsVqxIHM2wCoHyqEHGbk28VhdQdywP/S1q6yOONXEQkShuFRCN pFY5EVGvqEHonsAKXBOuaHAY4Z7wdElldN51mHypPE8GALok6gRhK8Sc/KKoXd7Fu2An RNHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=s8T+9YQtDd9tVrqkqWpwV7uqMTt7CIPACjTR7IIlLwc=; b=dN8Wr6c3Y+++9xV+61R/hTjRpFJNb30gy2ilIs1Nxk31bfP5HOE9V0t2gZe/Ng7pnI /SSakyyGsQWU1p1D0pdbYce2F5NwAyzCKDEHW0cpriRGP8eTNJfg/YD6sQD0+hC5gXjm 5knmp5Khy5jK2mn7fykda+qx40uITnNPiDbReK6fwmJgwFyHtCXwpSkTDTPjeEmt8KlT UuQ2gm0CviHOuu8Se+ZBOZK7ZIKuw4qeA4uVDnFyQPZSsMmE74KDPFjqhfUaX2ImNpZX NuqgzYpHPqihBgjL5TNBoQmKTyb/oYn8vZBIGBuSbJMvZOfV1A1ynTkimnRwICPYUCHs 0DwA== X-Gm-Message-State: AMke39n5WuCT7+vI34UNbjeLLQLduoRQ4dv8DhqT7GJAhHsKJN38NnUovmdG72L0Uy7p97JF2/athTc/t7mbTYYDBN9OPJ68w6JMjXbQjNU1oWRkl99aiRsHmdmBljfuso7s4+kz9szq3k5dC7Hdx1athcEwjUHxPQPLB/q3KksFckeAuSxFpcj4f//002Rfj8JxUx+wiNU6 X-Received: by 10.223.129.4 with SMTP id 4mr17961952wrm.27.1488826212705; Mon, 06 Mar 2017 10:50:12 -0800 (PST) Received: from [10.137.2.17] (ip-89-177-46-65.net.upcbroadband.cz. [89.177.46.65]) by smtp.gmail.com with ESMTPSA id y43sm23635523wrd.0.2017.03.06.10.50.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 10:50:11 -0800 (PST) Subject: Re: PATCH: two slab-like memory allocators To: Robert Haas , Andres Freund References: <20170228034232.4h7ouyhxq4lbbao2@alap3.anarazel.de> <1240.1488254244@sss.pgh.pa.us> <20170228051630.3qcevakcaaa6b4ef@alap3.anarazel.de> <1671.1488259784@sss.pgh.pa.us> <20170228074420.aazv4iw6k562mnxg@alap3.anarazel.de> <20170228184122.extbigaer5ryrt3z@alap3.anarazel.de> <20170301041835.wli3viwnxr5wonfv@alap3.anarazel.de> <20170301042936.usv23f4iaumeyptf@alap3.anarazel.de> <20170301225545.eoevemua234g4fzq@alap3.anarazel.de> <20170306174406.pfs3as44gc7a5ps2@alap3.anarazel.de> Cc: Tom Lane , Petr Jelinek , Petr Jelinek , John Gorman , pgsql-hackers From: Tomas Vondra Message-ID: Date: Mon, 6 Mar 2017 19:49:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 03/06/2017 07:05 PM, Robert Haas wrote: > On Mon, Mar 6, 2017 at 12:44 PM, Andres Freund wrote: >> On 2017-03-06 12:40:18 -0500, Robert Haas wrote: >>> On Wed, Mar 1, 2017 at 5:55 PM, Andres Freund wrote: >>>> The issue was that on 32bit platforms the Datum returned by some >>>> functions (int2int4_sum in this case) isn't actually a separately >>>> allocated Datum, but rather just something embedded in a larger >>>> struct. That, combined with the following code: >>>> if (!peraggstate->resulttypeByVal && !*isnull && >>>> !MemoryContextContains(CurrentMemoryContext, >>>> DatumGetPointer(*result))) >>>> seems somewhat problematic to me. MemoryContextContains() can give >>>> false positives when used on memory that's not a distinctly allocated >>>> chunk, and if so, we violate memory lifetime rules. It's quite >>>> unlikely, given the required bit patterns, but nonetheless it's making >>>> me somewhat uncomfortable. >>>> >>>> Do others think this isn't an issue and we can just live with it? >>> >>> I think it's 100% broken to call MemoryContextContains() on something >>> that's not guaranteed to be a palloc'd chunk. >> >> I agree, but to me it seems the only fix would be to just yank out the >> whole optimization? > > Dunno, haven't looked into it. > I think it might be fixable by adding a flag into the chunk, with 'true' for regular allocations, and 'false' for the optimized ones. And then only use MemoryContextContains() for 'flag=true' chunks. The question however is whether this won't make the optimization pointless. I also, wonder how much we save by this optimization and how widely it's used? Can someone point me to some numbers? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers