Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XkL9q-00065x-AS for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2014 22:59:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XkL9p-0001DX-RQ for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2014 22:59:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XkL9o-0001DQ-2Y for pgsql-hackers@postgresql.org; Fri, 31 Oct 2014 22:59:00 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XkL9k-0006w3-4z for pgsql-hackers@postgresql.org; Fri, 31 Oct 2014 22:58:58 +0000 Received: from anarazel.de (p5DDC7785.dip0.t-ipconnect.de [93.220.119.133]) by mrelayeu.kundenserver.de (node=mreue102) with ESMTP (Nemesis) id 0MRknR-1Xe81t3Wzx-00SybP; Fri, 31 Oct 2014 23:58:52 +0100 Received: by anarazel.de (Postfix, from userid 1000) id DE25410093A; Fri, 31 Oct 2014 23:58:51 +0100 (CET) Date: Fri, 31 Oct 2014 23:58:51 +0100 From: Andres Freund To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: _mdfd_getseg can be expensive Message-ID: <20141031225851.GO13584@awork2.anarazel.de> References: <20140331101001.GE13135@alap3.anarazel.de> <20141031223210.GN13584@awork2.anarazel.de> <12336.1414795725@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <12336.1414795725@sss.pgh.pa.us> X-Provags-ID: V02:K0:aoa0pgJh0VfpNVtbkROkNr4PLRiDVw4tI+zlNOZ/ALN Y51fPKZ+nQ6lgAhKWZ1XiV0HtwSQS6ff57S1iQQl25lVxE+40k duc8ad+Jk5Bf04H9O+zL1xoSAQ5ekS1yFeKxpOvWKib5s+Uze7 pNhaecoiYBHJZ8zc60CmKNvuDF3xxADnBgAqLuRU33lagY9j10 V8u6RvdStpAbxNKtboTaXyboVzNPn6sCXTeVffiD4WCirLxYvU FryksoalWds4+ePhJ1WhwSX4cesfkHCI/7XsN9aycWqkXZVUh0 Uk/aHrVLZEJWUBxIe2e0Vzfe840b1kcxC5SkHvoGfxZnYl8iui 61X5qFK80cT2LedpgtnzHBGysnstDttDLqtdEuAEF X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2014-10-31 18:48:45 -0400, Tom Lane wrote: > Andres Freund writes: > > I wrote the attached patch that get rids of that essentially quadratic > > behaviour, by replacing the mdfd chain/singly linked list with an > > array. Since we seldomly grow files by a whole segment I can't see the > > slightly bigger memory reallocations matter significantly. In pretty > > much every other case the array is bound to be a winner. > > > Does anybody have fundamental arguments against that idea? > > While the basic idea is sound, this particular implementation seems > pretty bizarre. What's with the "md_seg_no" stuff, and why is that > array typed size_t? > IOW, why didn't you *just* replace the linked list with an array? It stores the length of the array of _MdfdVec entries. To know whether it's safe to access some element we first need to check whether we've loaded that many entries. It's size_t[] because that seemed to be the most appropriate type for the lenght of an array. It's an array because md.c had already chosen to represent relation forks via an array indexed by the fork. So size_t md_seg_no[MAX_FORKNUM + 1]; contains the length of the _MdfdVec array for each fork. These arrays are stored in: struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1]; > This patch seems to be making some other changes that you've failed to > explain. I'm not aware of any that aren't just a consequence of not iterating through the linked list anymore. What change are you thinking of? Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers