2

If i have memory mapped a file of size 10GB in a 1GB machine and if i trigger a file i/o, after making sure that the data requested is not in physical memory, will the fetched data get mapped to the corresponding virtual address in mmap?

When i access the same location using mmap, will it again do an i/o (or will it make use of the data that was fetched using file i/o)

Thanks in advance,

Gokul.

2
  • what OS? what hardware? what language platform? Commented Feb 21, 2010 at 18:52
  • I am actually looking for a general solution which will work in Windows, Linux and Open Solaris. Commented Feb 22, 2010 at 6:35

1 Answer 1

1

It depends on the platform, but in general it'll be treated like other memory (swapped out when not in use, swapped in when required), except that instead of using the normal swap files/partitions it swaps from the original file on disk.

Sign up to request clarification or add additional context in comments.

8 Comments

Say i read a portion of the file using file i/o, can i assign that memory into one range of address in mmap?
No, you don't use file i/o - you mmap the file, and then access it as if it were memory.
OK. Thanks. I was actually intending to combine async i/o with mmap, but seems like it is not possible.
@Gokul - Memory mapped IO is an inherently synchronous operation. When your thread hits a page that needs to be loaded from disk, it's because the CPU had a page fault while trying to access some memory. The thread can't do anything else until that page is retrieved or the IO ends in an error. It's not like an async operation you can return from and get back to later- the thread implicitly needs that data to continue.
@Gokul - In general yes because now the pages will be cached; assuming you don't do unbuffered IO and the OS implements a unified buffer cache (most do). To accomplish the same thing and save yourself the read buffer, you may as well have another thread read the first byte of each page ahead of time and incur the page faults first.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.