memory - Do modern OS's use paging and segmentation? -
i reading memory architecture , got bit confused paging , segmentation. read modern os systems utilize paging manage memory access looking @ disassembled codes can see segments "ds" , "fs". means os ( saw on windows , linux) using both segmentation , pagging or mapping segments same pages (making segments irrelevants) ?
ok, based on book modern operating systems 3rd edition andrew s. tanenbaum , materials form open security training (opensecuritytraining.info), manage understand segmentation , paging , reply question is:
concepts:
1.1.segmentation:
segmentation partition of memory pieces (sections) called segments. these segments independents each other, have variable sizes , may grow needed.
1.2. virtual memory:
a virtual memory abstraction of real memory. means maps virtual address (used programs) physical address (used hardware). if programme wants access memory 2000 (mov eax, 2000), virtual address (2000) converted real physical address ( illustration 1422) , programme access memory 1422 thinking he’s accessing memory 2000. so, if virtual memory beingness used system, programs no longer access real memory directly, instead, used correspondent virtual memory.
1.3. paging:
paging virtual memory management scheme. explained before, maps virtual address physical address. paging divides virtual memory pieces called “pages” , divides physical memory pieces called “frame pages”. page can bound 1 or more frame page ( maintain in mind page can map different frame pages, 1 @ time)
advantages , disadvantages
2.1. segmentation:
the main advantage of using segmentation split memory different linear address spaces. programs can have address space code, other stack, dynamic variables (heap) etc. disadvantage segmentation fragmentation of memory. consider illustration – 1 portion of memory divided 4 segments sequentially allocated -> seg1(in use) --- seg2(in use)--- seg3(in use)---seg4(in use). if free memory seg2, have -> seg1(in use) --- seg2(free)--- seg3(in use)---seg4(in use). if want allocate data, can using seg2, if size of info bigger size of seg2, won’t able , space wasted , memory fragmented. problem segments have larger size , since segment can’t “broken” smaller pieces, must allocated in memory.
2.1. paging:
the main advantages of using paging abstract physical memory, hence, programs (and programmers) don’t need bother memory addresses. can have 2 programs access (virtual) memory 2000 because mapped 2 different physical memories. also, it’s possible utilize hard disk ensure necessary pages allocated memory. main disadvantage paging uses 1 linear address space. paging maps virtual memories 0 max addressable value programs. consider illustration - 2 chunks of memory, “chk1” , “chk2” next each other on virtual memory ( chk1 allocated address 1000 2000 , chk2 uses 2001 3000), if chk1 needs grow, os needs create room in memory new size of chk1. if happens again, os have same thing or, if no space can found, exception pop. routines managing kind of operations bad performance, because growth , shrink of memory happens lot of time.
segmentation , paging
3.1. why combine both?
an operational systems can combine both segmentation , paging. why? because combining it’s possible have best both without disadvantages. so, memory divided in many segments , each 1 of have 1 or more pages. when programme tries access memory address, first os goes correspondent segment, there he’ll find correspondent page, goes page , there he’ll find frame page programme wanted access. using approach, os divides memory various segments, including segments kernel , user programs. these segments have variable sizes , access protection features. solve fragmentation , “big segment” problems, paging used. paging larger segment broken several pages , necessary pages remains in memory (and more pages allocated in memory if needed). so, basically, modern oss have 2 memory abstractions, segmentation more used “handling programs” , paging “managing physical memory”.
3.2. how works?
an os running segmentation , paging have next structures:
3.2.1. segment selector:
this represents index on global/local descriptor table. contains 3 fields represent index on descriptor table, bit identify if segment nowadays on global or local descriptor table , privilege level.
3.2.2. segment register:
a cpu register used store segment selector. ( on x86 machine) there @ to the lowest degree register cs (code segment) , ds (data segment).
3.2.3. segment descriptors:
this construction contains info regarding segment, base of operations address, size ( in pages or in bytes), access privilege, info of if segment nowadays on memory or not, etc. (for fields, search segment descriptors on google)
3.2.4. global/local descriptor table:
the table contains several segment descriptors. construction holds segment descriptors system. if table global, can hold other things local descriptor tables descriptors, task state segment descriptors , phone call gate descriptors (i’ll not explain these here, please, google them). if table local, ( far know) holds user related segment descriptors.
3.3. how works?
so, access memory, first programme needs access segment. segment selector loaded segment register , global or local descriptor table (depending of field on segment selector). reason of memory address segment register: address , cs:address -> 001b:0044bf7a. os goes g/ldt , (using index field of segment selector) finds segment descriptor of address trying access. checks if segment if present, protection , if ok goes address stated on “base field” (of descriptor) + address offset . if paging not enabled, scheme goes straight real memory, paging on address treated virtual address , goes page directory. base of operations address + offset called linear address , interpreted 3 fields: directory+page+offset. on directory page, search directory entry specified on “directory” field of linear address, entry points page table , field “page” of linear address used find page, entry points frame page , offset used find address programme want access.
3.4. modern operational systems
modern oses "do not use" segmentation. in quotes because utilize 4 segments: kernel code segment, kernel info segment, user code segment , user info segment. means user's processes have same code , info segments (so same segment selector). segments alter when going user kernel. so, path explained on section 3.3. occurs, utilize same segments and, since page tables individual per process, page fault hard happen.
hope helps , if there mistakes or more details ( bit generic on parts) please, sense free comment , reply. give thanks guys
danilo pc
memory operating-system paging
No comments:
Post a Comment