Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMta2-007Ug2-E9 for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 17:38:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rMtZ2-006o68-Up for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 17:37:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMtZ2-006o5y-LM for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2024 17:37:28 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMtYw-000Vjo-8M for pgsql-hackers@postgresql.org; Mon, 08 Jan 2024 17:37:28 +0000 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3608cfa5ce6so7670715ab.0 for ; Mon, 08 Jan 2024 09:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704735440; x=1705340240; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=J9QiCg3fCRLNYbxyT5j0QL97reQ5m4IFznFZQ9CqBUM=; b=AaNs6GSp02pDEok+1hi0ijiLEcu5dQ1n93tlZb4vYez9JgjLrLRrbqKKWJsd9B3E3J u1/RXX64cLMsnoOixTnWFDl1VtXLSRHQ19M44ZesWSX2xPtouyrO6ixjUM9gWsBaUho/ 0Qlq/yolgiG9ScCSxtzoPX0Cl6XIfSMTjSGA+Trm6y/gbAIhJm4jYBeq536crnSmHwtZ 6MaUcnCSjDN+bW91/GJmamicvJu85o0WaStsj8FEo9hQJh6bf6lS8k4SHTsehzLloj6o BBIwMdvIcSRySvtPT9bWyU/SItouD5Ck3oAbXhJ5w9USg3caK9dJZZF31HQcLkMdoyyY 1bcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704735440; x=1705340240; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J9QiCg3fCRLNYbxyT5j0QL97reQ5m4IFznFZQ9CqBUM=; b=CCL9+knMt3wl+YENcmiqOLnImgwRbOCVP9iwRT+accuTWwIy4IuOkw+zOj5WeWKh0l rpwUnVFgGCQ69iOBB/xLNzhd2L6wgzt772+8O7i5QPlTYYX4pYl600J5+NeEZREfWe8m 7PDbiNoWFV2YsiVzaP9wuCry78HYXwAZYplDeWSMd+XyR8DaaXA7lygjcI7+9WR9MwVy t9473iVnIgVm4h7S7Zvg69BPPuQvKqFgkb+1gq692h1xwETYo0svebYT9pQ9ZTTMXTzH e/JNr3bcavA2+V+m7veq45FSFT5k1erM4Eqapf6C/2f0ir0DbgR0ivo+FZV6CL0sYuKP PvTQ== X-Gm-Message-State: AOJu0YyH73R+LfYDAqyzMpV3BndpDEe7Wwm79p4YwS7VkRdgas1Qsobi zXDCPfIFGntgKSgYltm6wDc= X-Google-Smtp-Source: AGHT+IGk45Z0aHUHBPXek4F1OPZ9m7ZVyCNWajOS5aeseW09TOHFDViduUaPtwwCE5dS3Y2O1H4WnQ== X-Received: by 2002:a92:ca09:0:b0:360:7c05:e479 with SMTP id j9-20020a92ca09000000b003607c05e479mr7289426ils.47.1704735437995; Mon, 08 Jan 2024 09:37:17 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id do29-20020a0566384c9d00b0046e0566ebe9sm81395jab.107.2024.01.08.09.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 09:37:17 -0800 (PST) Date: Mon, 8 Jan 2024 11:37:15 -0600 From: Nathan Bossart To: John Naylor Cc: Ants Aasma , pgsql-hackers@postgresql.org Subject: Re: add AVX2 support to simd.h Message-ID: <20240108173715.GC2611898@nathanxps13> References: <20231129171526.GA857928@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 08, 2024 at 02:01:39PM +0700, John Naylor wrote: > On Thu, Nov 30, 2023 at 12:15 AM Nathan Bossart > wrote: >> writers sse2 avx2 % >> 256 1195 1188 -1 >> 512 928 1054 +14 >> 1024 633 716 +13 >> 2048 332 420 +27 >> 4096 162 203 +25 >> 8192 162 182 +12 > > There doesn't seem to be any benefit at 256 at all. Is that expected > and/or fine? My unverified assumption is that the linear searches make up much less of the benchmark at these lower client counts, so any improvements we make here are unlikely to show up here. IIRC even the hash table approach that we originally explored for XidInMVCCSnapshot() didn't do much, if anything, for the benchmark at lower client counts. > Here, the peak throughput seems to be around 64 writers with or > without the patch from a couple years ago, but the slope is shallower > after that. It would be good to make sure that it can't regress near > the peak, even with a "long tail" case (see next paragraph). The first > benchmark above starts at 256, so we can't tell where the peak is. It > might be worth it to also have a microbenchmark because the systemic > one has enough noise to obscure what's going on unless there are a > very large number of writers. We know what a systemic benchmark can > tell us on extreme workloads past the peak, and the microbenchmark > would tell us "we need to see X improvement here in order to see Y > improvement in the system benchmark". Yes, will do. > I suspect that there could be a regression lurking for some inputs > that the benchmark doesn't look at: pg_lfind32() currently needs to be > able to read 4 vector registers worth of elements before taking the > fast path. There is then a tail of up to 15 elements that are now > checked one-by-one, but AVX2 would increase that to 31. That's getting > big enough to be noticeable, I suspect. It would be good to understand > that case (n*32 + 31), because it may also be relevant now. It's also > easy to improve for SSE2/NEON for v17. Good idea. If it is indeed noticeable, we might be able to "fix" it by processing some of the tail with shorter vectors. But that probably means finding a way to support multiple vector sizes on the same build, which would require some work. > Also, by reading 4 registers per loop iteration, that's 128 bytes on > AVX2. I'm not sure that matters, but we shouldn't assume it doesn't. > Code I've seen elsewhere reads a fixed 64-byte block, and then uses 1, > 2, or 4 registers to handle it, depending on architecture. Whether or > not that's worth it in this case, this patch does mean future patches > will have to wonder if they have to do anything differently depending > on vector length, whereas now they don't. That's not a deal-breaker, > but it is a trade-off to keep in mind. Yeah. Presently, this AVX2 patch just kicks the optimization down the road a bit for the existing use-cases, so you don't start using the vector registers until there's more data to work with, which might not even be noticeable. But it's conceivable that vector length could matter at some point, even if it doesn't matter much now. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com