Re: mmap() function call...
- From: Hallvard B Furuseth <h.b.furuseth@xxxxxxxxxxx>
- Date: Mon, 23 Apr 2007 14:10:18 +0200
Let's start from scratch... This may be a bit inaccurate, but anyway:
A process has a virtual address space (virtual memory).
Unless the process is swapped out, some or all of that virtual memory
is mapped to physical memory.
The virtual memory is also mapped to the swap file so that the process'
memory can be swapped/paged out if the system needs more memory. So if
you update some memory, the change will be carried through to the swap
file as well. If you read some allocated virtual memory which is not
mapped to physical memory, the corresponding data is read from the swap
file and into a new physical memory page, and the virtual memory page is
mapped do that.
mmap() with a file maps another file than the swap file to some virtual
memory. Depending on the mmap() flags, if you then update that memory,
the file is updated. If you read from that virtual memory, a chunk of
the file is if necessary read into physical memory and mapped to the
appropriate virtual memory page.
if i have a file of 100 Mb and RAM of 64 MB, will mmap() work?
If your _virtual_ address space is larger than 100M (+ whatever the
process is already using), that's no problem. If a process is using
200M virtual memory but you only have 64M phyiscal memory, then only
some of the virtual memory pages are mapped to physical memory at any
given time. The rest has been saved to the swap file or your mmapped
file. If the process tries to access an address which is not in memory
but is on file, the OS reads that address' page into a free physical
memory page from the swap/mmap file - likel after throwing some other
page out from physical memory to a file.
--
Hallvard
.
- Follow-Ups:
- Re: mmap() function call...
- From: sam_cit
- Re: mmap() function call...
- References:
- mmap() function call...
- From: sam_cit
- Re: mmap() function call...
- From: David Schwartz
- Re: mmap() function call...
- From: sam_cit
- mmap() function call...
- Prev by Date: Re: mmap() function call...
- Next by Date: Re: mmap() function call...
- Previous by thread: Re: mmap() function call...
- Next by thread: Re: mmap() function call...
- Index(es):
Relevant Pages
|