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 1mxu81-0002P7-VA for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 17:01: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 1mxu80-0007dC-PW for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 17:01:12 +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 1mxu80-0007Z5-3M for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 17:01:12 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mxu7r-0004cB-RX for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 17:01:11 +0000 Received: by mail-ed1-x52a.google.com with SMTP id z7so27572967edc.11 for ; Thu, 16 Dec 2021 09:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=jeC2UTQ9r3M+mbdHXJ85iX74ybD2/pZ6OHu9UqZQlbA=; b=ZiWJRFCjaCmWS//uVCZvWxHnnY7v6VkPZhKrn0og6MFUWVrQBvqglem79tipYJ0lg2 LmhRjEKq3NcRJ89vnjKQX9PnFY/YOTPKAAdzkNa93EfjVTvA7Si5gLRJeyifO3xAMBxu ezCGQun9kyxAmKLa2W3K1Shu+gX8Smvr1gVx7PpIiUlzAr4B02Cq2W+95YOMGZEBHvei d6sGmnsoppXCm1Gwo0wlLVb6L56yBzrFh/XVm9n4QnkGy7Ogk481fZIu/MyOZKr7vgSx QaujQTvrxNH23IxdfcT2pmcMZMVv4RX4kJT75nnTlZfiLZDDyjCvmh7ETguQYRJ8MEt3 CZXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=jeC2UTQ9r3M+mbdHXJ85iX74ybD2/pZ6OHu9UqZQlbA=; b=RKcmD9jJpiK/7rAtzwzOBYXvv6PYGlnAo+FOzGr3nzJAPfMyxd8PjhvRPfx0h+vcGe vrKspEyZy8+8YCuv0ycjhELIcmdIMnw0D/t+sLPI5G/ZOTEjVALyurEhVHWCTJBd1Gjx Ax5Z24wmDcauj06MTZg+NVAVmdKYSg7Qtc0QAiGW7Amey1jwwJPUdJ0nA18swoHr9fZl /I+i7gWM+hRpCMEdZ2/vFRlzYCak0uqcEk29v/934q+J4dE8zALP3NOVnTwJ8x4n3l/7 tg05Zz8qfjLO547deiTyQvPe2UnRv3Ma7ya6RusXVwlgmOHVdqKVQez5dpokMkrrDAjB kKPA== X-Gm-Message-State: AOAM5300Wtb+YvlGqqMtdV9zoAQLBgNaL3d6pS772Q7cvjMYrXegKqzo 6wJo9VphudhRShGUKBM1IJTgTSPHQ0DTduuVw6yk+lc0hzvzWZ1kUsNu+1DaqCO1ANXKAb6VFFZ k4U9RgLDAYwr5RaAXC8VUro+WRAtV+4vHmdSkC+8QQWRAvhpsb+AmQnS6WtAhk0XZlCjQaC9Mky lO8g/hQ83QZQg/rxnuh0K3cH4t/ZJa3IXD4zZ/Hlg4cNWB+JcT1Pzs X-Google-Smtp-Source: ABdhPJwQnzsAv6A7mNj3uzGSgPBnJ3wQMJHCCVAuDp/vp5jKWhkx0kK7Sea/OEanTbVGzcaKst2JsQ== X-Received: by 2002:a17:907:c22:: with SMTP id ga34mr16351337ejc.217.1639674060729; Thu, 16 Dec 2021 09:01:00 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id m6sm2753782edc.36.2021.12.16.09.00.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 09:01:00 -0800 (PST) Message-ID: <70b689dc-7ad4-138c-2c0b-9fcc131a1aaf@enterprisedb.com> Date: Thu, 16 Dec 2021 18:00:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: Use generation context to speed up tuplesorts Content-Language: en-US To: Ronan Dunklau , David Rowley , pgsql-hackers@lists.postgresql.org Cc: Andres Freund , Tomas Vondra References: <567d1ea7-bfeb-bd97-1a7f-b13d2770258c@enterprisedb.com> <2740198.88bMQJbFj6@aivenronan> <36444569.XM6RcZxFsP@aivenronan> From: Tomas Vondra In-Reply-To: <36444569.XM6RcZxFsP@aivenronan> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 12/16/21 17:03, Ronan Dunklau wrote: > Le jeudi 16 décembre 2021, 11:56:15 CET Ronan Dunklau a écrit : >> I will follow up with a benchmark of the test sorting a table with a width >> varying from 1 to 32 columns. >> > > So please find attached another benchmark for that case. > > The 3 different patchsets tested are: > > - master > - fixed (David's original patch) > - adjust (Thomas growing blocks patch) > Presumably Thomas is me, right? > So it looks like tuning malloc for this would be very benificial for any kind > of allocation, and by doing so we reduce the problems seen with the growing > blocks patch to next to nothing, while keeping the ability to not allocate too > much memory from the get go. > Thanks for running those tests and investigating the glibc behavior! I find those results very interesting. My conclusions from this is that the interaction interaction between "our" allocator and the allocator in malloc (e.g. glibc) can be problematic. Which makes benchmarking and optimization somewhat tricky because code changes may trigger behavior change in glibc (or whatever allocator backs malloc). I think it's worth exploring if we can tune this in a reasonable way, but I have a couple concerns related to that: 1) I wonder how glibc-specific this is - I'd bet it applies to other allocators (either on another OS or just different allocator on Linux) too. Tweaking glibc parameters won't affect those systems, of course, but maybe we should allow tweaking those systems too ... 2) In fact, I wonder if different glibc versions behave differently? Hopefully it's not changing that much, though. Ditto kernel versions, but the mmap/sbrk interface is likely more stable. We can test this. 3) If we bump the thresholds, won't that work against reusing the memory? I mean, if we free a whole block (from any allocator we have), glibc might return it to kernel, depending on mmap threshold value. It's not guaranteed, but increasing the malloc thresholds will make that even less likely. So we might just as well increase the minimum block size, with about the same effect, no? > I would like to try to implement some dynamic glibc malloc tuning, if that is > something we don't reject on principle from the get go. > +1 to that regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company