Re: Improve lseek scalability v3

From: Greg Stark <stark(at)mit(dot)edu>
To: Benjamin LaHaise <bcrl(at)kvack(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Matthew Wilcox <matthew(at)wil(dot)cx>, Andi Kleen <andi(at)firstfloor(dot)org>, viro(at)zeniv(dot)linux(dot)org(dot)uk, linux-fsdevel(at)vger(dot)kernel(dot)org, linux-kernel(at)vger(dot)kernel(dot)org, robertmhaas(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Improve lseek scalability v3
Date: 2011-09-16 22:44:59
Message-ID: CAM-w4HNAJVRx5Vj87hXjL9JDjwbUoDiso_NZcfomk7wpd2zshw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 16, 2011 at 9:08 PM, Benjamin LaHaise <bcrl(at)kvack(dot)org> wrote:
> For such tables, can't Postgres track the size of the file internally?  I'm
> assuming it's keeping file descriptors open on the tables it manages, in
> which case when it writes to a file to extend it, the internally stored size
> could be updated.  Not making a syscall at all would scale far better than
> even a modified lseek() will perform.

There's no hardwired limit on how many tables you can have in a
database, it's not limited by the number of file descriptors. Postgres
would have to keep some kind of LRU for recently opened files and
their sizes or something like that. There would probably still be a
lot of lseeks/fstats going on.

Generally keeping a Postgres cached value for the size would then have
a reliability issue. It's much safer to have a single authoritative
value -- the actual length of the file -- than have the same value
stored in two locations and then need to worry about them getting out
of sync. If a write fails when extending the file due to a filesystem
running out of space then Postgres might not know how to update its
internal cached state accurately for example.

There's no question it could be done but it's not clear it would
necessarily be much faster than a lock-free lseek/fstat.

On Fri, Sep 16, 2011 at 6:27 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> It depends on where the information is used. For some of the uses it needs to
> be exact (the assumed size is rechecked after acquiring a lock preventing
> extension)

Fwiw this might give the wrong impression. I don't believe scans
acquire a lock preventing extension -- that is another process can be
concurrently extending the file at the same time as the scan is
proceeding. The scan only locks out truncation (vacuum). Any blocks
added by another process are ignored by the scan because they can only
contain records invisible to that transaction. This does depend on the
lseek/fstat being done after the transaction snapshot is taken which
is possibly "rechecking" the value taken by the query planner but
they're really two independent things.

--
greg

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-09-16 23:27:32 Re: patch: plpgsql - remove unnecessary ccache search when a array variable is updated
Previous Message Andres Freund 2011-09-16 21:05:18 Re: Improve lseek scalability v3