Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5AWU-000251-Rq for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Jul 2021 17:24:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5AVw-0005GV-NQ for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Jul 2021 17:23:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5AVw-0005GL-BB for pgsql-hackers@lists.postgresql.org; Sun, 18 Jul 2021 17:23:40 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5AVr-00076C-0G for pgsql-hackers@postgresql.org; Sun, 18 Jul 2021 17:23:38 +0000 Received: by mail-wr1-x436.google.com with SMTP id f17so18713408wrt.6 for ; Sun, 18 Jul 2021 10:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8Nf3qLcSVNOb44ZkYX92yLaAFuUC8fBfhIG+344Yx7E=; b=bLHOmkN8wGjTnEkSu8SapvByYOcvYWCpm+wjcaaUoxoRpM4STZouWVpojHF/0ZVNyS q31Ip+wNpJ/49BAYODGWukR84xHPITI8FlD6iDVj18eAeOPm/adXAJrgTUrKvTj5EQI3 o+jVMW6VHPKeuVZw525Wt1NapkJUHw7Zjv0eSSXMJFFoKP6rdUUgxO+vEPfCN1+WnUMD PmCUbWx1IVDQITEZN8m9XtpN6HxLhqjT7RWai02zbYXkimv4RWcX9NoSOACRGE+txr/n 7GWStiKI84FjEZMJJr0VRKNhoUrV95GF/wnwzzt5Lrc0AdsANJOsabtSs1L6JcHwOZhk ABEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8Nf3qLcSVNOb44ZkYX92yLaAFuUC8fBfhIG+344Yx7E=; b=VjY6JnI19QmCdL9AavqIehjwnRMXWm5kmGq5Bwa3W8PhZbr8Pg5U7LlhsCrwo6L2SY PXoHCwBFtHp0G9PBChEweGZix8gRa5U9m4xv2wOx7/NODwVcl9ZXMJHMFBsJZfmurIZL DbqA3i4p692VGtOTAm8jN6/ygsuCwtiYgfTPYJ84mWz8ZoLgioGhG2C9zWv/HVI/pQMz ssuMVSxrBAoRZMGAex3yLcHYrsIyere5/ZvHSQa5Vr7LmUds10UkCcqbIerK4hkdOvt9 zMqon6h5HeFaInZCSkU4RnElqgJTB/gVRMBkyHsIOAbuLqHGj3BzAN2aX9zlww4ntZq5 /FRg== X-Gm-Message-State: AOAM530iiI7Jgqs62Ceaj6dAh1/oSBL+sAzFkSLjCDd0ASAxc96RzpSe bt6z6YBWa9Zx2c6UTSy5TBd2Y6AgFUoVB/0Iyz1ol9pgu4tQ4sBJAcQ+jvy2i7MMwiEhbcHWQho egCLV0wAhml4KfE9y2gM3m3W2QdlbfoSbJDsYEHu7EsMuOelzVqgFee5cP92mqJe3peq1DRh4RR Z7h6/gVuEAkjiVOa4RI28cF7IL0aDW02TjzOf6 X-Google-Smtp-Source: ABdhPJyMj9IYBaeuoZSa/S7ITwfwEB5UdF348olAUxxuDP5Flpm6EbeXj6L2Cy+U6W6DC6k6WRnHXA== X-Received: by 2002:adf:eed0:: with SMTP id a16mr24445553wrp.324.1626629013829; Sun, 18 Jul 2021 10:23:33 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id t16sm5462249wmj.16.2021.07.18.10.23.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Jul 2021 10:23:33 -0700 (PDT) Subject: Re: slab allocator performance issues To: Andres Freund Cc: pgsql-hackers@postgresql.org, Tomas Vondra References: <20210717194333.mr5io3zup3kxahfm@alap3.anarazel.de> <20210717211405.3ocp2rpxlnozg3tq@alap3.anarazel.de> <02ff3ced-3212-aea1-c7a0-4829f43e58d2@enterprisedb.com> <20210717231019.blfhyqniu6jed3ym@alap3.anarazel.de> <20210718010600.fat2f5j4gvqig56j@alap3.anarazel.de> From: Tomas Vondra Message-ID: <37dc9b41-dd75-251d-a77e-16c72c794b00@enterprisedb.com> Date: Sun, 18 Jul 2021 19:23:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210718010600.fat2f5j4gvqig56j@alap3.anarazel.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/18/21 3:06 AM, Andres Freund wrote: > Hi, > > On 2021-07-17 16:10:19 -0700, Andres Freund wrote: >> Instead of populating a linked list with all chunks upon creation of a block - >> which requires touching a fair bit of memory - keep a per-block pointer (or an >> offset) into "unused" area of the block. When allocating from the block and >> theres still "unused" memory left, use that, instead of bothering with the >> freelist. >> >> I tried that, and it nearly got slab up to the allocation/freeing performance >> of aset.c (while winning after allocation, due to the higher memory density). > > Combining that with limiting the number of freelists, and some > microoptimizations, allocation performance is now on par. > > Freeing still seems to be a tad slower, mostly because SlabFree() > practically is immediately stalled on fetching the block, whereas > AllocSetFree() can happily speculate ahead and do work like computing > the freelist index. And then aset only needs to access memory inside the > context - which is much more likely to be in cache than a freelist > inside a block (there are many more). > > But that's ok, I think. It's close and it's only a small share of the > overall runtime of my workload... > Sounds great! Thanks for investigating this and for the improvements. It might be good to do some experiments to see how the changes affect memory consumption for practical workloads. I'm willing to spend soem time on that, if needed. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company