pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: _mdfd_getseg can be expensive
Date: Fri, 31 Oct 2014 23:58:51 +0100
Message-ID: <20141031225851.GO13584@awork2.anarazel.de> (raw)
In-Reply-To: <12336.1414795725@sss.pgh.pa.us>
References: <20140331101001.GE13135@alap3.anarazel.de>
	<20141031223210.GN13584@awork2.anarazel.de>
	<12336.1414795725@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 2014-10-31 18:48:45 -0400, Tom Lane wrote:
> Andres Freund <andres@2ndquadrant.com> 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



view thread (25+ messages)  latest in thread

Message-ID: <20141031225851.GO13584@awork2.anarazel.de>
Permalink:  ../20141031225851.GO13584@awork2.anarazel.de/
Also on:    postgresql.org/message-id/20141031225851.GO13584@awork2.anarazel.de

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: andres@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: _mdfd_getseg can be expensive
  In-Reply-To: <20141031225851.GO13584@awork2.anarazel.de>
  References: <20140331101001.GE13135@alap3.anarazel.de> <20141031223210.GN13584@awork2.anarazel.de> <12336.1414795725@sss.pgh.pa.us> <20141031225851.GO13584@awork2.anarazel.de>

* 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