excessive memcpy() calls?

From: Alan Stange <stange(at)rentec(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: excessive memcpy() calls?
Date: 2002-08-06 20:40:01
Message-ID: 3D503421.3010306@rentec.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello all,

we have a fairly complicated query that we thought might run a bit
faster, so ran postgress under a profiler. We're running on Solaris 8
using the Sun Forte 7 compilers and it's profiler tools that can collect
execution profiles on a clock based profile as well as various hardware
counter overflow profiles. The database is fairly small at 800MB in size.

Using the collected data and poking around a bit it looks like memcpy()
is being called a lot of times. The total run time for the query is 223
cpu seconds of which 15.3 is in memcpy(). Of these 15 seconds, 6.8
comes from LogicalTapeRead() and 4 from BufFileRead().

Now here's the rub: LogicalTapeRead() calls ltsReadBlock() which calls
BufFileRead() which calls BufFileLoadBuffer() which calls FileRead().

FileRead() actually calls the read() system call which puts the relevant
bytes into a buffer in user space (and involves a copy of the data).
Working our way back up the call chain, BufFileRead() calls memcpy(),
performing another copy of the bytes into a second buffer. Going
further back up the call chain we find that LogicalTapeRead() again
calls memcpy() copying the bytes a *third* time into another buffer.

Is it possible that one of these copies can be removed? It seems to me
that one can be, but I'm only looking at the source for the first time
and perhaps I'm missing something. Yes, I know, this is only 6% of the
cpu time, but memory busses are relatively slow and this copying is
probably flushing some cpu cache as well.

-- Alan
stange(at)rentec(dot)com

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2002-08-06 21:17:50 Re: Open 7.3 items
Previous Message Peter Eisentraut 2002-08-06 20:26:14 Join syntax and join order