Week 7 address binding segmentation page tables Flashcards
(36 cards)
The address binding problem
REMEMBER THIS
logical address - in binary file we have machine segment which contains machine code which contains address ( logical addresses)
address binding problem is mapping logical address (in program) to actual addresses in memory AT RUNTIME given the state of memory ( whats free and whats not ) is only known at runtime
Non solutions to address binding problem:
why does avoiding multi programming not work ie only having one program in memory at a time
Would be incredibly slow
say a process was waiting for an io task to complete cpu would remain idle ( NO OTHER PROGRAM TO SWITCH TO)
Furthermore if we wanted to context switch to another program (which would be in disk) this would be even slower as retrieving from disk is very slow
Non solution statically assign ranges of addresses to a program
Multiple instances of program have same range so overlap and interrfere
Lots of internal fragmentation likely - we assign memory to program that isnt used
How much memory a program needs depends on a lot of different things so know way to know in advance how much to statically assign
EVERY PROGRAM THAT MIGHT RUN WOULD NEED SPACE RESERVED
whats load time relocation
While loading a program into memory, the loader adjusts the logical addresses (in the text segment) so they correctly reference the physical memory region where the program is placed.
does load time relocation suffer from internal fragmentation
Yes - physical memory shared between proccesses
and we can see theres memory assigned for stack and heap (which grow initially empty) - memory allocated to a process and not in use == INTERNAL FRAGMENTATION
does load time relocation suffer from external fragmentation
Yes Physical memory shared between processes (which can be of different size)
It may be the case that we have enough cumulative space in memory to fit a process but becuase that memory isnt contiguous we cant assign it to a process - external
Problems with loadtime relocation
Physical address space shared amongst processes
This means :
. no fault isolation
- if a process has a bug it would cause other processes to not work and even os to not work
. no security -
process can read / write to other process memory
. Slow
- adjusting logical addresses so they
correctly reference the physical memory
region where the program is placed is
slow
What is MMU
mmu is a conceptual device that sits between processor and memory and when a processor requests a region in memory the requested address is compared against the base and limit to see if request will be accepted
Faults of Simple MMU
Fault isolation - good between process if a process bugs out doesnt lead to other processes not working or os crashing
Security - Process can no longer read or write to other process’ memory ( as base- physical start of process limit - end physical addres of process)
Internal - occurs if base and limit are fixed
external still occurs
what is segmentation
Segmentation is a memory management scheme where a program’s logical address space is divided into variable-sized segments — such as code, data, stack, or heap — and each segment is mapped independently to physical memory using a segment table that stores the base address, limit, and access permissions for each segment.
what is a segment of memory
a <base.> pair</base.>
When is segmentation supported
MMU can work with multiple <base, limit> pairs
JUST READ - read thorougly tho very important
We can divide up our regions (data , text , stack) into segments which allows us to put permissions on segments:
* We cant write to a text segment (as this just contains the instructions of program which shouldn’t be modified during runtime)
* we cant execute a stack segment etc
WE HAVE JUST DIVIDED PROCESS BY THEIR LOGICAL PURPOSE(DATA,TEXT,STACK…)
Just read - read thoroughly though very important
so this is everyhting i know about the x86
Logical address = (segment, offset),
segment offset 16 bits
physical address 24 bits
We can have 4 active segments : CS ( code segment, DS) ( data segment) , SS (stack segment) , ES
ie if you want to change to a different data segment have to change selector value in data segment register to point to a different data segment
Table descriptor is a table that defines segments ( base , limit , access for each segment entry)
Each segment has a 16 bit register which has a selector that indexes into an entry in table descriptor
If you want to change a segment -> change selector value -> slow as active segments details cached but to know access non active segments details involves multiple memory accesses
Why is there no internal fragementation in segmentation
Because segments can be different sizes and so we can just have the size of a segment be exactly equal to how much memory it needs
why segmentation leads to non linear address space
Segments can be:
✅ Different sizes
✅ Overlapping
✅ Placed anywhere in physical memory
properties of
Fault isolation- We can now isolate faults to specific regions ( ie text , stack , code segment) which gives us even better fault isolation - no longer just isolates between processes
Security:
since we have gone even finer grained we don’t just segment the process but the regions within a process so of course process A cant refer to the memory of process B
rewriting no longer an issue -
We aren’t changing references of machine instructions no more
Instructions have corresponding segment types
Address binding is now just a matter of making segments
fragmentation :
internal for same reason we mentioned before:
Segments maybe different sizes:
-This will come in useful as it helps eliminate internal fragmentation – which arises when a processes is allocated more memory than it uses- this is eliminated as we can make the segment size match how much memory it uses since sizes can be different
External Fragmentaion:
still a problem memory must be contiguous so if we require a segment to have more memory than there is available adhering to the fact that its contiguous (cant have part of a segments memory here and another elsewhere) we still cant use the available space
what is paging
virtual memory divided into equal sized pages and physical into equal sized frame. Paging is the mapping of pages to frames.
Note SIZE OF PAGE = SIZE OF FRAME
what must mmu do in paging
programs only see virtual address
(p , o ) page number , offset
mmu must translate p to f
offset remains the same
Long winded explanation of why no external fragmentation
so essentially let me see if i understand correctly and you verify: Pages: equal sized blocks of virtual memory Frames : Equal sized blocks of physical memory Size of frame = size of page Why it eliminates External fragmentation: External fragmentation occured when we had available total space (but it was scattered) but we needed a large enough contiguos block of memory to satisfy However we can now place pages to frames non contiguosly: ie a process with 3 pages can go to frames 5,9 ,2 (non contiguos) This eliminates external fragmentation as we no longer need contiguos blocks to place pages into frames
short winded explanation of why no external fragmentatio
No external fragmentation in paging because even though virtual addresses are contiguous, physical frames can be scattered — as long as there are enough free frames, pages can map into them in any order.
Is there internal fragmentation and why
REMEMBER WE SAID PHYSICAL MEMORY IS DIVIDED INTO EQUAL SIZED FRAMES ( in this example each frame is 4KB)
If a program needs one more byte (of physical memory) we cant allocate a percentage of a frame to satisfy it we have to allocate it one more frame
However we limited it to 4095 bytes wasted (4096 -1)
what does page table base register hold and why
page table base register holds base (starting physical address) of current page table
MMU then uses the page table to convert virtual address to physical address
Look at notes for week 7 page 24 and page 25 beautiful diagram about conversion of virtual to physical address
tlb hit: look at tlb if page number present (tlb hit) you can find frame number without looking it up in page table ( havent accessed memory yet) We then do the actual memory access with the frame number we got from tlb tlb miss: look in tlb -> page number not there -> we look in page table for frame number ( 1 memory access so far) -> we then complete the actual access ( 2 memory access) TLB STORES THE DATA ON A TLB MISS SO FUTURE SEARCHES ARE FASTER