Re: [HACKERS] mmap vs read/write

From: ocie(at)paracel(dot)com
To: count0(at)fsj(dot)co(dot)jp
Cc: hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] mmap vs read/write
Date: 1998-05-15 22:50:45
Message-ID: 9805152250.AA06566@dolomite.paracel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Huw Rogers wrote:
>
> Someone posted a (readonly) benchtest of mmap vs
> read/write I/O using the following code:
>
> for (off = 0; 1; off += MMAP_SIZE)
> {
> addr = mmap(0, MMAP_SIZE, PROT_READ, 0, fd, off);
> assert(addr != NULL);
>
> for (j = 0; j < MMAP_SIZE; j++)
> if (*(addr + j) != ' ')
> spaces++;
> munmap(addr,MMAP_SIZE);
> }
>
> This is unfair to mmap since mmap is called once
> per page. Better to mmap large regions (many
> pages at once), then use msync() to force
> write any modified pages. Access purely in

Better yet, request the pages ahead of time and have another process
map them in "asynchronously". By the time the process is ready to map
the page in for itself, the page will have already been read in from
the disk, and a memory buffer will be allocated for it.

I want to try and implement this in a simple demo program when I get a
chance.

Ocie

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Richards 1998-05-15 23:09:31 sorting big tables :(
Previous Message Bruce Momjian 1998-05-15 22:16:58 Re: [HACKERS] mmap vs read/write