You are on page 1of 12

Bachelor of Science In Computer Engineering

Cpe 223 – Operating System

Copy-on-Write

Thrashing

Prepared by Darwin John A. Lavarez

I. Introduction

Copy-on-Write was introduced to allow both parent and child processes to

initially share the same pages in memory. If either process modifies a shared page,

only then is the page copied. It means that Copy-on-Write allows more efficient

process creation as only modified pages are copied.

Thrashing was introduced when a process does not have “enough” pages, the

page-fault rate is very high. It can be said that thrashing happens when a process is

busy swapping pages in and out.

II. Objectives

The following are the objectives of this topic:

• To present the concept of Copy-on-Write and Thrashing in Operating System.

• To introduce the position of Copy-on-Write in Virtual Memory Management.

• To determine the several classic Thrashing problems.


III. Discussions

Copy-on-Write sometimes referred as implicit sharing or shadowing is a

resource management technique commonly used in computer programming to

efficiently implement a “duplicate” or “copy” operation on modifiable resources.

Copy-on-Write finds its main use in sharing the virtual memory of operating

system processes, in the implementation of the fork system call:

• vfork() variation on fork() system call has parent suspend and child using copy-

on-write address space of parent

– Designed to have child call exec()

– Very efficient

In general, free pages are allocated from a pool of zero-fill-on-demand pages

 Pool should always have free frames for fast demand page execution

• Don’t want to have to free a frame as well as other processing on page

fault.

Example

Figure 1. Physical Memory before Process 1 modifies Page C


Figure 2. Physical Memory after Process 1 modifies Page C

If a resource is duplicated but not modified, it is not necessary to create a new

resource; the resource can be shared between the copy and the original.

Modifications must still create a copy, hence the technique:

– The copy operation is deferred to the first write.

Copy-on-Write in summary:

• OS memory management policy to lazily copy pages only when they

are modified

• Initially map same physical page to child virtual memory space

• Write to child virtual page triggers page protection violation

• OS handles exception by making physical copy of page and remapping

child virtual page to that page.


Thrashing is said to occur when a computer’s virtual memory resources are

overused, leading to a constant state of paging and page faults, inhibiting most

application-level processing.

This occurrence may cause the performance of the computer to degrade or

collapse. The situation can continue indefinitely until either the user closes some running

applications or the active processes free up additional virtual memory resources.

How it works:

Programs are allocated a certain number of pages as needed by the operating

system. Active memory pages exist in both RAM and on disk. Inactive pages are

removed from the cache and written to disk when the main memory becomes full.

If processes are utilizing all main memory and need additional memory pages, a

cascade of severe cache misses known as page faults will occur, often leading to a

noticeable lag in operating system responsiveness. This process together with the futile,

repetitive page swapping that occurs are known as "thrashing". This frequently leads to

high, runaway CPU utilization that can grind the system to a halt. In modern computers,

thrashing may occur in the paging system or in the I/O communications subsystem.

Cause of the Problem

In virtual memory systems, thrashing may be caused by programs or workloads

that present insufficient locality or reference: if the working set of a program or a

workload cannot be effectively held within physical memory, then constant data

swapping or thrashing may occur.


Other types of Thrashing:

 Cache Thrashing

Where main memory is accessed in a pattern that leads to multiple main memory

locations competing for the same cache lines, resulting in excessive cache misses.

 TLB Thrashing

Where the translation lookaside buffer (TLB) acting as a cache for the memory

management unit (MMU) which translates virtual addresses to physical addresses is too

small for the working set of pages.

 Heap Thrashing

Frequent garbage collection, due to failure to allocate memory for an object, due

to insufficient free memory or insufficient contiguous free memory due to memory

fragmentation is referred to as heap thrashing.

 Process Thrashing

A similar phenomenon occurs for processes: when the process working set cannot

be coscheduled – so not all interacting processes are scheduled to run at the same time –

they experience "process thrashing" due to being repeatedly scheduled and unscheduled,

progressing only slowly.

Possible Solution for Thrashing:

Using hysteresis thresholding could help mitigate the issue. One threshold for

paging and another to go back to memory


IV. Exam

Directions: Choose the letter of the correct answer that each number provided.

1. Sometimes referred as implicit sharing or shadowing.

a) Thrashing

b) Copy-on-Write

c) System Call

d) Virtual Memory Management

2. It is a resource management technique commonly used in computer programming to

efficiently implement a “duplicate” or “copy” operation on modifiable resources.

a) Thrashing

b) Copy-on-Write

c) System Call

d) Virtual Memory Management

3. In what implementation Copy-on-Write finds its main use in sharing the virtual

memory of operating system processes?

a) Fork System Call

b) Vfork()

c) Variation fork call

d) Thrashing
4. Has parent suspend and child using copy-on-write address space of parent.

a) Virtual system call

b) vfork() system call

c) Demand system call

d) Virtual Memory Management

5. Free pages are allocated from what pool of pages?

a) Page-on-Write

b) Page-on-call Demand

c) Segmentation Pages

d) Zero-fill-on-demand pages

6. Should always have free frames for fast demand page execution.

a) Thrashing

b) Copy-on-Write

c) Pool

d) Virtual Memory Management

7. Policy to lazily copy pages only when they are modified

a) Thrashing policy

b) Copy-on-Write policy

c) System Call policy

d) OS memory management policy


8. Handles exception by making physical copy of page and remapping child virtual page

to that page.

a) OS

b) Copy-on-Write

c) System Call

d) Virtual Memory

9. The technique used when a resource is duplicated but not modified but Modifications

must still create a copy.

a) The copy operation is deferred to the first write.

b) The copy operation is deferred to the modified resource.

c) The copy operation is deferred to the duplicated resource.

d) The copy operation is deferred to the second write.

10. Allows more efficient process creation as only modified pages are copied.

a) Thrashing

b) Copy-on-Write

c) System Call

d) Virtual Memory Management

11. Happens when a process is busy swapping pages in and out.

a) Thrashing

b) Copy-on-Write

c) System Call

d) Virtual Memory Management


12. Occurs when a computer’s virtual memory resources are overused, leading to a

constant state of paging and page faults, inhibiting most application-level processing.

a) Copy operation.

b) Thrashing

c) Translation look aside buffer

d) Virtual memory systems

13. This process together with the futile, repetitive page swapping that occurs are known

as what?

a) Thresholding

b) Thrashing

c) Translation look aside buffer

d) Virtual memory systems

14. In virtual memory systems, may be caused by programs or workloads that present

insufficient locality or reference.

a) Thresholding

b) Thrashing

c) Translation look aside buffer

d) Virtual memory systems


15. What occurs if the working set of a program or a workload cannot be effectively held

within physical memory?

a) Thresholding

b) Constant Data Swapping

c) Translation look aside buffer

d) Virtual memory systems

16. Where main memory is accessed in a pattern that leads to multiple main memory

locations competing for the same cache lines, resulting in excessive cache misses.

a) Cache Thrashing

b) TLB Thrashing

c) Heap Thrashing

d) Process Thrashing

17. Where the translation lookaside buffer (TLB) acting as a cache for the memory

management unit (MMU) which translates virtual addresses to physical addresses is

too small for the working set of pages.

a) Cache Thrashing

b) TLB Thrashing

c) Heap Thrashing

d) Process Thrashing
18. Frequent garbage collection, due to failure to allocate memory for an object, due to

insufficient free memory or insufficient contiguous free memory due to memory

fragmentation is referred to as heap thrashing.

a) Cache Thrashing

b) TLB Thrashing

c) Heap Thrashing

d) Process Thrashing

19. A similar phenomenon occurs for processes: when the process working set cannot be

coscheduled, so not all interacting processes are scheduled to run at the same time.

a) Cache Thrashing

b) TLB Thrashing

c) Heap Thrashing

d) Process Thrashing

20. Possible solution that could help mitigates the issue. One threshold for paging and

another to go back to memory.

a) Catharsis Thresholding

b) Trace Thresholding

c) Hysteresis Thresholding

d) Process Thresholding
Answer Key:

1. A 16. A

2. A 17. B

3. A 18. C

4. B 19. D

5. D 20. C

6. C

7. D

8. A

9. A

10. A

11. A

12. B

13. B

14. B

15. B

You might also like