2

It says

   p: SWAP  --  Swapped size (kb)
  The non-resident portion of a task's address space.

   q: RES  --  Resident size (kb)
  The non-swapped physical memory a task has used.

  RES = CODE + DATA.

Okay, what does "non-resident portion" mean?

Does SWAP mean that hard disk is used as additional memory?

Kevin
  • 40,767
user4951
  • 10,519

2 Answers2

4

Yes, swap is when the hard disk is used to hold memory once RAM is full; on Linux it's normally held in a separate swap partition, but can use files. Mac and Windows use files on the regular filesystem. Paging excess memory out to disk like that keeps the OS from having to kill processes to free up real RAM, which is why it is generally recommended to have a swap partition for your Linux installation. However, it's a great deal slower (several orders of magnitude) than real RAM, which is why it's only used as a last resort (and why so much time is put into figuring out which page [4kB chunk of memory] to send to swap).

Matt
  • 8,991
Kevin
  • 40,767
4

Besides your configured paging devices, swap also counts pages that come from files mapped in with mmap. These pages are only actually loaded into physical RAM when they are referred to by the program. These pages will be paged out to the original file rather than to the swap devices if they ever need to be paged out.

paxdiablo explains this here: https://stackoverflow.com/questions/1972765/mmap-problem-allocates-huge-amounts-of-memory

Or see the mmap man page.

Johan
  • 4,148
  • I don't think that value is accounted as OS swap though (unless using mmap in a way that it needs swap, like MAP_PRIVATE). Although an mmaped file can be functionally swapped out of memory when the kernel needs to, this doesn't involve a write to normal swap as the backing file already exists elsewhere on your file system. In my mind, no writes to swap = no swap usage. – Matt Feb 16 '13 at 19:53