Java NIO, written by Ron Hitchens, published by O'Reilly
What is Virtual Memory?
"All modern operating systems make use of virtual memory. It means that artficial addresses are used in place of physical(hardware RAM) memory addresses."
What are the advantages of using virtual memory?
1. Provide larger memory space
The idea is to use the harddisk to store the data in RAM. Memory paging is necessary. This is a scheme whereby the pages of a virtual memory space can be persisted to external disk storage to make room in physical memory for other virtual pages. Essentially, physical memory acts as a cache for a paging area, which is the space on disk where the content of memory pages is stored when forced out of physical memory. Aligning memory page sizes as multiples of the disk block size allows the kernel to issue direct commands to the disk controller hardware to write memory pages to disk or reload them when needed. It turns out that all disk I/O is done at the page level in paged operating systems. (Modern CPUs contain a subsystem known as the Memory Management Unit(Wikipedia), which contains the mapping information needed to translate virtual addresses to physical memory addresses.)
2. Reuse or share physical memory location
It is because more than one virtual address can refer to the same physical memory location. Due to the fact that all I/O flows through kernel space, all data (from/to) I/O device must be stored in a buffer B of kernel space first before copying to/from the buffer B' of a process in user space. With virtual memory, the addresses of B and B' are different virtual memory addresses V and V' respectively, but the V and V' both refer to the same physical memory location. Hence, no buffered data copy is needed between kernel space and user space which can save a lot of time.