How much of logical memory is actually allocated for each process on disk?

0

Suppose the processor is 32 bit. So each process running on that processor gets 2^32 bits of logical memory.

  1. If the system is having n processes, is n*2^32 bits allocated on disk? where is it allocated? is it in swap space?
  2. If the page size is 4KB,then total number of pages are 2^32/2^12 = 2^20. is sum of the pages resides on disk and RAM for this process is 2^20? if not, how many of these 2^20 is allocated? 3.#include <stdio.h> int main(){ printf("Hello World"); }

    is this simple process also occupies 2^20 pages on RAM+Disk?

  3. #include <stdio.h> int main(){ int x; scanf("%d",&x); while(x!=0){ malloc(sizeof(int)); x--; } }

    How many pages are allocated on disk+RAM initially at the time of loading? is it also 2^20?if not how it grows as each malloc call invoked?

veerendra

Posted 2016-06-04T02:38:10.303

Reputation: 9

It's virtual memory. You're confusing the address space size and what a running process actually uses. – Daniel B – 2016-06-04T07:57:32.613

Is this another homework question? – DavidPostill – 2016-06-04T18:05:50.073

Welcome to [su]! Please try and ask 1 question at a time (otherwise your question will be closed as too broad). Please read How do I ask a good question? and On-Topic.

– DavidPostill – 2016-06-04T18:06:14.940

Answers

1

The OS allocates as many virtual pages as necessary to map the sections defined in the executable files.

If another process is already running the same executables then the OS reuses read-only pages at least and if the OS supports "copy-on-write" then it reuses already mapped unaltered read-write pages for a new process. For stacks, heaps, etc., it will reserve the virtual address space, but the pages would be allocated on demand, i.e. when stack grows beyond already mapped space, then the OS allocates more page(s)

The space in a swap file is allocated when the system decides to swap some altered pages of a process out of RAM. This is optimal strategy though, the actual behavior may vary from OS to OS.

Serge

Posted 2016-06-04T02:38:10.303

Reputation: 2 585