1

What is the need of virtual memory on 64 bit microprocessor? As i know it can address around 16exabyte memory. So why do we still need paging. Thanks in advance

Yasin Fatullayev
  • 137
  • 1
  • 11
  • You don't if you have 16 exabyte of memory – SomeWittyUsername Oct 21 '18 at 16:34
  • I have less than 16exabyte. Say 8 Gb ram. Di we still need paging if we have les than 16exabyte? – Yasin Fatullayev Oct 21 '18 at 18:23
  • You don't absolutely **need** it, it just makes everything (mostly OS architecture related) better and simpler (or more powerful). – Ped7g Oct 21 '18 at 20:29
  • Thank you for clarification. I know the 64 bit architecture has its own memory protection feature. Is paging still implemented for backward compatibility? – Yasin Fatullayev Oct 21 '18 at 23:58
  • X86-64 does not have a separate memory protection feature. It uses paging for memory protection. The paging structures are different because the linear addresses are 48 bits instead of 32 bits, so it is not backward compatible. In fact, x86-64 *removed* one of the memory protection mechanisms in ia32—that is, segment limits and permissions, because it is not heavily used, since paging is so much more flexible and powerful. – prl Oct 22 '18 at 00:42
  • Thank you very much. I think i got all the answers i need. Thank you all – Yasin Fatullayev Oct 22 '18 at 00:46

3 Answers3

2

In addition to providing virtual memory, paging is used to control memory protection, to provide separation between different applications and between applications and the operating system. Paging also allow different applications to use the same linear address to access different memory locations.

prl
  • 11,716
  • 2
  • 13
  • 31
1

The memory pager is also capable of doing other very useful things, such as mapping a file to memory and paging only the blocks that are actually used from disk, mapping the same data into multiple processes with copy-on-write, giving each program only as much physical RAM as it actually uses, implementing shared memory, memory-mapped I/O and virtualization.

The main reason to have virtual memory is to be able to work with more data than the system has physical memory, but most of the underlying infrastructure (with the significant exception of the paging algorithm) would be needed anyway, and has hardware support.

Davislor
  • 14,674
  • 2
  • 34
  • 49
  • Working sets that exceed physical memory was one of the main *original* reasons for virtual memory. Now memory protection is probably the most important one. (R^X for security.) Some kind of segment / memory-region based mechanism could be viable. (Not like x86 segment registers, more like huge and variable-size pages.) – Peter Cordes Oct 23 '18 at 03:22
  • @PeterCordes True. Although you could implement memory protection on your pages without ever swapping out to disk. – Davislor Oct 23 '18 at 03:29
  • @PeterCordes It would be trickier to implement fast memory protection for different processes without any kind of virtual addressing whatsoever, but that might be achieved by partitioning the address space and marking which regions of memory each segment is allowed to read, write or execute. – Davislor Oct 23 '18 at 03:33
  • Oops I meant W^X in my first comment (write XOR exec permission) https://en.wikipedia.org/wiki/W%5EX. Anyway yes, each process would have multiple segments. I think you meant to say "each process is allowed to ...", because you'd want all of a single segment to be uniform. – Peter Cordes Oct 23 '18 at 03:38
  • 1
    @PeterCordes i see what you mean now. Yes, that kind of memory protection could be orthogonal to a virtual address space or to swapping from disk. – Davislor Oct 23 '18 at 04:04
-3

In the future we may see paging go away. One other problem is that we have systems with 8GB of physical memory with 64 bit processors. As soon as you need more than 8GB of memory, you have to resort to paging. It should not be that long until we have computer systems that have terrabytes of memory and paging will not be necessary.

In that case we will need new operating systems and even new computer systems to take advantage of such large memory.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • *As soon as you need more than 8GB of memory, you have to resort to paging.* What exactly are you referring to here? Clearly it's possible to design an ISA without paging that can use 64-bit addresses. (Or 40-bit or whatever you want). But for this `[x86-64]` question, paging is mandatory in x86-64 long mode (64-bit mode), regardless of how little physical RAM you have. (https://wiki.osdev.org/X86-64#Long_Mode). With an x86-64 CPU in fully-32-bit legacy mode, you can have paging disabled and access up to 4GiB of physical address space. Not up to 8, IDK where you're getting that number. – Peter Cordes Oct 23 '18 at 03:11
  • You can cover those 8GiB with 8x 1GB hugepages, and get zero TLB misses on CPUs with enough 1G TLB entries. And BTW, the future of x86 paging could be Intel's 5-level page tables: https://wiki.osdev.org/Setting_Up_Long_Mode#Future_of_x86-64_-_the_PML5. See also [Why in 64bit the virtual address are 4 bits short (48bit long) compared with the physical address (52 bit long)?](https://stackoverflow.com/q/46509152). I think it's unlikely that we'll abandon paging entirely any time soon; it's too useful for memory protection, and hugepages are a viable way to scale to huge working sets. – Peter Cordes Oct 23 '18 at 03:17
  • You are referring to the terminology of a specific processor architecture and its terminology. In the general usage, outside Intel processor documentation, paging is the process of exchanging data between secondary storage and memory. There is no requirement that a processor implement pages if i has more than 8GB of memory, it is just that the Intel processors require it. – user3344003 Oct 23 '18 at 16:30
  • The question title is asking about "virtual memory", which you can have even without a mechanism for storing pages to disk and faulting them back in. See Davislor's answer on this question. Anyway, why are you saying that 8GB is some kind of cutoff or threshold for x86-64? As I commented earlier, I don't think there's any hardware-imposed 8G limit, just a 4G limit for legacy mode. – Peter Cordes Oct 23 '18 at 19:43
  • Virtual memory IS the process of using secondary storage to simulate physical memory. Logical memory translation is the process of mapping pages to physical page frames. You can have logical memory translation without virtual memory but you cannot have virtual memory without logical page translation.. – user3344003 Oct 24 '18 at 12:57
  • That's not how most people define the terminology. For me (and I think most people) it's virtual memory if there's a page table + TLB so each process can have its own virtual address space, even without paging/swap space. Wikipedia's https://en.wikipedia.org/wiki/Virtual_memory agrees: *"The primary benefits of virtual memory include freeing applications from having to manage a shared memory space, increased security due to memory isolation, and being able to conceptually use more memory than might be physically available, using the technique of paging."* – Peter Cordes Oct 24 '18 at 13:20
  • So what you're calling "virtual memory" is what most people call "paging", and what you're calling "logical page translation" is what most people call "virtual memory". I'm assuming you got that terminology from some operating-systems textbook; it's common for textbook authors to pick their own terminology that they think will help clarify things, even if it's not universally used. – Peter Cordes Oct 24 '18 at 13:22