A question about virtual memory.

Ralf Mardorf kde.lists at yahoo.com
Mon Nov 9 13:01:34 UTC 2020


On Mon, 9 Nov 2020 23:18:17 +1100, Owen Thomas wrote:
>Why isn't virtual memory transferred to physical memory as soon as or
>perhaps not long after the space becomes available?

My guess is...

Probably because copying virtual memory from the swap on a disk to the
RAM, that isn't needed that moment, if needed anymore at all, makes no
sense, but would waste resources that could be used for something else.

Keep in mind that the kernel tries to manages memory in a smart way,
using all available memory, so it probably tends to free memory when
needed. It doesn't reorganise memory all the time. Probably some kind
of garbage collection and/or other mechanisms manage the memory from
time to time.

If you remove a file from a disk by rm, it doesn't overwrite the data,
it just removes the directory entry, the data is still stored on the
disk. I guess it's similar for memory and virtual memory usage. It's
possible to overwrite the data, but OTOH it's still kind of a cache.

Taking a look at my memory by running free claims that from 7850 MiB,
just 1982 MiB are used, but only 1358 are free. Actually my machine is
more or less idle at the moment, just running a few apps, so the
available 5660 MiB are much likely more or less quasi free, too.

[rocketmouse at archlinux ~]$ man free | grep available
       available
              Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into  ac‐
              count  page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emu‐
       The value for the shared column is not available from kernels before 2.6.32 and is displayed as zero.
[rocketmouse at archlinux ~]$ free --mebi
              total        used        free      shared  buff/cache   available
Mem:           7850        1982        1358         131        4509        5660
Swap:          2064         100        1964
[rocketmouse at archlinux ~]$ cat /proc/meminfo 
MemTotal:        8039240 kB
MemFree:         1397968 kB
MemAvailable:    5803248 kB
Buffers:          414916 kB
Cached:          3622620 kB
SwapCached:        15652 kB
Active:          3270032 kB
Inactive:        2593380 kB
Active(anon):    1441460 kB
Inactive(anon):   493072 kB
Active(file):    1828572 kB
Inactive(file):  2100308 kB
Unevictable:          80 kB
Mlocked:              80 kB
SwapTotal:       2114556 kB
SwapFree:        2011644 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:       1798696 kB
Mapped:           464112 kB
Shmem:            128572 kB
Slab:             635456 kB
SReclaimable:     574164 kB
SUnreclaim:        61292 kB
KernelStack:        7792 kB
PageTables:        19460 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6134176 kB
Committed_AS:    3909240 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:             1072 kB
HardwareCorrupted:     0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:     2711688 kB
DirectMap2M:     5548032 kB
DirectMap1G:     1048576 kB




More information about the ubuntu-users mailing list