Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bqUkv-0001Pm-OF for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Oct 2016 00:35:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bqUkv-00046Q-2w for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Oct 2016 00:35:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bqUjW-0002SB-1q for pgsql-hackers@postgresql.org; Sun, 02 Oct 2016 00:34:22 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bqUjS-0000ID-RH for pgsql-hackers@postgresql.org; Sun, 02 Oct 2016 00:34:20 +0000 Received: by mail-wm0-x22e.google.com with SMTP id f193so47815921wmg.0 for ; Sat, 01 Oct 2016 17:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=oQGesBCrx1a20TNDG5raXau/XWkcj0ACKpUaPPCtpbE=; b=bLLVjFgUqG++/3cLIQ9dmPlRrw7CaXFZg5z/ST3HY0TAPmNgIrtaAQq2P3Bp4mfsbc z4ccMCSdjCHojFSOwIjWiyXXWQJtJSe4oafY9pdoLgDbq0PB4wN2jpl25f7LArCZjal4 wiLctZ4llNeNDWzok6K40I6bQR5DbVUhrKy3ggY9SpAf4w/7Ccv74cIyOnu4rRomv+yV khI7006R2RgBpSLr5iju9UXij2VgA2twkh8K/NW6UeT7O//agU69AlKEwkqifsK6lPRL GW0dHkMQ619Du5CbKNkBfjmTM3xQG536SaYaXP7wy2xIQiytqY1BOXtnP/9aU4TlI4gk 08YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=oQGesBCrx1a20TNDG5raXau/XWkcj0ACKpUaPPCtpbE=; b=E6xEKYqm9kruXqZdEKIptezlkLT9uSAeQJn5X4GNUaMzySP/5YImzdWtEFDjkJizwU h2nDfUAupi77V/Quns9N0Q2N1CS9XYmfRYBVBiDQF+wUqueuWMNagIhk42+PQF6Ypo22 S7MyuDzYPa95KZ/NgII3kMDgHx/IcKPK5oSsikVa3F/vzWie3xF6FPfXzT/ZvE14K/gx UIp8aMAdjtE5riQwPgc1DlHgJ+4u1OyIKucKq/ukafS8CfN4xEYEWzy33SSwbpp54/W3 6VNl32EbtvbYtNj949xUDjb2rgmBAGRkI+8DjjwSPbrqSG5CfjNFh+i9aS/nn+zirNKj bMcw== X-Gm-Message-State: AA6/9RmaAnToAU45dOSp84wP8ZcdOIJCRs7j3S4pTq7ZlI5uQpUbbkuVGNPTlLP9yX8a/k3kg7+KZtdRZcnWD9F1FADBNCRZs33wflRA29hvin+F+tudlbmVh6r+374Uv3XrBuFHLpEyeMPPVRrTyy5GQdPYn9pMMYuJEwxr30SRaK+Mma9sBTvlznq83kisZDFo+AkIXM5f X-Received: by 10.194.192.195 with SMTP id hi3mr11212383wjc.108.1475368456762; Sat, 01 Oct 2016 17:34:16 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id lf9sm13326201wjb.22.2016.10.01.17.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Oct 2016 17:34:15 -0700 (PDT) Subject: Re: PATCH: two slab-like memory allocators To: Jim Nasby , Petr Jelinek , pgsql-hackers@postgreSQL.org References: <68b837a3-ce55-f9a2-f685-9eafac536f21@2ndquadrant.com> <885540a7-ac72-5a21-6dae-a4d5b50672da@2ndquadrant.com> <03110c11-ea72-7b4d-027d-6f19eb300b2a@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Sun, 2 Oct 2016 02:34:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 10/02/2016 01:53 AM, Jim Nasby wrote: > On 9/26/16 9:10 PM, Tomas Vondra wrote: >> Attached is v2 of the patch, updated based on the review. That means: > > + /* make sure the block can store at least one chunk (with 1B for a > bitmap)? */ > (and the comment below it) > > I find the question to be confusing... I think these would be better as > > + /* make sure the block can store at least one chunk (with 1B for a > bitmap) */ > and > + /* number of chunks can we fit into a block, including header and > bitmap */ > Thanks, will rephrase the comments a bit. > I'm also wondering if a 1B freespace bitmap is actually useful. If > nothing else, there should probably be a #define for the initial > bitmap size. That's not the point. The point is that we need to store at least one entry per block, with one bit in a bitmap. But we can't store just a single byte - we always allocate at least 1 byte. So it's more an explanation for the "1" literal in the check, nothing more. > > + /* otherwise add it to the proper freelist bin */ > Looks like something went missing... :) > Ummm? The patch contains this: + /* otherwise add it to the proper freelist bin */ + if (set->freelist[block->nfree]) + set->freelist[block->nfree]->prev = block; + + block->next = set->freelist[block->nfree]; + set->freelist[block->nfree] = block; Which does exactly the thing it should do. Or what is missing? > > Should zeroing the block in SlabAlloc be optional like it is with > palloc/palloc0? > Good catch. The memset(,0) should not be in SlabAlloc() as all, as the zeroing is handled in mctx.c, independently of the implementation. > + /* > + * If there are no free chunks in any existing block, create a new > block > + * and put it to the last freelist bucket. > + */ > + if (set->minFreeCount == 0) > Couldn't there be blocks that have a free count > minFreeCount? (In > which case you don't want to just alloc a new block, no?) > > Nevermind, after reading further down I understand what's going on. I > got confused by "we've decreased nfree for a block with the minimum > count" until I got to the part that deals with minFreeCount = 0. I think > it'd be helpful if the "we've decreased nfree" comment mentioned that if > nfree is 0 we'll look for the correct value after updating the freelists. > Right. I think it'd be good to add an assert ensuring the minFreeCount value matches the block freelist. Or at least SlabCheck() could check this. > + block->bitmapptr[idx/8] |= (0x01 << (idx % 8)); > Did you consider using a pre-defined map of values to avoid the shift? I > know I've seen that somewhere in the code... > > Patch 2... > > Doesn't GenSlabReset() need to actually free something? If the call > magically percolates to the other contexts it'd be nice to note that in > the comment. No, the other contexts are created as children of GenSlab, so the memory context infrastructure resets them automatically. I don't think this needs to be mentioned in the comments - it's pretty basic part of the parent-child context relationship. Thanks! -- 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