# Where is the swap file?



## fmalloy (Sep 27, 2000)

I'm curious - where does X put the VM swap storage? If you are low on disk does the VM file minimize your memory capacity? Can I move it to another disk?


----------



## ajmas (Sep 28, 2000)

If it is anything like any other Unix system, then you will have a special partition on your disk reserved for it - though I can't say for certain.


----------



## sverre (Sep 28, 2000)

Nope, it's a swapfile (or 2 it seems). I suppose Apple thought it a bit too hard for ppl to config swap partitions.
They're stored in /var/vm/
I don't think you can move them to another disk. They are likely opened before other disks are mounted.


----------



## ajmas (Sep 28, 2000)

Is there any option to make a swap partition? A swap partition certainly offers better performance than a swap file - especially since the OS knows that there is reduced risk of fragmentation.


----------



## fmalloy (Sep 28, 2000)

Yes, I seem them now. I have three of them; each one is 80MB. So I assume that I have only 240MB of VM? I only allocated a 1GB partition for OS X. I don't know how much gets created, and if it grows dynamically or not. Can't I somehow add a link to another partition to get more swap space?


----------



## sverre (Sep 29, 2000)

It grows dynamically. I only had 2 files when I checked, each also 80M. So I suppose it allocates them in chunks of that size. If you installed it on a 1GB partition you probably don't have much free space left though.


----------



## fmalloy (Sep 30, 2000)

Well, now I have 5 swapfiles (swapfile0 thru swapfile4)! The 4th swapfile seems to have gotten created when OmniWeb started allocating memory like crazy before I quit it. The last one got created at 4:31am, when I wasn't using the computer:


% ll /var/vm
total 781280
drwxr-xr-x   7 root  wheel       264 Sep 30 04:31 .
drwxr-xr-x  16 root  wheel       500 Sep 24 00:50 ..
-rw------T   1 root  wheel  80000000 Sep 24 18:03 swapfile0
-rw------T   1 root  wheel  80000000 Sep 24 18:11 swapfile1
-rw------T   1 root  wheel  80000000 Sep 24 18:47 swapfile2
-rw------T   1 root  wheel  80000000 Sep 29 21:19 swapfile3
-rw------T   1 root  wheel  80000000 Sep 30 04:31 swapfile4

So I've got a whopping 400MB just for swap. Now, the disk is 96% full (I only allocated 1GB for OS X). I wonder what's going to happen when the disk goes full.

I am very disappointed in this approach of adding arbitrary 80MB chunks and never releasing them when no longer needed. And it appears you can't have them put anywhere else. Do these files ever go away?

It would be nice to have a dynamically growing or shrinking file, or at least allow us to set the size of the swap file to keep it from getting out of control.

This seems to be worse than VM is OS9; at least you could set the size of the swap file.

Any comments or suggestions'? What's the size of everyone else's swap?


----------



## fmalloy (Sep 30, 2000)

Well, I just found this out: if I log out and back in, the additional three swap files are gone, and I'm left with the two original swap files:

% ll /var/vm
total 312512
drwxr-xr-x   4 root  wheel        92 Sep 30 10:43 .
drwxr-xr-x  16 root  wheel       500 Sep 24 00:50 ..
-rw------T   1 root  wheel  80000000 Sep 24 18:03 swapfile0
-rw------T   1 root  wheel  80000000 Sep 24 18:11 swapfile1

The other 240MB has been released:

% df -k 
Filesystem             1K-blocks     Used    Avail Capacity  Mounted on
/dev/disk0s8             1048440   778060   270380    74%    /

Hurray!

So, it appears you can free up large amounts of accumulated swap by logging out and back in. I'm glad you don't have to restart to do it.

It seems OS X partitions swap into 80MB chunks, adding another 80MB chunk when you need more swap due to launching more apps. Usually in UNIX, the administrator allocates one big swap file of a specified size, and that's the hard limit. I suppose this is a better way as it somewhat grows dynamically (at 80MB increments), but cannot shrink.

I found that logging out and back in (I was logged in for 5 days) does seem to clear out memory, release swap, and generally make things run smoother. It does take quite a while to log out and in though (on my beige G3).


Learning more each day!


----------



## sverre (Oct 1, 2000)

The reason loggin out and then in frees up vm is probably that it makes apps quit. Particulary Classic.app seem to be very bad att releasing the memory it allocates (perhaps for technical reasons), so quiting and restarting it might be enough to free quite a lot of mem.


----------

