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 1is8Wz-0006mg-MN for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2020 17:02:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1is8Wy-0005uV-H2 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2020 17:02:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1is8Wy-0005uO-52 for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2020 17:02:04 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1is8Ws-000229-Nl for pgsql-hackers@postgresql.org; Thu, 16 Jan 2020 17:02:02 +0000 Received: by mail-wr1-x443.google.com with SMTP id t2so19930621wrr.1 for ; Thu, 16 Jan 2020 09:01:58 -0800 (PST) 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; bh=NQXElpzO9WMAGp74ykdY8RnsYor7XrY3BP3FMqqpM8c=; b=gAZpMrieVbMaKC+ULuS93Loa9de04DFSNqUKIEpoW+g6F3faq6CuC33k+Xj205M/5f IFejNSEQP5KU6wF8p5QCCGzMC/5oNbZYciPZ4lVAk2xbdr+jeN1M5rb2zJl4EpvhEZDy gF0qiSP8HOLTaK9y0VYtBDbDgaBlJb3OGHteX2e2/5jlyAKbWlXNxO54Dbzm4Zv/W9Yp x6VcxR1gGzmNAzsO4MLc12mKEzhjpgzvl61kBPCr92Cfkjro0k1/fH0nTtspQ02Z9Mpl Pb3oyt2vqnn930D0RazIFF+4hVDTW5oDN8QNEDdV59zhT5kx8HA7RpsWVV/HTtXPn6bS hTsw== 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; bh=NQXElpzO9WMAGp74ykdY8RnsYor7XrY3BP3FMqqpM8c=; b=CCdDiMZufyeaLZiafcKvOGlxOtIbG8sJ/EGvD+r8hmYQpqbq6adEBsyH7jJTO+ZZLC 73RIoiKCY+g/pVFq+j/M2xot08xmA+qGdq0MaU5fMCDvo7C3LeLtVlVcTQDVbwBYoInu DeqzoqprDsgGHk+VzpMWknUxhjpWv1o0x+5Ypb7MP8OdR8BDVWHSwNiSecLSETPcmWam Am2PHsZIOwgpQCdtse1rd6OV79BxfndJxzdyJDGPGU/tHH/g/yyt6/pfJBikj9sEatHP nM5SG+0X8h2PnrW2DfbwpQcrhp4YeFOE/sh++y6PQud3YeQgdrvVu/9cU+NrlyVMJivo eKRw== X-Gm-Message-State: APjAAAWmkyCXjDBIsdGNijBhDKkMdo2kA8lNiZzLiuw+uIpOZWfR11+0 Fi0FmljSiTeH69VttYIkK+3JYA== X-Google-Smtp-Source: APXvYqyrQEspAr7vVG3egHj376+HK6ACTZmvr1/+AznUQyJIRZDR6uFiE3Oi41S8wdZueq5YjXXCEg== X-Received: by 2002:a05:6000:11c3:: with SMTP id i3mr4280316wrx.244.1579194116120; Thu, 16 Jan 2020 09:01:56 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id b67sm1548531wmc.38.2020.01.16.09.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 09:01:55 -0800 (PST) Date: Thu, 16 Jan 2020 18:01:53 +0100 From: Tomas Vondra To: Andres Freund Cc: Tom Lane , Tomas Vondra , pgsql-hackers@postgresql.org Subject: Re: SlabCheck leaks memory into TopMemoryContext Message-ID: <20200116170153.qp36chsyhikvgvxt@development> References: <20200116044119.g45f7pmgz4jmodxj@alap3.anarazel.de> <23952.1579151393@sss.pgh.pa.us> <20200116061732.vvpyexenaortpu5y@alap3.anarazel.de> <27213.1579155900@sss.pgh.pa.us> <20200116064143.opcu2vhcktddpzbh@alap3.anarazel.de> <19743.1579188421@sss.pgh.pa.us> <20200116162500.pcgxmykirm677mt6@development> <20200116164849.75rzho6zn4qppnf3@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200116164849.75rzho6zn4qppnf3@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jan 16, 2020 at 08:48:49AM -0800, Andres Freund wrote: >Hi, > >On 2020-01-16 17:25:00 +0100, Tomas Vondra wrote: >> On Thu, Jan 16, 2020 at 10:27:01AM -0500, Tom Lane wrote: >> > Andres Freund writes: >> > > ... I thought you were asking whether >> > > any additional memory could just be avoided... >> > >> > Well, I was kind of wondering that, but if it's not practical then >> > preallocating the space instead will do. >> > >> >> I don't think it's practical to rework the checks in a way that would >> not require allocations. Maybe it's possible, but I think it's not worth >> the extra complexity. >> >> The attached fix should do the trick - it pre-allocates the space when >> creating the context. There is a bit of complexity because we want to >> allocate the space as part of the context header, but nothin too bad. We >> might optimize it a bit by using a regular bitmap (instead of just an >> array of bools), but I haven't done that. > >I don't get why it's advantageous to allocate this once for each slab, >rather than having it as a global once for all slabs. But anyway, still >clearly better than the current situation. > It's largely a matter of personal preference - I agree there are cases when global variables are the best solution, but I kinda dislike them. It seems cleaner to just allocate it as part of the slab, not having to deal with different number of chunks per block between slabs. Plus we don't have all that many slabs (like 2), and it's only really used in debug builds anyway. So I'm not all that woried about this wasting a couple extra kB of memory. YMMV of course ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services