Docsity

Chapter 6 reading exercise, Exercises of Operating Systems

Toggle sidebar
bg1
Question 1:
Segmentation solves the problem of physical memory waste by supporting sparse address
spaces. It allows the OS to place logical segments like code, heap, and stack in different parts
of physical memory to avoid allocating the large, unused gaps between them.
Question 2:
When segmentation is used, the hardware translates a virtual address into a physical address
by extracting the segment bits from the top of the address to identify the specific segment(code,
stack, heap). Then the remaining bits is the offset which tells the hardware the specific byte
within that segment. The hardware then checks if the offset is within the bounds of that
segment. If the offset is greater than or equal to the segment size, it leads to a segmentation
fault. If it is less than, the hardware adds the offset to the base physical address to find the final
location in memory.
Question 3:
A segmentation fault is an error that occurs when a program attempts to access a memory
address that it is not allowed to access(an illegal address). This can happen when the hardware
is using segmentation to translate a virtual address into a physical address.
Question 4:
External fragmentation is a problem where physical memory becomes full of small holes of free
space, making it difficult to allocate new segments or grow existing ones. It can be reduced by
compaction, where the OS stops running processes and rearranges existing segments in
physical memory to make them contiguous. It can also be reduced by using a free list
management algorithm which helps by trying to keep large extents of memory available for
allocation. It uses different strategies like best-fit, worst-fit, first-fit, or the buddy algorithm. Lastly,
it can be reduced by paging, which chops memory in fixed size spaces therefore avoiding the
problem of external fragmentation since memory is never allocated in variable sized chunks.
Question 5:
a) Base + Offset= 2048 + 135 = 2183
b) The variable x is a local variable stored on the stack. Its virtual address is 18KB(value of
ebx) after the instructions execute. According to the book, since the stack segment has a
base register of 28KB and grows downward, we first extract the 12-bit offset from the
virtual address (2KB), then compute the negative offset as 2KB − 4KB = −2KB. Adding
this to the base gives a physical address of 28KB + (−2KB) = 26KB.
c) The value for the base register for the stack segment is 28KB. This is the physical
address where the stack segment begins in physical memory, as given by the segment
register table in the book (Figure 16.4).
d) At 128, it loads the current value of x which is 21 into the eax register, then adds 3 to the
value in eax(21) which is 24, lastly it stores the new value in eax. So after executing
executing 135: movl %eax, 0x0(%ebx), the new value of x is 24.
pf2

Partial preview of the text

Download Chapter 6 reading exercise and more Exercises Operating Systems in PDF only on Docsity!

Question 1: Segmentation solves the problem of physical memory waste by supporting sparse address spaces. It allows the OS to place logical segments like code, heap, and stack in different parts of physical memory to avoid allocating the large, unused gaps between them. Question 2: When segmentation is used, the hardware translates a virtual address into a physical address by extracting the segment bits from the top of the address to identify the specific segment(code, stack, heap). Then the remaining bits is the offset which tells the hardware the specific byte within that segment. The hardware then checks if the offset is within the bounds of that segment. If the offset is greater than or equal to the segment size, it leads to a segmentation fault. If it is less than, the hardware adds the offset to the base physical address to find the final location in memory. Question 3: A segmentation fault is an error that occurs when a program attempts to access a memory address that it is not allowed to access(an illegal address). This can happen when the hardware is using segmentation to translate a virtual address into a physical address. Question 4: External fragmentation is a problem where physical memory becomes full of small holes of free space, making it difficult to allocate new segments or grow existing ones. It can be reduced by compaction, where the OS stops running processes and rearranges existing segments in physical memory to make them contiguous. It can also be reduced by using a free list management algorithm which helps by trying to keep large extents of memory available for allocation. It uses different strategies like best-fit, worst-fit, first-fit, or the buddy algorithm. Lastly, it can be reduced by paging, which chops memory in fixed size spaces therefore avoiding the problem of external fragmentation since memory is never allocated in variable sized chunks. Question 5: a) Base + Offset= 2048 + 135 = 2183 b) The variable x is a local variable stored on the stack. Its virtual address is 18KB(value of ebx) after the instructions execute. According to the book, since the stack segment has a base register of 28KB and grows downward, we first extract the 12-bit offset from the virtual address (2KB), then compute the negative offset as 2KB − 4KB = −2KB. Adding this to the base gives a physical address of 28KB + (−2KB) = 26KB. c) The value for the base register for the stack segment is 28KB. This is the physical address where the stack segment begins in physical memory, as given by the segment register table in the book (Figure 16.4). d) At 128, it loads the current value of x which is 21 into the eax register, then adds 3 to the value in eax(21) which is 24, lastly it stores the new value in eax. So after executing executing 135: movl %eax, 0x0(%ebx), the new value of x is 24.

Question 6: 0100101 - 2 = 64 bytes 6 Page size - 16 bytes VPN bits - high 3 bits - 010 - 2 in decimal Offset - 0101 - 5 in decimal According to the page table, a VPN of 2 equals a PFN 5 and binary for 5 is 101 Concatenate the PFN with the Offset in binary which is 1010101 - 85 in decimal