Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hyd4O-0004tZ-2c for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2019 14:19:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hyd4M-00055J-SO for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2019 14:19:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hyd4M-00054X-GV for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2019 14:19:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hyd4K-0000Qk-4M for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2019 14:19:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7GEIwXM011213; Fri, 16 Aug 2019 10:18:58 -0400 From: Tom Lane To: Peter Eisentraut cc: Noah Misch , pgsql-hackers@lists.postgresql.org Subject: Re: Unexpected "shared memory block is still in use" In-reply-to: <8cd56b77-dfd9-cfbe-cad2-663939b5f510@2ndquadrant.com> References: <22224.1557340366@sss.pgh.pa.us> <20190509055414.GB1066859@rfd.leadboat.com> <2663.1557409654@sss.pgh.pa.us> <2226.1557439179@sss.pgh.pa.us> <17642.1557442078@sss.pgh.pa.us> <20190510072213.GA1098093@rfd.leadboat.com> <25485.1557500141@sss.pgh.pa.us> <16908.1557521200@sss.pgh.pa.us> <20190511190715.GA1124997@rfd.leadboat.com> <29530.1565738526@sss.pgh.pa.us> <8cd56b77-dfd9-cfbe-cad2-663939b5f510@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Fri, 16 Aug 2019 15:09:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11211.1565965138.1@sss.pgh.pa.us> Date: Fri, 16 Aug 2019 10:18:58 -0400 Message-ID: <11212.1565965138@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut writes: > On 2019-08-14 01:22, Tom Lane wrote: >> Attached is a draft patch to change both shmem and sema key selection >> to be based on data directory inode rather than port. > For the POSIX APIs where the numbers are just converted to a string, why > not use both -- or forget about the inodes and use the actual data > directory string. Considering that we still need an operation equivalent to "nextSemKey++" (in case of a key collision), I'm not really sure how working with strings rather than ints would make life better. > For the SYSV APIs, the scenario that came to my mind is if someone > starts a bunch of servers each on their own mount, it could happen that > the inodes of the data directories are very similar. Sure. That's why I didn't throw away any of the duplicate-key-handling logic, and why we're still checking for st_dev match when inspecting particular shmem blocks. (It also seems likely that somebody who's doing that would be using similar pathnames on the different mounts, so that string-based approaches wouldn't exactly be free of collision problems either.) > There is also the issue that AFAICT the key_t in the SYSV APIs is always > 32-bit whereas inodes are 64-bit. Probably not a big deal, but it might > prevent an exact one-to-one mapping. True, although the width of inode numbers is probably pretty platform- and filesystem-dependent. We could consider trying some more complicated mapping like xor'ing high and low halves, but I don't entirely see what it buys us. > Of course, ftok() is also available here as an existing solution. I looked at that briefly, but I don't really see what it'd buy us either, except for opacity which doesn't seem useful. The Linux man page pretty much says in so many words that it's a wrapper for st_ino and st_dev; and how does it help us if other platforms do it differently? (Actually, if Linux does it the way the man page suggests, it'd really be a net negative, because there'd only be 24 bits of key variation not 32.) regards, tom lane