Allocating new pages, Operating System

Assignment Help:

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.


Related Discussions:- Allocating new pages

Deadlock, Suppose we have 3 processes running at the same time as shown in ...

Suppose we have 3 processes running at the same time as shown in the following table. Each resource only has one instance. Show a possible scenario of resource allocation that r

Why page sizes always powers of 2, Q. Why page sizes always powers of 2? ...

Q. Why page sizes always powers of 2? Answer: Recall that paging is executed by breaking up an address into a page and offset number. It is most competent to break the address

Necessary conditions for deadlock, Here are the conditions necessary for a ...

Here are the conditions necessary for a deadlock to occur; note that all of them are necessary, and none is suf?cient: 1. ?nite resources: the resources are held in a mutually-e

What is a two state process model?, What is a two state process model? ...

What is a two state process model?   At any time a process is being implementing by a processor or not. Therefore a process may be in Running or not running state. When an Ope

Computer number systems, Binary number based systems   Binary is a  ' base...

Binary number based systems   Binary is a  ' base 2' number system, only two numbers exist namely '0' and '1'. Conversion from binary to base 10 is easy if the number column techn

Three conditions that solution for critical section problem, What are three...

What are three conditions that a solution for the critical section problem must satisfy? The three conditions are as following:- a)      Mutual exclusion :- if a process is

Cpu, what is cpu

what is cpu

Define instance, Define Instance. An instance is an administrative unit...

Define Instance. An instance is an administrative unit in which components of R/3 systems giving one or more services are grouped together.  The services offered by a case are

Explain a computing environment, Q. Polling for an I/O completion is able ...

Q. Polling for an I/O completion is able to waste a large number of CPU cycles if the processor iterates a busy-waiting loop several times before the I/O completes. However if the

Define multithreading, Define multithreading The proficiency of an oper...

Define multithreading The proficiency of an operating system to execute different parts of a program called threads simultaneously is called as multithreading. A thread is a fl

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd