Re: Caching number of blocks in relation to avoi lseek.

From: Alfred Perlstein <bright(at)wintelcom(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Denis Perchine <dyp(at)perchine(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Caching number of blocks in relation to avoi lseek.
Date: 2000-06-13 03:01:48
Message-ID: 20000612200147.F18462@fw.wintelcom.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

* Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> [000612 19:37] wrote:
> Denis Perchine <dyp(at)perchine(dot)com> writes:
> > No... You did not get me. I am talking about completly different thing:
> > I strace'ed postgres binary when doing queries and found out that it
> > do lseek after each read, and the difference in the position is 8096.
> > It means that we are in correct position anyway and do not need additional lseek.
>
> Oh. Hmm. Not sure if it's really worth the trouble, but you could try
> having fd.c keep track of the current seek position of VFDs when they
> are open as well as when they are closed, and optimize away the lseek
> call in FileSeek if the position is already right. You'd have to think
> carefully about what to do if a read or write fails, however --- where
> has the kernel left its seek position in that case? Possibly this could
> be dealt with by setting the internal position to "unknown" anytime
> we're not perfectly sure where the kernel is.

Have you thought of using pread/pwrite which are available on many
modern platforms:

ssize_t
pread(int d, void *buf, size_t nbytes, off_t offset)

Pread() performs the same function, but reads from the specified
position in the file without modifying the file pointer.

I'm unsure how the postgresql system uses it's fds, however if they
are really shared via dup() or across fork/exec they will share
the same offset across multiple instances of the fd. The only way
around this behavior is to reopen the file in each process to get
a private offset.

--
-Alfred Perlstein - [bright(at)wintelcom(dot)net|alfred(at)freebsd(dot)org]
"I have the heart of a child; I keep it in a jar on my desk."

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hiroshi Inoue 2000-06-13 03:08:02 RE: ALTER TABLE DROP COLUMN
Previous Message Tom Lane 2000-06-13 02:41:52 Re: memory management suggestion

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2000-06-13 07:48:05 Re: Patches for SGI IRIX 6.x
Previous Message Tom Lane 2000-06-13 02:34:41 Re: Caching number of blocks in relation to avoi lseek.