Understanding Virtual Address, Virtual Memory and Paging -


i've been learning these topics , read many articles , books lack complementary information , confused me more. here, i’d explain know while asking questions. hopefully, topic useful many me. i'd learn validity of knowledge , corrections if necessary.

virtual memory

some articles “virtual memory space of hard disk emulates physical memory can have more memory have.”. other articles “virtual memory combination of physical memory (ram), section of hard disk acts physical memory , page tables.” different things , don’t understand why there different explanations that.

let’s go second explanation since how wikipedia describes virtual memory well. @ point virtual address makes sense since use address @ virtual memory instead of physical memory directly.

by way, mac says have 8gb physical memory , 8gb virtual memory. in case vm include physical memory or amount of space in hd used memory? have 16gb memory available programs?

enter image description here

question 1:

intel i5 has 36 bit address bus , means can address 64gb memory. let’s installed 4gb ram computer. however, programs may not aware of size of memory installed used on many different systems different sizes of memory. virtual memory becomes handy. abstracts away actual size of memory installed.

however, happens when programs want access memory address 0xfffffffff? have 4gb installed , perhaps memory space in hd.

i have 2 theory question:

1. since page tables maintained os, os decodes address , finds out page , checks page in page table see whether have physical address associated (valid , invalid flags), if yes goes physical address page entry points @ in physical memory + offset defined in virtual address , brings value. otherwise page fault happens , os looks page in secondary storage, fetches , puts in memory , updates page table.

2. throws outofmemory type of exception says don’t have memory given address can address.

the disadvantage of first theory happens when program wants use 64gb memory? need have 60gb memory space in hd since have 4gb. however, in screen shot below mac tells me there 8gb virtual memory.

question 2:

how processes put in virtual memory? mean each process has 0x0 - 0xfffffffff virtual memory space available them or there 1 virtual memory address space process placed?

if each process assumes have memory available them, memories following:

enter image description here

if there 1 virtual memory concept, this:

enter image description here

page table

so page table data structure sits between physical addresses , virtual addresses. associative array (or dictionary) each page (key), there physical address associated (value).

os uses mmu (memory management unit) perform translation virtual address physical address.

enter image description here

question 3:

is there 1 big giant page table includes pages every process or each process has own page table?

paging

paging memory management method. virtual memory , physical memory divided pages (which fixed , same size blocks) memory management unit. technique useful when swap pages between memory , secondary storage can swap pages between them. program instance requests data located in address. however, address program using virtual address , mmu translates using page table. during this, mmu checks page table whether requested present in page table , os gets secondary storage if not , updates page table.

question 4:

let’s process requests data address converted physical address has data already. how known data not belong requester processes , should replaced 1 in secondary storage?

there dirty bit example used whether write page hard disk or not don’t think determines owner process.

some people use term "virtual memory" if synonymous page file, since page file represents part of allocated memory not "real" memory (i.e. ram). people consider "virtual memory" entire abstraction layer operating system gives programs, combines ram , page file.

i'm not sure of these definitions favored mac os, though seems unlikely computer not have any paged memory allocated, i'm guessing adding 8gb of paged memory 8gb of actual ram, total of 16gb of available (virtual) memory.

remember because operating system manages memory allocation , deallocation requests, free whatever wants. understanding operating systems have different memory allocation tables each process, literally give same virtual memory address multiple programs, memory addresses map different actual blocks in memory. 64-bit operating system can allocate maximum amount of 32-bit addresses multiple 32-bit programs--they're not limited same 32-bit memory addresses.

however, there limits: operating system can have limits set size page file allowed grow to. unless you've deliberately told operating system so, not have 64 gb of total virtual memory. , if did, can't allocate 64 gb every program, you'd have outofmemory error before os allocates virtual address @ 0xfffffffff program. (in fact, wouldn't surprised learn 0xfffffffff reserved error-code location, similar 0x0.) since addresses program knows have no correlation true memory addresses, there's possibility you'd end being allocated memory address program thinks of 0xfffffffff, if operating system isn't using anywhere near memory.

is there 1 big giant page table includes pages every process or each process has own page table?

likely both... , some.

  1. each process has private memory table, , os actively prevent program accessing memory address hasn't been allocated table.
  2. there's such thing shared memory, 2 processes need use same information can create area of shared memory , have addresses in memory space accessible both.
  3. the operating system needs have way track how overall memory available, address spaces free/used, , virtual memory blocks have been allocated locations in ram or in page file.

so, supposing process has been allocated memory @ address 0x00000002, when goes load value out of memory address, operating system might recognize maps real memory address 0x00000f23, , memory address value fetched cpu register. or, realize has moved page containing address onto disk somewhere, in case operating system find empty part of memory , load page's data disk memory first. (again, memory address doesn't have correlation original memory address program requested.)

if there isn't empty memory pull page from, os first have move data out of memory , page file. tries intelligently determine memory least used in near future. end memory getting requested shortly after gets swapped disk, replace next piece of memory program request. "thrashing" causes computers insufficient memory go really, really slow, since disk accesses orders of magnitude slower memory accesses.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -