You are on page 1of 9

EONE ETOUA OSCAR VIANNEY

FUNDAMENTALE COMPUTER SCIENCE 4

MEMORY MANAGMENT

1-
First-Fit:
212K is put in 500K partition.
417K is put in 600K partition.
112K is put in 288K partition (new partition 288K = 500K - 212K).
426K must wait.
Best-Fit:
212K is put in 300K partition.
417K is put in 500K partition.
112K is put in 200K partition.
426K is put in 600K partition.
Worst-Fit:
212K is put in 600K partition.
417K is put in 500K partition.
112K is put in 388K partition.
426K must wait.
In this example, Best-Fit turns out to be the best.

2-
Physical Memory 32 frames = 25
Size of word 1024 = 210
Total Physical Address Space = 15 bits
Logical Memory 8 pages = 23
Size of word = 210
Total Logical Address Space = 10 +3 = 13 bits

3-
An address on a paging system is a logical page number and an offset. The physical page is
found by searching a table based on the logical page number to produce a physical page number.
Because the operating system controls the contents of this table, it can limit a process to
accessing only those physical pages allocated to the process. There is no way for a process to
refer to a page it does not own because the page will not be in the page table. To allow such
access, an operating system simply needs to allow entries for non-process memory to be added
to the process’s page table. This is useful when two or more processes need to exchange data
they just read and write to the same physical addresses (which may be at varying logical
addresses). This makes for very efficient inter process communication.

4-
a. 400 nanoseconds; 200 nanoseconds to access the page table and 200 nanoseconds
toaccess the word in memory.
b. If we add associative registers, and t percent of all page-table references are found in
the associative registers. Effective access time = t%x(200 nanoseconds) + (100-
t%)x(400 nanoseconds).

5-
By allowing two entries in a page table to point to the same page frame in memory, users can
share code and data. If the code is reentrant, much memory space canbe saved through the
shared use of large programs such as text editors, compilers, and database systems. “Copying”
large amounts of memory could be effected by having different page tables point to the same
memory location.However, sharing of non reentrant code or data means that any user having
access to the code can modify it and these modifications would be reflected in the other user’s
“copy.”

6-
a) No.
b) No.
c) No.
d) Yes.
e) Likely to improve CPU utilization as more pages can remain resident and not require
paging to or from the disks.
f) Also an improvement, for as the disk bottleneck is removed by faster response and more
throughput to the disks, the CPU will get more data more quickly.
g) Again, the CPU will get more data faster, so it will be more in use. This is only the case
if the paging action is amenable to prefetching (i.e., some of the access is sequential).
h) Increasing the page size will result in fewer page faults if data is being accessed
sequentially. If data access is more or less random, more paging action could ensue
because fewer pages can be kept in memory and more data is transferred per page fault.
So this change is as likely to decrease utilization as it is to increase it.

7- Compare the memory organization schemes


a. External fragmentation
Contiguous Allocation with Fixed-Size Partitions: does not suffer from external
fragmentation.
Contiguous Allocation with Variable-Size Partitions: suffers from external
fragmentation.
Pure Segmentation: suffers from external fragmentation.
Paging: does not suffer from external fragmentation.
b. Internal fragmentation
Contiguous Allocation with Fixed-Size Partitions: suffers from internal
fragmentation.
Contiguous Allocation with Variable-Size Partitions: does not suffer from internal
fragmentation.
Pure Segmentation: does not suffer from internal fragmentation.
Paging: suffers from internal fragmentation.
c. Ability to share code across processes
Contiguous Allocation with Fixed-Size Partitions: no support for code sharing across
processes.
Contiguous Allocation with Variable-Size Partitions: no support for code sharing
across processes.Pure Segmentation: supports code sharing across processes.
However, we must be careful to make sure that processes do not mix code and data in
the same segment.
Pure Paging: supports code sharing across processes. As in pure segmentation, we must
make sure that processes do not mix code and data in the same page.

8- Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2,


3,6.
- LRU replacement
 Frames = 1
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Default D D D D D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 20 page defaults.
 Frames = 2
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 3 3 2 2 5 5 2 2 2 3 3 6 6 2 2 2 3 3
Frame2 2 2 4 4 1 1 6 6 1 1 1 7 7 3 3 1 1 1 6
Default D D D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 18 page defaults.
 Frames = 3
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 4 4 4 5 5 5 1 1 1 7 7 7 2 2 2 2 2
Frame2 2 2 2 2 2 2 6 6 6 6 3 3 3 3 3 3 3 3 3
Frame3 3 3 3 1 1 1 2 2 2 2 2 6 6 6 1 1 1 6
Default D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 15 page defaults.
 Frames = 4
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 6 6
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 5 5 5 5 5 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 6 6 6 6 6 7 7 7 7 1 1 1 1
Default D D D D D D D D D D
page
As shown in the table table below, there will be 10 page defaults.
 Frames = 5
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3
Frame5 5 5 5 5 5 5 7 7 7 7 7 7 7 7
Default D D D D D D D D
page
As shown in the table table below, there will be 8 page defaults.
 Frames = 6
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.

 Frames = 7
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame7 7 7 7 7 7 7 7 7
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.
- FIFO replacement
 Frames = 1
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Default D D D D D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 20 page defaults.
 Frames = 2
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 3 3 2 2 5 5 2 2 2 3 3 6 6 2 2 2 3 3
Frame2 2 2 4 4 1 1 6 6 1 1 1 7 7 3 3 1 1 1 6
Default D D D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 18 page defaults.
 Frames = 3
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 4 4 4 4 6 6 6 6 3 3 3 3 2 2 2 2 6
Frame2 2 2 2 2 1 1 1 2 2 2 2 7 7 7 7 1 1 1 1
Frame3 3 3 3 3 5 5 5 1 1 1 1 6 6 6 6 6 3 3
Default D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 16 page defaults.
 Frames = 4
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 5 5 5 5 5 3 3 3 3 3 1 1 1 1
Frame2 2 2 2 2 2 2 6 6 6 6 6 7 7 7 7 7 7 3 3
Frame3 3 3 3 3 3 3 2 2 2 2 2 6 6 6 6 6 6 6
Frame4 4 4 4 4 4 4 1 1 1 1 1 1 2 2 2 2 2
Default D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 14 page defaults.
 Frames = 5
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1
Frame3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2
Frame4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3
Frame5 5 5 5 5 5 5 7 7 7 7 7 7 7 7
Default D D D D D D D D D D
page
As shown in the table table below, there will be 10 page defaults.
 Frames = 6
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 7 7 7 7
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2
Frame4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Default D D D D D D D D D D
page
As shown in the table table below, there will be 10 page defaults.
 Frames = 7
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame7 7 7 7 7 7 7 7 7
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.
- OPTIMAL replacement

 Frames = 1
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Default D D D D D D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 20 page defaults.

 Frames = 2
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 3 4 4 1 5 6 6 6 6 6 6 6 6 2 2 2 3 6
Frame2 2 2 2 2 2 2 2 2 1 1 1 7 7 3 3 1 1 1 1
Default D D D D D D D D D D D D D D D
page
As shown in the table table below, there will be 15 page defaults.
 Frames = 3
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 6
Frame2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 2 2 2 2 2
Frame3 3 4 4 4 5 6 6 6 6 6 6 6 6 6 1 1 1 1
Default D D D D D D D D D D D
page
As shown in the table table below, there will be 11 page defaults.
 Frames = 4
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 1 7 7 7
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 5 6 6 6 6 6 6 6 6 6 6 6 6 6
Default D D D D D D D D
page
As shown in the table table below, there will be 8 page defaults.
 Frames = 5
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame5 5 5 5 5 5 5 7 7 7 7 7 7 7 7
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.
 Frames = 6
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.
 Frames = 7
Pages 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Frame1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Frame2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Frame3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Frame4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Frame5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Frame6 6 6 6 6 6 6 6 6 6 6 6 6 6
Frame7 7 7 7 7 7 7 7 7
Default D D D D D D D
page
As shown in the table table below, there will be 7 page defaults.

9- In the Second Chance page replacement policy, the candidate pages for removal
are consider in a round robin matter, and a page that has been accessed between
consecutive considerations will not be replaced.

The page replaced is the one that - considered in a round robin matter - has
not been accessed since its last consideration.

 Implementation:
o Add a "second chance" bit to each memory frame.
o Each time a memory frame is referenced, set the "second chance" bit to
ONE (1) - this will give the frame a second chance...
o A new page read into a memory frame has the second chance bit set to
ZERO (0)
o When you need to find a page for removal, look in a round robin manner
in the memory frames:
 If the second chance bit is ONE, reset its second chance bit (to
ZERO) and continue.
 If the second chance bit is ZERO, replace the page in that
memory frame.

10- Belady’s anomaly is the name given to the phenomenon where increasing the
number of page frames results in an increase in the number of page faults for a
given memory access pattern. This phenomenon is commonly experienced in
following page replacement algorithms: First in first out (FIFO), Second chance
algorithm, Random page replacement algorithm.

11- It is a phenomenon in virtual memory schemes when the processor spends most
of its time swapping pages, rather than executing instructions. This is due to an
inordinate number of page faults.

12- With demand paging, a page is brought into memory only when a location on
that page is actually referenced during execution. With pre-paging, pages other
than the one demanded by a page fault are brought in. The selection of such pages
is done based on common access patterns, especially for secondary memory
devices.

13- The difference between demand-cleaning and precleaning

- Demand cleaning: Apage is written out only when it has been selected for
replacement.
- Precleaning: Modified pages are updated on secondary memory before their
page frames are needed so that pages can be written out in batches.

14-
a. Contiguous memory allocation: might require relocation of the entire
program since there is not enough space for the program to grow its allocated
memory space.
b. Segmentation: might also require relocation of the segment that needs to be
extended since there is not enough space for the segment to grow its allocated
memory space.
c. Paging: incremental allocation of new pages is possible in this scheme
without requiring relocation of the program’s address space.

15- Programs are divided into segments and segments are paginated. So each
segment address is not a memory, but an address in the segment page table. The
segment and page tables can be same paginated.

You might also like