pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Dilger <mark.dilger@enterprisedb.com>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Andrey Borodin <x4mmm@yandex-team.ru>
Cc: pgsql-hackers@postgresql.org
Subject: Re: pglz compression performance, take two
Date: Fri, 19 Mar 2021 12:35:46 -0700
Message-ID: <EB24F56E-901B-46D6-BFFC-71D51603ABDE@enterprisedb.com> (raw)
In-Reply-To: <20210122024811.GE27167@telsasoft.com>
References: <FEF3DC5E-4BC4-44E1-8DEB-DADC67046FE3@yandex-team.ru>
	<D75ABE30-2AAA-47DB-A89F-665E03BAAD2A@yandex-team.ru>
	<25991595-1848-4178-AA57-872B10309DA2@yandex-team.ru>
	<20201230043930.GG25152@telsasoft.com>
	<BF0A7E6D-AB21-47F8-A5FA-328CAA32DB12@yandex-team.ru>
	<20210122024811.GE27167@telsasoft.com>



> On Jan 21, 2021, at 6:48 PM, Justin Pryzby <pryzby@telsasoft.com> wrote:
> 
> @cfbot: rebased
> <0001-Reorganize-pglz-compression-code.patch>

Review comments.

First, I installed a build from master without this patch, created a test installation with lots of compressed text and array columns, upgraded the binaries to a build with this patch included, and tried to find problems with the data left over from the pre-patch binaries.  Everything checks out.  This is on little-endian mac osx intel core i9, not on any ARM platform that you are targeting with portions of the patch.

+/**************************************
+ *  CPU Feature Detection            *
+ **************************************/
+/* PGLZ_FORCE_MEMORY_ACCESS
+ * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
+ * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
+ * The below switch allow to select different access method for improved performance.
+ * Method 0 (default) : use `memcpy()`. Safe and portable.
+ * Method 1 : direct access. This method is portable but violate C standard.
+ *         It can generate buggy code on targets which assembly generation depends on alignment.
+ *         But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
+ * See https://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
+ * Prefer these methods in priority order (0 > 1)
+ */

The link to blogspot.fr has a lot more information than your summary in the code comments.  It might be hard to understand this comment if the blogspot article were ever to disappear.  Perhaps you could include a bit more of the relevant details?

+#ifndef PGLZ_FORCE_MEMORY_ACCESS   /* can be defined externally */
+#if defined(__GNUC__) && \
+  ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) \
+  || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
+#define PGLZ_FORCE_MEMORY_ACCESS 1
+#endif
+#endif

I can understand wanting to set this on gcc + ARMv6, but doesn't this belong in a configure script rather than directly in the compression code?

The blogspot article indicates that the author lied about alignment to the compiler when using gcc on ARMv6, thereby generating a fast load instruction which happens to work on ARMv6.  You appear to be using that same approach.  Your #if defined(__GNUC__), seems to assume that all future versions of gcc will generate the instructions that you want, and not start generating some other set of instructions.  Wouldn't you at least need a configure test to verify that the version of gcc being used generates the desired assembly?  Even then, you'd be banking on gcc doing the same thing for the test code and for the pglz code, which I guess might not be true.  Have you considered using inline assembly instead?



—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company








view thread (32+ messages)  latest in thread

Message-ID: <EB24F56E-901B-46D6-BFFC-71D51603ABDE@enterprisedb.com>
Permalink:  ../EB24F56E-901B-46D6-BFFC-71D51603ABDE@enterprisedb.com/
Also on:    postgresql.org/message-id/EB24F56E-901B-46D6-BFFC-71D51603ABDE@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: mark.dilger@enterprisedb.com, pryzby@telsasoft.com, x4mmm@yandex-team.ru
  Subject: Re: pglz compression performance, take two
  In-Reply-To: <EB24F56E-901B-46D6-BFFC-71D51603ABDE@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox