Re: [HACKERS] mmap vs read/write - Mailing list pgsql-hackers

From ocie@paracel.com
Subject Re: [HACKERS] mmap vs read/write
Date
Msg-id 9805152250.AA06566@dolomite.paracel.com
Whole thread Raw
In response to mmap vs read/write  (Huw Rogers <count0@fsj.co.jp>)
List 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

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] mmap vs read/write
Next
From: Michael Richards
Date:
Subject: sorting big tables :(