memory management - In linux every process is given a 4GB of virtual address space considering a 32-bit architecture -
hi new linux kernel development. want clearity following statement.
*> in memory, every process given 4gb of virtual address space
considering 32-bit architecture. lower 3gb virtual addresses accessible user space portion of process , upper 1gb accessible kernel space portion.*
- does mean each process in linux allocated memory space 1gb+3gb?
- if yes there hundreds of process in linux , 100*4gb space system gets of memory space?
- what has relation kernel stack , user stack ?
- does every process in linux has kernel , user stack ?
intro
linux, modern operating systems, uses virtual pages provided modern architectures, including x86 family.
in system virtual memory, physical memory (actual ram resource) abstract process running on system. address space numbers memory could be.
paging
memory can mapped (put @ address) in pages architecture dependent size of memory chunk. if want put memory @ address process can use it, you'd have pick page aligned number (a multiple of page size) , place @ least 1 page there.
protection
virtual memory allows memory protection sets permissions process have. when process's executable memory mapped (the instructions executes stuff) read/execute only. means processor can execute memory, , can read it, can't write it.
when process loaded disk (in linux exec
system call) placed in memory several regions of memory mapped. these regions executable code program, data sections, , stack. process can request more memory mapped later using mmap
or brk
system calls.
when process tries access memory not have mapped, triggers infamous segfault
error, , kernel kill program. other times, hardware fault program have memory mapped, because kernel unmapped save until needed. happens here process stops running, kernel remaps memory, , process starts running again nothing happened.
address space
so size of address space upper limit of memory have if program had mapped every address possibly actual ram memory.
the 1 gig address space kernel part process's meta-data kernel keeps track of. instance, keep listing of open files, , mapped memory in process headers. keep thread headers there. again, of not mapped, needs.
note each process has own universe of addresses, never sees process has mapped @ addresses. way, process can act if process on machine, mapping memory address chooses.
also note, 4gb number because hardware addressing supports 32 bit numbers, largest number 1 can hold in 32 bit number 2^32 = 4,294,967,296. 4 gb. 1 can map 4gb of addresses memory.
this crappy intro, please googling on virtual memory.
Comments
Post a Comment