mmap, virtual memory, physical memory

mmap, virtual memory, physical memory

Post by Matthias Mulumba Lumal » Fri, 07 Jul 2000 04:00:00



Hi,
    Help I'm confused! From my readings on the Net and elsewhere it
would appear that the mmap system call is used to map a file into a
process's virtual memory, adding a new region to the address space. But
it seems also that this virtual mapping implies physical mapping  if the
corresponding physical pages are not already loaded (by some other
process), except for the MAP_ANONYMOUS case.
If this is so how can we have a page in a process's address space
(virtual memory) that is not present in physical memory? Of course this
can happen after swapping but initially when loading a program how do
you create its address space (virtual memory) without having all the
regions in physical memory? i.e. How do you provide for demand-paging?

                                Any help appreciated.
                                                                Mathias

 
 
 

mmap, virtual memory, physical memory

Post by Kaz Kylhe » Fri, 07 Jul 2000 04:00:00


On Thu, 06 Jul 2000 19:20:36 +0200, Matthias Mulumba Lumala


>Hi,
>    Help I'm confused! From my readings on the Net and elsewhere it
>would appear that the mmap system call is used to map a file into a
>process's virtual memory, adding a new region to the address space. But
>it seems also that this virtual mapping implies physical mapping  if the
>corresponding physical pages are not already loaded (by some other
>process), except for the MAP_ANONYMOUS case.

No, it does not imply a commit; mmap just creates the association between
a region of memory and the object on disk. The pages of the object
are loaded on demand.

Quote:>If this is so how can we have a page in a process's address space
>(virtual memory) that is not present in physical memory? Of course this
>can happen after swapping but initially when loading a program how do
>you create its address space (virtual memory) without having all the
>regions in physical memory? i.e. How do you provide for demand-paging?

It happens automatically; the mmap system call sets up the page tables
such that the entries indicate that the pages are not present. When the
``not present'' pages are accessed, they trigger page faults. The kernel's
response to the page faults exceptions is to load the page into memory,
and then update the page tables of the process to indicate that the page
is now present. Upon returning from the page fault, the instruction is
tried-again and this time succeeds.

--
#exclude <windows.h>

 
 
 

1. Real Memmory /Virtual Memory /Physical Memory Accountancy.

Dear Forum!
Any kind person to respond?

I used this program:

#include <stdio.h>
#include <sys/pstat.h>
main()
{
struct pst_static buf;
struct pst_dynamic dyn;
pstat_getstatic(&buf,sizeof(struct pst_static),1,0);
pstat_getdynamic(&dyn,sizeof(struct pst_dynamic),1,0);
printf("Total  Page Size=%dB\n",buf.page_size);
printf("Total  Phys memory=%dMB\n",buf.page_size/1024*buf.physical_memory/1024);
printf("Total  Virt memory=%dMB\n",buf.page_size/1024*dyn.psd_vm/1024);
printf("Active Virt memory=%dMB\n",buf.page_size/1024*dyn.psd_avm/1024);
printf("Total  Real memory=%dMB\n",buf.page_size/1024*dyn.psd_rm/1024);
printf("Active Real memory=%dMB\n",buf.page_size/1024*dyn.psd_arm/1024);
printf("Free        memory=%dMB\n",buf.page_size/1024*dyn.psd_free/1024);

Output is:

Page Size=4096B
Total  Phys memory=2047MB
Total  Virt memory=597MB
Active Virt memory=333MB
Total  Real memory=665MB
Active Real memory=352MB
Free        memory=263MB

I use HP-UX Release 11.0.

What is it's interpretation? How can I obtain 2047 MB using other
parameters?
Like Total Phys Memory = Total Real Memory + Total Free Memory or
something like that....
Virtual Memory - Does it have any share in RAM? I knew that it is the
disk space
getting used.
If real memory is 665MB Far less compared to Total Phys Memory then
why
there is some figure in the account head of Active Virual Memory? I am
confused...

I did man vmstat ..It did not said avm - actual virtual pages ..show
shall
I multiply the shown figure with Page Size=4096B? No where unit is
mentioned
in HP-UX 11.0 documentation.

Waiting eagerly for your reply.

Cheers!
Samik Nath

2. NEWBIE: Need a Windoze / Linux Peer-to-Peer

3. help on mmapping physical memory...

4. Sound Blaster Live driver not loading

5. mmap of physical device memory on MPC823e on Linux 2.4.18

6. Binding to the Network Card

7. MMAP: limiting physical memory hogging

8. IP MULTICAST LOOPBACK

9. Physical memory versus detected memory 2.4.7-10

10. Is "shared memory" a way to reduce physical memory usage?

11. Virtual / Physical memory address access in drivers ? help ?

12. Mapping Physical Memory To Kernel Virtual

13. Get Physical and Virtual memory using Forte C++