A question about virtual memory.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about virtual memory.

Owen Thomas
A recent post relating to this topic has prompted me to ask this question.

Looking at the System Monitor, I see that virtual memory begins to fill when physical memory is near its maximum. However, when physical memory usage drops, I do not see a drop in virtual memory with a corresponding rise in physical memory - it seems that data in virtual memory remains there at least until it is needed. Sometimes it seems that I can have much more free space in physical memory than I have data in virtual memory.

Why isn't virtual memory transferred to physical memory as soon as or perhaps not long after the space becomes available? How might I instruct my computer to behave as I might expect? Indeed, am I expecting too much of the wrong thing?

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: A question about virtual memory.

Liam Proven
On Mon, 9 Nov 2020 at 13:20, Owen Thomas <[hidden email]> wrote:
>
> A recent post relating to this topic has prompted me to ask this question.
>
> Looking at the System Monitor, I see that virtual memory begins to fill when physical memory is near its maximum. However, when physical memory usage drops, I do not see a drop in virtual memory with a corresponding rise in physical memory - it seems that data in virtual memory remains there at least until it is needed. Sometimes it seems that I can have much more free space in physical memory than I have data in virtual memory.
>
> Why isn't virtual memory transferred to physical memory as soon as or perhaps not long after the space becomes available? How might I instruct my computer to behave as I might expect? Indeed, am I expecting too much of the wrong thing?

Why would you want your computer to waste time fetching stuff back
into RAM that you haven't used?

Stuff is swapped out when it hasn't been used for a while.

https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)

If you don't use it, then it stays swapped out. If you use it, it's
brought back.

The OS tries to keep the disk cache big so that if you want something
new, it'll load quicker.


--
Liam Proven – Profile: https://about.me/liamproven
Email: [hidden email] – gMail/gTalk/gHangouts: [hidden email]
Twitter/Facebook/LinkedIn/Flickr: lproven – Skype: liamproven
UK: +44 7939-087884 – ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: A question about virtual memory.

ubuntu-users mailing list
In reply to this post by Owen Thomas
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@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@archlinux ~]$ free --mebi
              total        used        free      shared  buff/cache   available
Mem:           7850        1982        1358         131        4509        5660
Swap:          2064         100        1964
[rocketmouse@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

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: A question about virtual memory.

Owen Thomas
Thanks Liam, Ralf, for the responses. Please excuse the length of time it took to write a follow-up; I went to bed shortly after posting my question, and have only now been able to respond.

I guess an LRU or variant thereof is being used for memory management so that once virtual memory begins to be used, it never goes back to zero. Perhaps some operating system utility grabs memory for some purpose and never lets it go, or possibly an application is leaking memory that is eventually being exported to disk.

Hmmm...


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: A question about virtual memory.

Liam Proven
On Mon, 9 Nov 2020 at 23:58, Owen Thomas <[hidden email]> wrote:
>
> Thanks Liam, Ralf, for the responses. Please excuse the length of time it took to write a follow-up; I went to bed shortly after posting my question, and have only now been able to respond.
>
> I guess an LRU or variant thereof is being used for memory management so that once virtual memory begins to be used, it never goes back to zero. Perhaps some operating system utility grabs memory for some purpose and never lets it go, or possibly an application is leaking memory that is eventually being exported to disk.
>
> Hmmm...

Oh, it probably will _eventually_. And you can tune it with the
"swappiness" parameter.


--
Liam Proven – Profile: https://about.me/liamproven
Email: [hidden email] – gMail/gTalk/gHangouts: [hidden email]
Twitter/Facebook/LinkedIn/Flickr: lproven – Skype: liamproven
UK: +44 7939-087884 – ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users