操作系统:虚拟内存的大小是多少?

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?

以上link给了我一个答案,但我还是有些疑惑。 请按照这里发布的问题的方式回答,这样我就不会感到困惑.....

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? 

谢谢

分页是将虚拟地址转换为物理地址的方式。这是通过页面 tables.

完成的

在长模式(64 位模式)的 x86 上,页面 tables 允许 48 位虚拟地址 spaces(如 2^48 最大大小)。这个限制是由于 x86 的长模式页面 tables 的设计。分页一次使用指针中的几位来确定页面 table 中的下一个位置。基本上,page tables 是一个相对较浅的 b-tree 风格的树,让你查找对应于虚拟地址的物理地址。

将虚拟地址转换为物理地址 Long Mode page tables (for small pages)先从虚拟地址中提取9位,再提取9位,再提取9位,再提取9位,再提取9位,找到合适的页,并使用低 12 位来查找正在访问的精确字节,总共 48 位。

(对于large和huge page,x86分别跳过最后1和2步分页,寻找large或huge page的地址,未使用的低21或30位用于查找精确字节在那个页面)

虚拟地址 space 不一定是动态的,具体取决于动态的含义。地址 space 始终是 48 位(只要您不在模式之间切换,例如从长模式切换到启用分页的保护模式(即 32 位模式))。虚拟地址 space 几乎总是稀疏的,因为在大多数规范(有效)地址中,不要指向任何有用的东西。页面 table 没有大多数地址的映射(访问这些地址会产生页面错误,这些错误在 Linux 上经常被反弹回用户 space 作为您知道和喜爱的 SIGSEGV ).

也就是说,虚拟内存可以是动态的,因为当发生页面错误时,内核可以映射到该页面。为了实现交换,操作系统将在磁盘上使用额外的 space,通过将不经常使用的页面写回磁盘并延迟将页面拉回 RAM 来提供更多 RAM 的错觉。

有趣的是,页面 table 没有限制可以防止多次映射同一物理页面。您可以构建一个巨大的页面 table,其中每个虚拟地址都指向完全相同的页面(这很疯狂),但可行。这意味着地址 space 不一定是稀疏的,只是很有可能是。 (请注意,此页面 table 会很大。我确定有人已经计算过,但我的第一个猜测是 TB 级)

If size of the physical memory is 2^32-1, then what is the size of virtual memory?

虚拟地址的大小space与物理地址的大小space无关。没有答案。

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?

两者

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?

这可能是特定处理器的硬件限制。