Re: mmap doubt??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/26/07, adheer chandravanshi <adheerchandravanshi@xxxxxxxxx> wrote:
Hi Rick,

> Could you please provide me reference where you read that mmap()
> implements on demand memory allocation?

I read it in "Understanding the Linux Kernel", 3rd Edition by Bovet and Cesati.

In chapter 16 "Accessing files"..section "memory mapping a file"

Below is the paragraph from the book which says it:

File memory mapping depends on the demand paging mechanism described
in the section "Demand Paging" in Chapter 9. In fact, a newly
established memory mapping is a memory region that doesn't include any
page; as the process references an address inside the region, a Page
Fault occurs and the Page Fault handler checks whether the nopage
method of the memory region is defined. If nopage is not defined, the
memory region doesn't map a file on disk; otherwise, it does, and the
method takes care of reading the page by accessing the block device.
Almost all disk-based filesystems and block device files implement the
nopage method by means of the filemap_nopage( ) function.

This is correct.
Because if you mmap a file and if you pass the mmaped address directly to kernel than kernel will complain bad address.
As no page table was created for it.

But if user application just uses that address, like printing first character as given below.
--
map_addr = mmap(NULL, mMapSize, PROT_READ | PROT_WRITE,
                            MAP_SHARED, fd, 0);

printf(" %c",*map_addr);

--
Then driver_nopage method is called which creates page table entry and then kernel understand that address.

Correct me if i am wrong???

Thanks,
Manisha










 

> thanks,
>
> Rick
>


Adheer

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux