The virtual memory/paging facility lets a kernel "virtualize" memory to userspace processes. The kernel can take pages from physical memory, and arrange them through paging so they appear contiguous to a userspace process.
A limit can be set on a userspace process's memory and if the process goes beyond it a "page fault" occurs, which causes a CPU exception which bounces back to the kernel. This prevents the userspace program from messing with memory allocated to the kernel or other programs, without the kernel's permission.
Typically userspace programs ask the kernel to extend this limit via well defined interfaces (called by the C functions malloc()
and free()
for example.). The kernel is responsible for keeping track of how much and what memory a program is allocated.
This "page fault" mechanism can also let the kernel swap the page the process was trying to access with one from disk, if the kernel is able to overprovision memory (and both Windows and Linux support this) hence why it is called swapping. If the memory access was indeed invalid (i.e. the process is trying to access memory it didn't ask for first) then typically the process will be killed with a SIGSEGV.
So "swapping" is an additional feature (in Linux you can actually disable it entirely if you want) that depends on virtual memory/paging, but isn't required just because a CPU has virtual memory/paging. The concepts are not the same but swapping depends on paging/virtual memory to exist.
Also, after more closely reading your question, "paging" is sometimes uses as a synomym for "swapping" - but I've never heard of "swapping" meaning the whole process's memory is swapped out vs. "paging" meaning only part of it is swapped out.
But why does linux need a swap partition then? If the physical memory
is full, some processes will be outsourced to the hard drive and a new
process will be mapped from virtual memory to physical memory.
"Virtual memory" is physical memory, just "remapped." The MMU hardware cannot directly map to any storage device. The MMU can throw a fault that tells the kernel a process tried to access memory it shouldn't have - and the kernel can use this mechanism to see that a process wants something back from disk that it thought was in memory and then do the "swap". The point being it's the operating system that decides to save pages to disk so it can use those pages for other processes, not the hardware.