Anyone know how to adjust the Vitual Memory Page Files?

knighthawk

Registered
I was reading in some of the threads about repartitioning a hard drive and moving the VM file over to that drive (to reduce frags), and another person said that he increased his VM file size from the default 80mb to 600mb. How do I do these things?

I have been looking through the documentation provided by Apple in the librarys/documentation section, and it seems REALLY weak! Is there more documentation that I am missing? The help files seem directed more toward beginning mac users than users that have owned macs since the Mac Plus.
 
I'm not at an OS X box now, but I seem to recall that in the /etc/rc or /etc/rc.common script (or somewhere around there) is the call to the dynamic paging program with a bunch of arguments, one of which is 80000000. I imagine you could change that number to something bigger and get the effect you're looking for.

-Rob
 
dynamic_pager [-F filename] [-L low water alert trigger] [-H high water alert trigger] [-S file size] [-P priority]

This is set at boot by /etc/rc

eg:

<...>
##
# Start the virtual memory system.
##

ConsoleMessage "Starting virtual memory"

swapdir=/private/var/vm

# Make sure the swapfile exists
if [ ! -d ${swapdir} ]; then
ConsoleMessage "Creating default swap directory"
mount -uw /
mkdir -p -m 755 ${swapdir}
chown root:wheel ${swapdir}
else
rm -rf ${swapdir}/swap*
fi

dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile
<...>

Just change the 80000000 to 600000000 and change swapdir=/private/var/vm to wherever you want to put it.
 
You can find detailed instructions on ResExcellence

http://www.ResExcellence.com/hack_html_01/06-01-01.shtml

This will only tell you how to move the default location of the swap file, not change the default size. It also includes tips for setting up a partition to handle your OSX swapfile and a Linux swapfile.

Out of curiosity, why do you want to increase the swapfile size? What benefit does that give you?
 
Previous threads about this subject suggested that it increased VM access when you computer is using more than 80MB of VM (like with Photoshop or other memory hogs).

It increases speed because of less fragmentation, and only one file to sort through. The idea situation is to have a dedicated hard drive for scratch. Traditionally in UNIX, you want to have at least as much VM as your memory (but maybe that was only with systems of less than 128mb).
 
I'm surprised that apple hasn't gone the standard *nix way of creating a swap partition (not the same as a partition with only a swap file on it!) and using a swap file as a backup if the partition isn't big enough. Or at least making it an option. It's not really a problem for me (512MB RAM) but i can see it helping a 128MB imac!

Peter
 
For everything that Apple has done that is non-traditional UNIX, I am sure that they have a good reason. It might be traditional inside of Apple that they choose to do it this way, or it might even be that the performance is better using a standard HFS+ format than the SWAP format.

Who knows...
 
My guess is that since a swap partition requires you to repartition, they went with something which would allow a simple installation without the backup/repartition/install/restore work.
 
I was about to post a question on this. Apple should atleast have that hidden option somewhere for advance tweaking.

When osX was first release, I've even have reserve partition space just for the swap partition! :( too bad I haven't found a way to do it yet. Well I've also haven't really played with osX in that kind of detail.

But, there will be s significant speed difference between a swap file and a swap partition though! Mainly because a swap partition is just a raw partition without a filesystem. The OS read/writes raw swap data to/from it without having to go through the extra filesystem layer. This makes swap memory a whole lot faster.

I like to see that on osX someday. :(
 
Originally posted by knighthawk
For everything that Apple has done that is non-traditional UNIX, I am sure that they have a good reason. It might be traditional inside of Apple that they choose to do it this way, or it might even be that the performance is better using a standard HFS+ format than the SWAP format.

Who knows...

Those who don't study UNIX has to reinvent it, poorly...
 
I don't know how VM really works for everything else, but for IRIX another UNIX flavor, here's a summary.

When coder/developers creates an application/binary... they usually reserve the maximum memory needed for the application to run. So when you run the application it goes out and mark pages of memory for reserve, sadly, even though it really needs to use a fraction of it. It is a common practice for these coders to always reserve the max, and something even more than what the application really needs. In IRIX, instead of using REAL physical memory, instead the kernal goes out an reserve swap memory, but allows the application to use the physical memory when it needs it. The the code goes out to reserve memory, the kernel force it to reserve the swap space, because it's not really using it anyway, and for the pages of memory it is actually using, it reserves the real memory. This allows the system to optimize real memory usage. VM is not a replacement for physical memory, but more like a another partition of memory where reserve memory are swap to. Without it, the kernel will start reserving the real memory, and you'll find yourself quickly running out of memory. So even if you have loads of memory, like over 1G of ram, it's still would add significant performace increase to use VM.

Here's an example: You have an application, APP. When you run it, it will reserve 64M of memory, but of the 64, it uses only 4M. The system will swap out 60M into swapspace, and use only 4M of real memory that it actually needs. Without it, it will reserve all 64M of your real memory. If you only have 128M of ram, you'll find yourself quickly out of memory. The system simply runs more efficient with VM.

It's common that most application will reseve 2X to 2.5X or even 4X the actually memory it needs. Ir depends on the coder. Thats pretty much why ppl say you need swap space 2-4X your physical memory.

The second usage is, when you dont have enough physical memory, then the kernal actually goes out and swap to swap space. I guess this is the method most users are familiar with. Useful for low memory systems, but will deteriote performace.

I know this is not the most technically correct way to explain it. I'm sure some UNIX guru can explain it much more accurate than I can, but I hope it gives you an idea.

So bottom line, even if you got adequate meory. Using VM is still recommended.

NEXT:

Swap file VS. Swap Partition.

In the unix world, creating a swap file is the means to temporary add more swap space. It is by no means a permanent swap. WHY? Simply because swapping to a file requires reading and writing to a few extra layers. That means it's a hell of a lot slower than swapping to a raw swap partition. Any system that swaps to a file vs swapping to a partiton is comparable a lot slower. If you have a Linux (or FREEBSD) system handle, you can try it and compare. For example Linux with a partition performs a lot faster (memory wise) than with just a swap file.

This is what dissappoints me about osX. It's pretty fast now, but I want to see how much faster it can be if, I can create a raw partition. Doing a man on fstab says that it's possible. But osX doesn't seem to use the fstab to activate swap like Linux or BSD. Because I can create a raw partition, but cannot tell osX to swap to it. /etc/fstab seems to be ignored. :(

Anyone else looked into this? I'm sure there is a way! I dont think apple will go through the trouble in stripping out that piece of code in the kernel.

-devinci
 
Back
Top