Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Oct 1997 13:04:07 -0700
From:      David Greenman <dg@root.com>
To:        "Peter Edwards" <peter.edwards@isocor.ie>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Wheres all my memory going? 
Message-ID:  <199710082004.NAA22784@implode.root.com>
In-Reply-To: Your message of "Wed, 08 Oct 1997 19:48:21 BST." <343A136B0000097B@paradise.isocor.ie> (added by paradise.isocor.ie) 

next in thread | previous in thread | raw e-mail | index | archive | help
>David Greenman wrote:
>> >But if theres 152MB of free memory then why is it ever pushing stuff out
>> >into swap???
>> 
>>    Because there was something that took lots of memory and triggered a
>> pageout. The system "caches" the data written out to swap - it isn't
>freed
>> up just by being paged back in again. This is why it is so important that
>> you have at least as much swap as you have main memory. The weird thing
>isn't
>
>My knowledge of VM is pretty basic, but I dont get this. The "newvm" doc in
>/usr/share/papers indicates that one of the reasons for the switch to the
>region-based VM approach was to avoid having to assign each page of
>phyiscal memory with a page of swap space, and being able to treat the sum
>of physical memory and swap space as the available virtual memory of the
>machine.

   Sort of. Actually, the advantage is that swap space can be lazy-allocated
only when it is actually needed, rather than always allocating all of it up-
front. In the old 4.3BSD VM system, even read-only executable pages had to
be backed by swap - the system copied the whole thing to swap first before
executing the code...this is SLOW for obvious reasons.

>Surely the fact that the memory is "cached" is just so the process being
>swapped out can also get its old pages as quickly as another can use that
>free memory for it's new pages? If memory runs out, so be it. The cached
>pages can be freed up for other use, because they're on disk, but why is
>there a requirement to have more swap than physical RAM? What benefit is
>gained by not mirroring each memory page with one in the swap files as was
>done previously. Sorry for sticking my inexperienced oar in, but I'd like
>to get a grip on this.

   I can't parse most of the above. Basically, you have a modified page; the
system runs out of physical memory and needs to page something out; space is
allocated for the page in swap and the page is paged out. Now, the process
that the page originally belonged to needs it again, so the system pages it
back in, but the page isn't "freed from swap". If the system needs to reclaim
the page again after it was swapped back in and if it hasn't been modified
while it was in memory, then it is just freed - it doesn't need to be paged
out again because a copy is "cached" on the disk in the swap partition. This
saves precious disk I/O. Does this make sense?

-DG

David Greenman
Core-team/Principal Architect, The FreeBSD Project



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710082004.NAA22784>