0% found this document useful (0 votes)
2 views6 pages

OS Answer

OS Answer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

OS Answer

OS Answer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY

HO CHI MINH UNIVERSITY OF


TECHNOLOGY

Course ID: CO2018

ASSIGNMENT
Simple Operating System Simulation

Instructor: Nguyen Phuong Duy


Class: CC06
Group: 1

Group member
ID Name Email
2452421 Đào Nguyên Hưng [Link]@[Link]
2453464 Đặng Quốc Trung [Link]@[Link]
2452147 Trương Lê Bảo bao.truong05122006@[Link]
2450007 Phạm Hoàng Hải hai.pham1508@[Link]
2452156 Trần Thanh Bình tranthanhbinh07062006@[Link]
Vietnam National University Ho Chi Minh City
Ho Chi Minh University of Technology

Team Workload and Evaluation

Student ID Name Task Evaluation

2452421 Đào Nguyên Hưng Integration + Testing 100%

2453464 Đặng Quốc Trung Paging 100%

2452147 Trương Lê Bảo Virtual Memory 100%

2450007 Phạm Hoàng Hải Scheduling 100%

2452156 Trần Thanh Bình Physical Memory 100%

Operating System - Semester 252 Page 1/5


Vietnam National University Ho Chi Minh City
Ho Chi Minh University of Technology

Contents

1 Scheduling 3

2 Memory Management 3

Operating System - Semester 252 Page 2/5


Vietnam National University Ho Chi Minh City
Ho Chi Minh University of Technology

1 Scheduling

Question: Considering the impactness of MLQ detailed policies, what is the


benefit of each policy?
The MLQ policy separates processes into different ready queues based on their
priority value, the smaller its priority value, the more execution chances that the process
have in the scheduler since the formula of the slot is slot[p] = MAX_PRIO - p. After
emptying the slot and the queue are still in the ready queue, the scheduler resets the
slot counter to start the next round which prevent starvation. Finally, if the process
isnt finished, it will put back to the end of its own priority queue that contain processes
with the same priority value are served in FIFO order. Beside that, since it put at the
tail, the queue also apply the round robin rule, creating a fairness between the processes
with the same priority.

2 Memory Management

Question: What is the primary motivation for combining segmentation with


paging in memory manage ment? How does this hybrid approach address
limitations inherent in using either technique alone?
In memory management, segmentation and paging are combined to handle each
other’s disadvantages when using them alone:

• Segmentation manages logic memory areas such as STACK and HEAP. This layer
provides boundary protection and memory organization. However, that segmen-
tation alone requires large contiguous physical memory blocks, as fragmented the
memory is, the more complex it is to find continuous space.

• Paging solves this by using page tables, each page can be mapped to any physical
frame. Even if the memory is fragmented, the process still observes continuous
physical memory [Link], paging makes swapping because the OS can move
individual pages between RAM and SWAP space. However, paging alone only
works with page number and offsets, with no logical memory areas, which may
lead process to read any page without boundary check.

By this hybrid approach, the system achieves memory protection, flexible physical

Operating System - Semester 252 Page 3/5


Vietnam National University Ho Chi Minh City
Ho Chi Minh University of Technology

memory allocation, efficient swapping, reduce fragmentation issues and create


isolation between user memory and kernel memory.

Question: What are the benefits of extending hierarchical paging to N


level?

• Advantages:

Avoid using huge page table, each level would contains S times more entries than
the previous level, result in ~O(log(N)) level for N is total memory

Demand paging prevents allocating all the page tables overhead, only allocate
necessary ones and would allocate only when needed, which in terms, result in
lower overhead memory even for massive virtual address space.

Demand paging is also scalable by design, making future changes easier

• Tradeoffs:

Increased lookup time: N level paging means walking N pages to find the target
address. Although this can be cushioned using a TLB

Question: What are the advantages and disadvantages of paging and


contiguous memory allocation?

• Paging:

*Advantages:

– No external fragmentation, as pages can be placed in any free frame

– Easy to find free frame, therefore easier to allocate new memory

*Disadvantages:

– Internal fragmentation might happens, as the last page might not be used
completely

– Page table consume memory, address lookup consume processing power

• Continuous Allocation:

*Advantages:

Operating System - Semester 252 Page 4/5


Vietnam National University Ho Chi Minh City
Ho Chi Minh University of Technology

– Very simple to implement, only need base register and limit register

– Very simple to calculate address: Address = Base + offset

– Benefit from data locality

*Disadvantages:

– External fragmentation, as total memory are not guaranteed to be contigu-


ous

– Fixed size lead to difficulty in allocating more memory

Question: What happens if the synchronization is not handled in your


Simple OS? Illustrate the problem of your simple OS (assignment out-
puts) by example if you have any in the added kernel memory opera-
tions.

If the synchronization is not handled in our OS, it will leads to race conditions,
undefined behavior, and incorrect results.

For example, free_fp_list in mm-memphy.c file is a shared resource. When 2


CPUs call MEMPHY_get_freefp(), then they will get the same frame and over-
write each other. We will call this situation a double free, which leads to a spoiled
list.

From our codebase, other modules already use pthread_mutex to protect their
shared resources (sched.c has queue_lock, libmem.c has mmvm_lock, mm64.c
has pg_lock), we also add free_fp_lock to get_freefp and put_freefp. So
only 1 CPU can access the list at a time.

Operating System - Semester 252 Page 5/5

You might also like