Allocating new pages, Operating System

Processes have valid and invalid entries on their page tables. The valid entries all point to some where "real" (e.g. a physical page, or some portion of disk in case of non-resident pages, etc). The entries that don't point anywhere are the entries that we will use when allocating a new page.

The allocation of new pages can be done in two ways: either via sbrk(), or via mmap(). If you want to increase the size of the heap (i.e. the number of valid pages), you can use sbrk().

Using mmap(), on the other hand, maps a ?le into a process' virtual address space. In the allocator you implemented, for example, you used mmap() to map memory addresses to the ?le /dev/zero. This makes it seem like you were allocating space from /dev/zero each time you called mmap(). (Remember that whenever you read something from /dev/zero, you get only zeroes for as long as you want to keep reading.) But, since /dev/zero is a read-only ?le and we usually call mmap() using the MAP PRIVATE ?ag, we follow the COW rules. When you actually try to write to the memory mmap()'d from /dev/zero, the OS intervenes and clones the corresponding page. So, instead of actually writing to /dev/zero, you end up writing to a new memory page.

Now suppose you mmap 3 pages to /dev/zero. Right after you do this, the process' page table contains three mappings to /dev/zero. These are all COW mappings to a same single page in memory, which itself maps to /dev/zero3. However, the ?rst time some of these pages is modi?ed, a new page is created, and the corresponding mapping in one of the page tables is modi?ed. Notice that we could have used mmap with any other ?le instead of /dev/zero; say, an MP3 ?le.

In this case, whenever we mmap'd, we would be actually mapping memory addresses to portions of the MP3 ?le. If we then tried to write to those areas of memory, we would be indirectly over writing the ?le! Notice, however, that we could be careful enough and used the mmap parameter MAP PRIVATE; then, we would still be able to read from the MP3 ?le, but all writings to it would be done using Copy On Write.

Posted Date: 3/12/2013 5:55:40 AM | Location : United States







Related Discussions:- Allocating new pages, Assignment Help, Ask Question on Allocating new pages, Get Answer, Expert's Help, Allocating new pages Discussions

Write discussion on Allocating new pages
Your posts are moderated
Related Questions
Q. Describe the concept of transaction atomicity? Answer: A transaction is a sequence of read as well as writes operations upon some data followed by a commit operation. If the

You must use fork and pipe to complete this project. This project creates processes to add all numbers in a file. The user will enter a number (1, 2, or 4) of parallel processes

How can the deadlock be prevented? To evade deadlocks first we will have to obtain the information about how resources are to be requested. And as well we should make sure that

Problem: Managing Outside Communication. a. What is the principal action we use when communicating through a web browser? b. Give an example of how to preaddress an email


Determine a parser which is a variant of top-down parsing without backtracking Recursive Descend parser is a variant of top-down parsing without backtracking.

Define the OS/2 threads code The sample program in Listing is very similar to the NetWare example. OS/2 commands are substituted for the pseudocode commands controlling thread

What is an operating system process? How is it different from a program? Why do we need the concept of a process, rather than simply talk about programs running in memory? The e

Invalid page fault :If a page fault happens for a reference to an address that's not part of the virtual address space, so that there could not be a page in memory corresponding

Evicting the most-recently used (MRU) page does very well on LRU's worst case. In general, however, MRU is a bad idea, since many programs exhibit temporal locality in their memory