what can be the maximum size of Virtual memory? - memory

I saw this question - What's the difference between "virtual memory" and "swap space"?
Here it is mentioned that virtual memory = RAM space + disk space - which the process can use.
So what can be the maximum size of Virtual memory ?
Is Max(Virtual Memory) = Disk space + RAM space - OS space (on RAM and Disk) ?

Virtual memory is not limited by size of memory pointers in the machine, virtual memory limits are not the same as addressing memory space. More virtual memory than available in your pointer-based address space using paging can be addressed
Virtual memory upper limits are set by the OS: eg. 32-bit Windows the limit is 16TB, and on 64-bit Windows the limit is 256TB.
Max limitation is physical disk space.
To determine how much virtual memory you need, since the user's system contains the different amount of RAM, it is based on the system. By default, the OS will set the appropriate size for Virtual Memory. The default and appropriate size of Virtual Memory is:
<Amount_Of_System_Memory> * 1.5 = <Default_Appropriate_Size_Of_Virtual Memory>
Personally speaking, to maintain the good overall system performance, you should be using the default size of actual size for Virtual Memory and the triple the value of the size of the main memory for the maximum size of Virtual Memory.

Theoretical Limits:
The starting point is the size of a virtual address. Generally 32-bits give a theoretical maximum of 2^32 virtual addresses.
Some systems divide the virtual address space in to dedicated regions (e.g., user and system). The VAX divided the address space into 4 regions (user, stack, system, reserved/unusable 1/4th of the address space).
From there . . .
Configuration Limits:
Most systems may impose a limit on the size of the user page table. This may be per user or a system limit. That restricts the size of the address space.
From there . . .
Runtime Limits:
The size of the available paging areas limit the maximum virtual address space a point in time.

Virtual memory management technique which help us to use secondary memory as it was a part of main memory.  
Virtual memory frees up RAM by swapping data that has not been used recently over to a storage device, such as a hard drive or solid-state drive (SSD).
So it limits the maximum size of the virtual memory equal to the maximum physical secondary memory we have.  
Why do we need Virtual Memory:
As we can't load the whole data into the ram and we have limited space there, so we have a page table in the ram which maps the address of the data in secondary memory in the page table, So on demand of the program, we swap-in and swap-out the data between RAM and secondary memory.
This technique is called the virtual memory. we don't have actual memory in ram but we still can have a reference of data in secondary memory which can be loaded and unloaded based on the need.

Related

Will mmu be used when cpu access virtual memory allocated via kmalloc?

I'm aware that memory allocated by kmalloc is physically continuous and virtual memory it returned has just an offset from its physical memory.
But if CPU tries to access the virtual memory it returned, will MMU and page table be used? I heard all address CPU use are virtual memory and has to be passed to MMU. But now that there is only an offset between its physical and virtual memory, I think there is no need to use page table and mmu anymore.

OPERATING SYSTEMS: what is the size of the virtual memory?

LINK 1: If size of the physical memory is 2^32-1, then what is the size of virtual memory?
the above link gives me an answer but i still do have some doubts.
pls answer in the way the questions posted here so that i will not be confused.....
1.Virtual memory is also called as Demand Paging whenever a page fault occurs
the operating system swaps the required page from the virtual memory. the virtual memory
here mean the harddisk or secondary storage. So how much space can be allocated for a
porcess in virutal memory? can this size(the space allocated for each process in the
Virtual memory) exceeds the size of our RAM size? i mean if our RAM is 4GB then what is
the maximum size of the virtual memory you can have for a process?can we have 4GB of
virtual memory for every process or can we have more than 4GB for every process?
(if it needs)
2.is the Virtual memory size fixed or dynamic? How much space is allocated for this memory
and in the above link it is told that 2^48 is the size of virtual memory in 64 bit machine
why is it only 2^48 and how can once can say a number like that?
thank you
If size of the physical memory is 2^32-1, then what is the size of virtual memory?
The size of the virtual address space is independent of the size of the physical address space. There is no answer.
So how much space can be allocated for a porcess in virutal memory?
That depends upon hardware limits, system parameters, and process quotas.
can this size(the space allocated for each process in the Virtual memory) exceeds the size of our RAM size?
Yes and it frequently does.
i mean if our RAM is 4GB then what is the maximum size of the virtual memory you can have for a process?
It can be anything. The rams size does not control.
can we have 4GB of virtual memory for every process or can we have more than 4GB for every process?
Both
is the Virtual memory size fixed or dynamic?
Dynamic
How much space is allocated for this memory and in the above link it is told that 2^48 is the size of virtual memory in 64 bit machine why is it only 2^48 and how can once can say a number like that?
It could be a hardware limit for a specific processor.
Paging is the way that virtual addresses are converted into physical addresses. This is done via page tables.
On x86 in Long Mode (64 bit mode), the page tables allow for 48 bit virtual address spaces (as in, 2^48 max size). This limitation is due to the design of x86's long mode page tables. Paging uses a few bits at a time from pointers to determine where to go next in the page tables. Basically, page tables are a relatively shallow b-tree style tree that let you look up the physical address corresponding to a virtual address.
To convert virtual addresses to physical addresses Long Mode page tables (for small pages) first extract 9 bits from the virtual address, then 9 more, then 9 more, then 9 more to find the right page, and use the low 12 bits to find the precise byte being accessed, for 48 bits total.
(For large and huge pages, x86 skips the last 1 and 2 steps of paging respectively, to find the address of the large or huge page, and the unused low 21 or 30 bits are used to find the precise byte in that page)
Virtual address spaces aren't necessarily dynamic, depending on what is meant by dynamic. The address space is always 48 bits (so long as you aren't switching between modes, like from long mode to protected mode with paging enabled (I.e. 32 bit mode)). Virtual address spaces are almost always sparse, as in most canonical (valid) addresses don't point don't point anything useful. The page tables don't have mappings for most addresses (accesses to those addresses generate page faults, which on Linux are often bounced back to userspace as the SIGSEGV you know and love).
That said, virtual memory can be dynamic in that when a page fault occurs the kernel could map in that page. To implement swap, OSes will use extra space on disk to give the illusion of more RAM by writing infrequently used pages back to disk, and lazily pulling pages back into RAM.
Fun fact, page tables have no restriction preventing the same physical page from being mapped in multiple times. You could build a monstrous page table with every virtual address pointing into exactly the same page (which is crazy), but doable. This means address spaces aren't necessarily sparse, just very likely to be. (Note that this page table would be huge. I'm sure someone has done the calculation, but my first guess would be order of terabytes)

Does virtual memory always provide a larger address space to a process?

From what I understand, a process is allocated real memory space, i.e., RAM. This is fixed so if the process needs more memory, it gets it from virtual memory.
So what the virtual memory does is just swaps pages into/out of the processes memory space as required, however, the processes REAL memory space remains constant.
My question is, is it possible for virtual memory to physically change the real memory space of the process in order to give it more memory?
At the risk of oversimplification, a process is allocated a page table (for simplicity, assuming a single level page page). The page table has a number of entries. each entry represent at a potential page in memory. The maximum size of the page table is limited by the address space of the processor. However, the operating system may restrict the page page size smaller than this.
(Assuming each executable starts a new process) The application loader will set up the address space to an initial state that includes all the static data, executable code, pre-allocated modifiable data, and an initial state.
There is no physical memory at this point.
As the program start up, it will reference pages in virtual memory that have no physical memory (page fault). The operating system will then assign physical memory pages to the virtual pages. At startup there will be many page faults.
As the application runs it can allocate more virtual memory up to the limits of the page table size.
As the application runs, the operating system can remap physical memory to virtual memory. The same virtual address can have multiple physical addresses while the program runs.
So this is an incorrect assumption.
From what I understand, a process is allocated real memory space, i.e., RAM. This is fixed so if the process needs more memory, it gets it from virtual memory.
This is not correct:
So what the virtual memory does is just swaps pages into/out of the processes memory space as required, however, the processes REAL memory space remains constant.
Yes to this:
My question is, is it possible for virtual memory to physically change the real memory space of the process in order to give it more memory?

Virtual memory without secondary storage

Can you have virtual memory without a secondary storage ( hard disk ) ?
In a pure sense, yes you can: Virtual Memory
What makes memory virtual is the fact that all memory accesses by the process are intercepted at the CPU level and a hardware Memory Management Unit is used to manage a mapping of the process address space onto the physical memory, no matter where that storage is presently really located.
You can have computing systems with virtual memory that have no backing storage (which is what people call it when you can move pages of memory out to disk for later retrieval).
In this case, the virtual memory system is used to allow the OS to intercept and prevent illegal memory references, but not in order to increase the working-set size of processes beyond the amount of installed physical memory.

What does the memory address mean?

Does a hex memory address represent the position in the memory as a whole?
e.g. 4 gb ram and there is a memory adress. Does it point to the position(in bytes) that the data starts at? e.g. at 2.1 gb.
How do memory address work on hard disk before the data is loaded into memory?
Is there ever a case where parts of the data are fetched from memory and other data is fetched from disk? How are the locations differentiated?
Thanks
A hex memory address (like what you would see if you printed out the value of a pointer) points to a location in virtual memory.
On a 32 bit system, each process has a full 4GB of virtual memory. This virtual memory is managed by the CPU and the operating system. When you access a location in virtual memory, the CPU and operating system determine where in the systems actual physical memory that location is mapped, and the data is retrieved from there.
The operating system may also take things out of physical memory and swap them to disk, in order to make room in physical memory for other things. Then, if you try to access the virtual memory location of something that was swapped from physical memory to disk, a "page fault" is generated which causes the OS to re-load the page from disk into physical memory.
Modern operating systems have virtual memory.
This means that the address which uses your program to access some byte in memory, is purely "virtual", non-existent. The operating system maps it via special hardware controllers to real memory locations which are completely different and there may be no physical memory location at all for a given address. For example, you may mmap() a file into (virtual) memory, and accessing a byte at the virtual addresses would mean accessing a byte of file. Similarly, if some memory page wasn't used for a long time, the OS may swap off the page from physical RAM to disk. In this case virtual memory wouldn't point to physical memory locations too.
In most cases - yes. But some processors uses 2 values to calculate real address. For example Intel 8086.
Hardisk is only storage, that has its own system to store information. So before any CPU operation is executed, data has to be loaded into RAM.

Resources