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 1m5j42-0001Qb-WA for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 06:17:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5j41-00033o-PT for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 06:17:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5j40-00033L-DR for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 06:17:09 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5j3t-0001Kv-Bi for pgsql-hackers@postgresql.org; Tue, 20 Jul 2021 06:17:07 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BB7565C01DF; Tue, 20 Jul 2021 02:16:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 20 Jul 2021 02:16:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=bOukZu1a2Cq3LJOiI18sX2H2TVK JaKUGoPVhVz1VwQQ=; b=t1rOlCpFK2zI+SwVGAGwecxMyH7juCrTHOR0gLnaMxK +DsvR5TZHuK7lCaoIWX2JbUYdUpNuIHhqsfRGznPR6aC8+Cl0OCdTMSpwo4u9lnz taVyyTe4P7mAPqqIr4FSSAaVqn4wOmvp6O5I6myLyGhUAwQbOQs57dlVfxaWQ2/S uE9YCTqWKKCshPOhMROdUf0qsdRFv1mtJOJ3BkHJvC2yRx7XiGYpatb9dujABZY/ sJ9xrN63+skbKYEVsJQsDRQQ48/od02UfKJ+TFvCspuPHYg6R/sIKcSEC/+YA8dv fFOlNHZ3NF4ezwmrWMU5Sz8M6lAs04SUCVmCZYcEWYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=bOukZu 1a2Cq3LJOiI18sX2H2TVKJaKUGoPVhVz1VwQQ=; b=ewUhkzPrsrZl/NUYCq/Pxk /hq3jhcR1r34IsADAGe4gnc7+dOvuDY4DX+dEAgErjK7VtP3jnbMfS+5OOx1OKg/ h32L2Th+r8Y1SLNNpcqJbltDqKwhx/hPW7YRDz31CYYpJ/qF2u3f4ahtpi8zYYD1 SpLdfX/hKELq2a3txgbYgFi/Ur9724rxlSM9DfIT2SIyeOmNSiFtw+mLgV9zmLNS tIaRAG3mgyVvDuH+0pWlzJ71jpmNARYw35ROUid+y2oj2zXbS9riKGJGMp15OpTY 0l9SkNG+kLHD6QG6L98MzCCofEgehzdSb2crf0kEhj99QnnyLI6xitAVA1zts3hQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrfedugdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepudekhfekleeugeevteehleffffejgeelueduleeffeeutdelffeujeffhfeu ffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Jul 2021 02:16:58 -0400 (EDT) Date: Mon, 19 Jul 2021 23:16:57 -0700 From: Andres Freund To: David Rowley Cc: PostgreSQL-development , Robert Haas , Michael Paquier , Tomas Vondra Subject: Re: Avoid stack frame setup in performance critical routines using tail calls Message-ID: <20210720061657.bcueir3krgmkt6m5@alap3.anarazel.de> References: <20210719195950.gavgs6ujzmjfaiig@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2021-07-20 16:50:09 +1200, David Rowley wrote: > I've not taken the time to study the patch but I was running some > other benchmarks today on a small scale pgbench readonly test and I > took this patch for a spin to see if I could see the same performance > gains. Thanks! > This is an AMD 3990x machine that seems to get the most throughput > from pgbench with 132 processes > > I did: pgbench -T 240 -P 10 -c 132 -j 132 -S -M prepared > --random-seed=12345 postgres > > master = dd498998a > > Master: 3816959.53 tps > Patched: 3820723.252 tps > > I didn't quite get the same 2-3% as you did, but it did come out > faster than on master. It would not at all be suprising to me if AMD in recent microarchitectures did a better job at removing stack management overview (e.g. by better register renaming, or by resolving dependencies on %rsp in a smarter way) than Intel has. This was on a Cascade Lake CPU (xeon 5215), which, despite being released in 2019, effectively is a moderately polished (or maybe shoehorned) microarchitecture from 2015 due to all the Intel troubles. Whereas Zen2 is from 2019. It's also possible that my attempts at avoiding the stack management just didn't work on your compiler. Either due to vendor (I know that gcc is better at it than clang), version, or compiler flags (e.g. -fno-omit-frame-pointer could make it harder, -fno-optimize-sibling-calls would disable it). A third plausible explanation for the difference is that at a client count of 132, the bottlenecks are sufficiently elsewhere to just not show a meaningful gain from memory management efficiency improvements. Any chance you could show a `perf annotate AllocSetAlloc` and `perf annotate palloc` from a patched run? And perhaps how high their percentages of the total work are. E.g. using something like perf report -g none|grep -E 'AllocSetAlloc|palloc|MemoryContextAlloc|pfree' It'd be interesting to know where the bottlenecks on a zen2 machine are. Greetings, Andres Freund