Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > How to clear the Virtual Memory?

How to clear the Virtual Memory?
Thread Tools
Jim_MDP
Mac Enthusiast
Join Date: Jul 2003
Location: Kali
Status: Offline
Reply With Quote
Dec 15, 2003, 05:02 AM
 
Well� a search on this turned up nil, so�

How do I reset, and hopefully reclaim, the VM space?

The damn thing has passed 3 gig and nothing I do seems to affect it.

Who's got the magic sudo command?

     
entrox
Senior User
Join Date: Jan 2003
Location: Stuttgart, Germany
Status: Offline
Reply With Quote
Dec 15, 2003, 05:55 AM
 
You don't "clear" virtual memory. As the name says, it's virtual e.g. not real. A process can map 2G of memory on a machine with 128M for example. Perhaps it only commits 20M and that's what it's really using - the rest is actually reserved in virtual memory until the process needs more. Only if it exceeds the amount of real memory (look at the output of `top'), it will access the swap space. So there's nothing to reclaim - it's virtual after all.

Addendum: Open the activity monitor and select "System Memory". There are two columns which are relevant: Real Memory and Virtual Memory. The former displays how much a process is really using while the latter shows how much it requested, but didn't commit to. Think of physical memory as being a cache for virtual memory.
( Last edited by entrox; Dec 15, 2003 at 06:04 AM. )
     
wireframe
Junior Member
Join Date: Dec 2003
Location: UK
Status: Offline
Reply With Quote
Dec 15, 2003, 06:44 AM
 
To clear it, just close a few apps that are taking up large amounts of memory, and look for anything that has been leaking memory too. Then OS X will clear the pagefiles after a bit. Panther seems to be pretty good at doing this.
     
Landos Mustache
Professional Poster
Join Date: Dec 2002
Location: Partying down with the Ewoks, after I nuked the Death Star!
Status: Offline
Reply With Quote
Dec 15, 2003, 11:48 AM
 
restart. Clearing it manually can cause you to lose work.

"Hello, what have we here?
     
CatOne
Mac Elite
Join Date: Nov 2001
Status: Offline
Reply With Quote
Dec 15, 2003, 11:56 AM
 
Originally posted by Jim_MDP:
Well� a search on this turned up nil, so�

How do I reset, and hopefully reclaim, the VM space?

The damn thing has passed 3 gig and nothing I do seems to affect it.

Who's got the magic sudo command?

'sudo periodic daily weekly monthly'

This runs the cron scripts which includes a find command which refreshes the locate database. Seems to flush stuff out of VM as a side-effect.

Note, having "the Virtual Memory" full isn't really a bad thing -- most of the stuff is cached and makes apps re-launch faster.
     
chabig
Addicted to MacNN
Join Date: Jun 1999
Location: Las Vegas, NV, USA
Status: Offline
Reply With Quote
Dec 15, 2003, 12:09 PM
 
The VM size displayed in Activity Monitor is just a number. It has no relationship to physical machine resources. As entrox said, it's virtual, not real. Don't worry about it.

And I've always believed that running the periodic scripts has become an old wive's tale. They have no effect on my VM size. But they're harmless, so run them if you want to.

Chris
     
entrox
Senior User
Join Date: Jan 2003
Location: Stuttgart, Germany
Status: Offline
Reply With Quote
Dec 15, 2003, 12:24 PM
 
Now that I think of it, I should have made myself clearer: Clear the Virtual Memory?! That would require some sort of re-allocator, which is a concept so ridiculous it makes me want to laugh out loud and chortle.
     
himself
Mac Elite
Join Date: Jan 2002
Location: Live at the BBQ
Status: Offline
Reply With Quote
Dec 16, 2003, 03:42 AM
 
Originally posted by chabig:
As entrox said, it's virtual, not real. Don't worry about it.
It's not real? Okay, I understand the technical definition of virtual is something akin to "not real", but when your VM swapfiles are taking up 3-4gigs or more of valuable diskspace (and continue growing) that you maybe cannot afford to spare, it seems very real. I thought 10.2 was bad with how it handles VM, but in all honesty, Panther is worse. Neither does an acceptable job of reclaiming disk space (i.e., for a large image or video file one may have been editing, but that file and app have been long put away), and VM files tend to just sit there until you restart. I thought the whole point of VM was to allocate "memory" (in the absence of physical memory) to apps that need it, when they need it. And when they're done with it, take it back. Or is that not correct?
"Bill Gates can't guarantee Windows... how can you guarantee my safety?"
-John Crichton
     
dtriska
Mac Elite
Join Date: Sep 2000
Location: Canada
Status: Offline
Reply With Quote
Dec 16, 2003, 04:19 AM
 
Originally posted by Jim_MDP:
Well� a search on this turned up nil, so�

How do I reset, and hopefully reclaim, the VM space?

The damn thing has passed 3 gig and nothing I do seems to affect it.

Who's got the magic sudo command?

Are you saying that you have 3 GB of swap files, or that you saw 3 GB of virtual memory allocated in either top or Process Viewer. If the latter, don't worry about it. If the former, either logout and back in, or restart.
     
chalk_outline
Dedicated MacNNer
Join Date: Nov 2003
Location: sleep
Status: Offline
Reply With Quote
Dec 16, 2003, 06:05 AM
 
Originally posted by himself:
It's not real? Okay, I understand the technical definition of virtual is something akin to "not real", but when your VM swapfiles are taking up 3-4gigs or more of valuable diskspace (and continue growing) that you maybe cannot afford to spare, it seems very real. I thought 10.2 was bad with how it handles VM, but in all honesty, Panther is worse. Neither does an acceptable job of reclaiming disk space (i.e., for a large image or video file one may have been editing, but that file and app have been long put away), and VM files tend to just sit there until you restart. I thought the whole point of VM was to allocate "memory" (in the absence of physical memory) to apps that need it, when they need it. And when they're done with it, take it back. Or is that not correct?
That's what I thought too. Usually I just put down the mouse, grab a cup of coffee and make love to my woman. By the time I get back I am at the Log-in screen. Everybody wins. OS X rules.
     
entrox
Senior User
Join Date: Jan 2003
Location: Stuttgart, Germany
Status: Offline
Reply With Quote
Dec 16, 2003, 06:14 AM
 
Originally posted by himself:
I thought the whole point of VM was to allocate "memory" (in the absence of physical memory) to apps that need it, when they need it. And when they're done with it, take it back. Or is that not correct?
That is partially correct. The point of virtual memory is to give applications an address space, which is not bounded by the size of physical memory. The system works like this: each process can allocate up to 4G memory on Mac OS X (I think it's 8G on G5s), regardless of the actual number of available memory. This works because the kernel doesn't really allocate the memory but only reserves it. Now, the trick is that the kernel will page in so called "pages" (4K chunks of memory) from a backing store (usually the swapfiles) into physical memory, as soon as the process tries to read or write from/to an address in its allocated space. This is called a "page fault", because the process tried to access a logical address that is not in physical memory. This will go on as long as there are free pages in physical memory (think of it like a cache). As soon as the number of free pages dips below a certain threshold, the kernel will perform special steps to ensure that infrequently accessed pages will get moved out of the physical memory to the backing store (this is also the distinction between active and inactive pages - see `top'). This process is called "paging out" or "swapping out". If a process has bad locality of reference or a lot of processes compete for memory, the kernel will begin to page quite a lot, which ultimately results in disk thrashing (crunch crunch crunch) and poor performance.
You can get some statistics by calling `vm_stat' in the terminal or looking at top (it shows page ins and outs).

So, what was I trying to say? The point is, that the size of reserved VM is completely irrelevant with regard to used disk space or performance and that you can't "clear" VM short of killing a few processes. On my machine with 768M RAM, the current VM size is 5.11G and the swapfiles occupy 514M right now.

Don't Panic.
     
Sophus
Mac Enthusiast
Join Date: Nov 2001
Location: Norway
Status: Offline
Reply With Quote
Dec 16, 2003, 06:27 AM
 
Originally posted by himself:
It's not real? Okay, I understand the technical definition of virtual is something akin to "not real", but when your VM swapfiles are taking up 3-4gigs or more of valuable diskspace (and continue growing) that you maybe cannot afford to spare, it seems very real. I thought 10.2 was bad with how it handles VM, but in all honesty, Panther is worse. Neither does an acceptable job of reclaiming disk space (i.e., for a large image or video file one may have been editing, but that file and app have been long put away), and VM files tend to just sit there until you restart. I thought the whole point of VM was to allocate "memory" (in the absence of physical memory) to apps that need it, when they need it. And when they're done with it, take it back. Or is that not correct?
I believe some people try to understand OSX memory management using experiences and knowledge from OS9 as a reference. OSX' memory management is completely different and much smarter. Don't get caught up in the numbers in top/monitor. OSX does an excellent job at memory management and will page out/reclaim or do whatever necesseary steps for the machine to take advantage of the resources in an optimal way at all times.

Some good explanations in this thread BTW.
( Last edited by Sophus; Dec 16, 2003 at 07:01 AM. )
     
chabig
Addicted to MacNN
Join Date: Jun 1999
Location: Las Vegas, NV, USA
Status: Offline
Reply With Quote
Dec 16, 2003, 10:06 AM
 
Entrox's explanation is spot on. My Powerbook has 640MB RAM, and the VM size is 4.23GB. I've been using it pretty hard today for video stuff, yet I only have three swap files totally 256MB.

You can see the swapfiles at /private/var/vm/

Check yours. I'm sure they don't total 3-4GB.

Chris
     
asxless
Mac Elite
Join Date: Sep 1999
Status: Offline
Reply With Quote
Dec 16, 2003, 11:28 AM
 
Unfortunately, if you are running OS X on a Mac with limited available disk space (<1GB) the "don't worry, be happy" advice in many of the preceding posts is actually dangerous.

Despite the good detailed technical explanations proffered, the OS X virtual memory implementation can (and will) continue to fill up the boot volume with swap files to the point of damaging system preferences, etc. This behavior (in Jaguar) has been documented in several threads here and on other Mac fora. This weakness is exacerbated by the behavior of several of Apple's own applications: iPhoto has a habit of creating a prodigious number of swap files and the Finder does not report the missing disk space in a timely manner. BTW OS X does _not_ warn you that your boot volume is so full that applications (e.g. the Finder) are unable to write their preferences back to disk.

So if you have more than 2 GB of free disk space on your boot volume -- "don't worry, be happy". But if you've allowed your boot volume become over crowded -- don't wait until spring cleaning In the mean time, the simplest way to free up the disk space used by the VM swap files is to restart OS X... and then get to cleaning up your boot volume ASAP.

-- asxless in iLand
( Last edited by asxless; Dec 16, 2003 at 11:41 AM. )
     
neilw
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status: Offline
Reply With Quote
Dec 16, 2003, 11:29 AM
 
I've got 5.5 GB vmsize, and about 1.5 GB swapfiles. So I wouldn't assume they're *that* small.

Not that I particularly care, until I otherwise run out of disk.
     
ReggieX
Professional Poster
Join Date: Oct 2000
Location: Toronto, ON
Status: Offline
Reply With Quote
Dec 16, 2003, 05:38 PM
 
You don't even have to restart, simply logging out and logging back in again will clear most of the swapfiles out.

Then again, if you're seeing gigs upon gigs of actual swapfiles being created, sounds like you've got a serious memory leak.
The Lord said 'Peter, I can see your house from here.'
     
chabig
Addicted to MacNN
Join Date: Jun 1999
Location: Las Vegas, NV, USA
Status: Offline
Reply With Quote
Dec 16, 2003, 08:11 PM
 
...simply logging out and logging back in again will clear most of the swapfiles out.
Are you sure? It never does that for me. And I don't see why it should or would. Logging out is nothing like restarting. All you're doing is quitting some threads. From the OS perspective I don't think the kernel cares whether you're logged in or not.

Chris
     
Toyin
Mac Elite
Join Date: Nov 2000
Location: Boston
Status: Offline
Reply With Quote
Dec 16, 2003, 11:51 PM
 
Originally posted by asxless:
Unfortunately, if you are running OS X on a Mac with limited available disk space (<1GB) the "don't worry, be happy" advice in many of the preceding posts is actually dangerous.

Despite the good detailed technical explanations proffered, the OS X virtual memory implementation can (and will) continue to fill up the boot volume with swap files to the point of damaging system preferences, etc. This behavior (in Jaguar) has been documented in several threads here and on other Mac fora. This weakness is exacerbated by the behavior of several of Apple's own applications: iPhoto has a habit of creating a prodigious number of swap files and the Finder does not report the missing disk space in a timely manner. BTW OS X does _not_ warn you that your boot volume is so full that applications (e.g. the Finder) are unable to write their preferences back to disk.

So if you have more than 2 GB of free disk space on your boot volume -- "don't worry, be happy". But if you've allowed your boot volume become over crowded -- don't wait until spring cleaning In the mean time, the simplest way to free up the disk space used by the VM swap files is to restart OS X... and then get to cleaning up your boot volume ASAP.

-- asxless in iLand
I think you need a new hardrive or need a better archiving solution, if you're constantly running with only 1gb free. And Panther has warned me several times when I've gotten under 1gb of free space left.
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
     
asxless
Mac Elite
Join Date: Sep 1999
Status: Offline
Reply With Quote
Dec 17, 2003, 12:54 AM
 
Originally posted by Toyin:]I think you need a new hardrive or need a better archiving solution, if you're constantly running with only 1gb free. And Panther has warned me several times when I've gotten under 1gb of free space left.
Say what bro? It's a bit rich to suggest that I "need a new hardrive or need a better archiving solution" when you say that "Panther has warned [you] several times when [you]'ve gotten under 1gb of free space left". Sounds like you are the one with the inadequate hard drive and/or archiving issues

Since you obviously missed my point --- I was suggesting that anyone who is running low on available disk space needs to do a little house keeping to free up space for the OS X VM swap files, regardless of which version of OS X they are running. Shockingly enough _everyone_ has not upgraded to Panther yet. So IMHO any advice about what to do about VM swap files etc. needs to include more than just Panther users.

-- asxless in iLand
     
Toyin
Mac Elite
Join Date: Nov 2000
Location: Boston
Status: Offline
Reply With Quote
Dec 17, 2003, 01:06 AM
 
Originally posted by asxless:
Say what bro? It's a bit rich to suggest that I "need a new hardrive or need a better archiving solution" when you say that "Panther has warned [you] several times when [you]'ve gotten under 1gb of free space left". Sounds like you are the one with the inadequate hard drive and/or archiving issues

Since you obviously missed my point --- I was suggesting that anyone who is running low on available disk space needs to do a little house keeping to free up space for the OS X VM swap files, regardless of which version of OS X they are running. Shockingly enough _everyone_ has not upgraded to Panther yet. So IMHO any advice about what to do about VM swap files etc. needs to include more than just Panther users.

-- asxless in iLand
I got your point, but you said, and I quote "BTW OS X does _not_ warn you that your boot volume is so full that applications (e.g. the Finder) are unable to write their preferences back to disk.". So you didn't get my point. OSX does warn you, but unless you do some cleaning you will run into problems, just as the dialog suggests.

By the way, last I checked I had 17gb free on my PB, but when I was working on 60+minutes of DV my hardrive was getting a little over worked. The offending files are now on one of my 120gb firewire drives .
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
     
asxless
Mac Elite
Join Date: Sep 1999
Status: Offline
Reply With Quote
Dec 17, 2003, 01:58 AM
 
Originally posted by Toyin:
I got your point, but you said, and I quote "BTW OS X does _not_ warn you that your boot volume is so full that applications (e.g. the Finder) are unable to write their preferences back to disk.". So you didn't get my point. OSX does warn you, but unless you do some cleaning you will run into problems, just as the dialog suggests.
To be more actuate... OS X 10.3 warned you. Prior versions of OS X (10.0, 10.1 & 10.2) do not provide any warning about low disk space. As I posted earlier "IMHO any advice about what to do about VM swap files etc. needs to include more than just Panther users" because everyone has not upgraded to Panther yet.

FWIW I have experienced OS X (10.2) swap files filling up a boot volume and trashing system, Finder etc. preferences without warning. But I have not yet had the pleasure of seeing OS X (10.3) issue a low disk space warning

-- asxless in iLand
     
himself
Mac Elite
Join Date: Jan 2002
Location: Live at the BBQ
Status: Offline
Reply With Quote
Dec 17, 2003, 04:06 AM
 
Originally posted by Sophus:
I believe some people try to understand OSX memory management using experiences and knowledge from OS9 as a reference. OSX' memory management is completely different and much smarter. Don't get caught up in the numbers in top/monitor. OSX does an excellent job at memory management and will page out/reclaim or do whatever necesseary steps for the machine to take advantage of the resources in an optimal way at all times.

Some good explanations in this thread BTW.
Yeah, memory management is somewhat smarter than OS9, but in crunchtime situations, I'm really not all that impressed with OS X memory management (well, okay sometimes I am impressed...).

And when I quote numbers upwards of 2GB, I'm not talking about top/monitor numbers. I'm talking about the swapfiles you can find at /var/vm . Right now, things are light. But my main qualm with Panther VM is how it goes about making swapfiles. For instance, the latest swapfile is equal in size to the sum of all of the previous swapfiles. Or, in other words, the amount of diskspace the swapfiles take up doubles with each new swapfile created. Even if you have a comfortable cushion of disk space on your startup volume, it can fill up pretty quickly in crunchtime situations, when you are working on several large files in several memory hungry applications... your relatively tiny 512MB worth of swapfiles can quickly skyrocket to 1GB, then 2GB, 4GB, etc... Jaguar at least kept swapfiles a consistent size, but it was otherwise the same thing.

Yeah, maybe this is the way these things work and have worked for the majority of computer history, but something needs to be improved. Or maybe I should blow my savings on a maxxed out DP G5.
"Bill Gates can't guarantee Windows... how can you guarantee my safety?"
-John Crichton
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:54 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,