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 1qE2HA-0008Lp-Nx for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jun 2023 06:34:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qE2H9-0001Mb-JA for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jun 2023 06:34:07 +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 1qE2H9-0001Li-7l for pgsql-hackers@lists.postgresql.org; Tue, 27 Jun 2023 06:34:07 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qE2H6-000jIT-KM for pgsql-hackers@postgresql.org; Tue, 27 Jun 2023 06:34:06 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31114b46d62so4888260f8f.3 for ; Mon, 26 Jun 2023 23:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; t=1687847643; x=1690439643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lCKu2jppED3pS90D6KPdoco2DX9hdWotjzBi+S6/dHo=; b=APISmbjJYHPv4t4icUFgXToTVDiJakAclnU8+aAgDq+KrcPHcbijYqLsQxD0SyK5gr +WbAdeC7hKe/jAUq0EaisJoQtuyXVbWTCUc0Tt58vMS/T5ipPIV5JzaCBKWAykJCoMwP ySahC6uX8eeeo4Tyd8hyPY3W73hY6WohdpJQA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687847643; x=1690439643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lCKu2jppED3pS90D6KPdoco2DX9hdWotjzBi+S6/dHo=; b=HVB2CbzDBgIhggmPVNIed0r+n2ib/h7nWTbmdV9y+ubnm797ZnxLBeKl3FhMX45L1a 07OR/qN9SG10j6i+hzpXcy5y/HX7kJLI1+q7R82GnLkCpOO/7UZ4l/rl2qKY/AiAPCnR WEvI5In0kc2TWBmECeniLmr0uAxHjRtov5kXcTsZfxPJNAJPDq+ikoG5rXmL1aYVQPeN WzEMxe/x9lmtephFzXSnv5KUYJ+YsyV5NibfzazQ779pUHehXvAZzX1rgfygq51THJWO 3hQNf5GrgUn3ddNGFqYbpR2NHB6cqQDrrRetLRpSAXS5vww087+5IbdzeFlO9RG7OEEn hqfQ== X-Gm-Message-State: AC+VfDySMhfmriZPfThxkY+ytShGBoufjoU4NmwEQIzZOxFT63xbEbfu 90UfMic61Hj6yd6YrfqOwAXYoQ== X-Google-Smtp-Source: ACHHUZ76Vxl98P7ZxZ1nJtOD4lpLSctdg9w3BfkvmUtiE23xBmtGGfh22mjXgrrjBqislSRrO/GR4A== X-Received: by 2002:a05:6000:1047:b0:313:ded8:f346 with SMTP id c7-20020a056000104700b00313ded8f346mr8636364wrx.22.1687847643444; Mon, 26 Jun 2023 23:34:03 -0700 (PDT) Received: from aivenlaptop.localnet ([45.13.105.93]) by smtp.gmail.com with ESMTPSA id s6-20020a5d4ec6000000b0030ae849c70csm9360145wrv.37.2023.06.26.23.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 23:34:02 -0700 (PDT) From: Ronan Dunklau To: Andres Freund Cc: pgsql-hackers@postgresql.org, Peter Eisentraut , tomas.vondra@enterprisedb.com Subject: Re: Add GUC to tune glibc's malloc implementation. Date: Tue, 27 Jun 2023 08:35:28 +0200 Message-ID: <8235070.T7Z3S40VBb@aivenlaptop> In-Reply-To: <20230626210348.rk4h3bscdtcwbe7o@awork3.anarazel.de> References: <3424675.QJadu78ljV@aivenlaptop> <2285512.ElGaqSPkdT@aivenlaptop> <20230626210348.rk4h3bscdtcwbe7o@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart10293421.nUPlyArG6x" Content-Transfer-Encoding: 7Bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --nextPart10293421.nUPlyArG6x Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Le lundi 26 juin 2023, 23:03:48 CEST Andres Freund a =E9crit : > Hi, >=20 > On 2023-06-26 08:38:35 +0200, Ronan Dunklau wrote: > > I hope what I'm trying to achieve is clearer that way. Maybe this patch= is > > not the best way to go about this, but since the memory allocator > > behaviour can have such an impact it's a bit sad we have to leave half > > the performance on the table because of it when there are easily > > accessible knobs to avoid it. > I'm *quite* doubtful this patch is the way to go. If we want to more > tightly control memory allocation patterns, because we have more > information than glibc, we should do that, rather than try to nudge glibc= 's > malloc in random direction. In contrast a generic malloc() implementation > we can have much more information about memory lifetimes etc due to memory > contexts. Yes this is probably much more appropriate, but a much larger change with=20 greater risks of regression. Especially as we have to make sure we're not=20 overfitting our own code for a specific malloc implementation, to the detri= ment=20 of others. Except if you hinted we should write our own directly instead ? >=20 > We e.g. could keep a larger number of memory blocks reserved > ourselves. Possibly by delaying the release of additionally held blocks > until we have been idle for a few seconds or such. I think keeping work_mem around after it has been used a couple times make= =20 sense. This is the memory a user is willing to dedicate to operations, afte= r=20 all. >=20 >=20 > WRT to the difference in TPS in the benchmark you mention - I suspect that > we are doing something bad that needs to be improved regardless of the > underlying memory allocator implementation. Due to the lack of detailed > instructions I couldn't reproduce the results immediately. I re-attached the simple script I used. I've run this script with different= =20 values for glibc_malloc_max_trim_threshold.=20 Best regards, =2D- Ronan Dunklau --nextPart10293421.nUPlyArG6x Content-Disposition: attachment; filename="bench.sh" Content-Transfer-Encoding: base64 Content-Type: application/x-shellscript; name="bench.sh" IyEvYmluL2Jhc2gKCnNlYz01CmRibmFtZT1wb3N0Z3JlcwpyZWNvcmRzPTEwMDAwCm1vZD0xMDAK CnBzcWwgLWMgImRyb3AgdGFibGUgaWYgZXhpc3RzIHQiICRkYm5hbWUKcHNxbCAtYyAiY3JlYXRl IHRhYmxlIHQgKGEgYmlnaW50IG5vdCBudWxsKSIgJGRibmFtZQpwc3FsIC1jICJpbnNlcnQgaW50 byB0IHNlbGVjdCB4ICUgJG1vZCBmcm9tIGdlbmVyYXRlX3NlcmllcygxLCRyZWNvcmRzKSB4IiAk ZGJuYW1lCnBzcWwgLWMgInZhY3V1bSBmcmVlemUgdCIgJGRibmFtZQoKZm9yIGkgaW4gezEuLjMy fQpkbwoJZWNobyAkaQoJcHNxbCAtYyAiZXhwbGFpbiBhbmFseXplIHNlbGVjdCAqIGZyb20gdCBv cmRlciBieSBhIG9mZnNldCAxMDAwMDAwMDAwIiAkZGJuYW1lIHwgZ3JlcCAtRSAiTWVtb3J5fERp c2siCgllY2hvICJzZWxlY3QgKiBmcm9tIHQgb3JkZXIgYnkgYSBvZmZzZXQgMTAwMDAwMDAwMCIg PiBiZW5jaC5zcWwKCWZvciBsb29wcyBpbiB7MS4uM30KCWRvCgkJcGdiZW5jaCAtbiAtTSBwcmVw YXJlZCAtVCAkc2VjIC1mIGJlbmNoLnNxbCAkZGJuYW1lIHwgZ3JlcCB0cHMKCWRvbmUKCglwc3Fs IC1jICJhbHRlciB0YWJsZSB0IGFkZCBjb2x1bW4gYyRpIGJpZ2ludCIgJGRibmFtZQoJcHNxbCAt YyAidXBkYXRlIHQgc2V0IGMkaSA9IGEiICRkYm5hbWUKCXBzcWwgLWMgInZhY3V1bSBmdWxsIHQi ICRkYm5hbWUKCXBzcWwgLWMgInZhY3V1bSBmcmVlemUgdCIgJGRibmFtZQpkb25lCgoK --nextPart10293421.nUPlyArG6x--