Solaris 10 swap device and filesystem

Hi all,

Q1) Due to application requirement, i am required to have more swap space.
Currently my swap is on a partition with 32GB.
I have another partition with 100GB, but it already has a UFS filesystem on it.

Can i just swap -d /dev/dsk/current32gb and swap -a /dev/dsk/ufs100gb ?
Will there be a problem if the 100gb already has a filesystem on it ?

p.s. Due to personal preference, I do not want to create a swapfile and add on to the existing swap space.

Q2) The swap size recommendation for the application is to have 75% * RAM (128gb) = 96GB swap.

Do i really have to create the swap in multiples of 32GB (e.g.. 32, 64, 96) ?

Is there any performance impact if i just use a 100GB swap instead of a 96GB one ?

Regards,
Noob

Q1) Problem: the swap would trash the filesystem!

BTW my personal thumb formula is: swap-GB = 4 x SQRT(RAM-GB)

Q2) No, can be any size.

Q3) The larger the used swap, the lower is the paging to/from the swap. The unused swap does not matter for performance (but is wasted disk space).

1 Like

Hi MadeInGermany

Thanks for your reply.

Q1) Do you mean that there will be a problem if i use a partition with an existing UFS filesystem as the swap device ? or do actually you mean "No problem" ?

Q2) That would be 4 x SQRT(128GB) = 4 x 11.31 = around 48GB ?

Q3) Can you elaborate abit further here ? - The "used" swap here means "allocated" swap or really "utilized" swap. I thought when memory is insufficient, paging to/from swap will occur. So how does having a big swap reduce paging ?

Last but not least, is it okay for me to use my 100GB partition with UFS filesystem as my new swap device ? - as I do not want to re-partition the harddisk and affect the rest of my partitions

p.s. initially i allocate 32GB of swap for my 128GB ram, but oracle's grid installation for database suggest 0.75(RAM) for swap, and hence i am trying to use an existing partition (100GB) as the actual swap device

Hope to hear from you soon.

If you use the same disk partition for swap and for a UFS filesystem, the contents of the UFS filesystem will be destroyed if any data is swapped to that swap space.

If you were willing to create a swapfile in the UFS filesystem and add that to your swap space, that would be different. But since you have said that is not an option, you MUST NOT allocate the same partition to be used as swap space and as an active filesystem.

1 Like

Hi Don,

Thanks for your reply. The current ufs partition is use as a standby and i am willing to lose its current content.

Does that means I can use it to as a swap device despite having created an ufs filesystem on it; (as it will be overwritten during page swap) right ?

Ensure that the 100GB is not mounted. Then it can be trashed, you can add it to swap.
(If it's a partition on a physical disk on Sparc, it might give an error - in this case you must change the "wm" flag to "wu" in "format"s partition menu, in order to declare it unmountable. It's a good habit anyway.)
With used swap I mean the utilized swap, (blocks - free) in swap -l

1 Like

Given the fact using a swapfile would be the most sensible solution, can you elaborate on this personal preference against it?

How much free space is available on the 100GB partition and on the root (/) one?

Will the application make actually use of the swap, i.e. is there a risk the application do more than reserving that extra memory and effectively write pages there?

If you are sure the answer is no for the last question, you might fake swap space by using a sparse file:

e.g.:

mkfile -n 64g /var/tmp/64g-sparse
swap -a `lofiadm -a /var/tmp/64g-sparse`
1 Like

Oh no, please don't have a swap file in /var/tmp/ !! "Application is slow, perhaps it helps to delete some temporary files..."
Better something like /critical_swapfile/
And then, isn't a sparse file a risk by itself? What happens if there is no free disk space in the file system? Kernel panic?

1 Like

Well, nothing particular will happen if that file is removed by a clueless administrator. The lofi device will still point to the same inode, now linkless. After a reboot, the system will start without that extra swap configured whether the file is removed or not.

I'm not sure but it might lock or panic indeed. To clarify, my suggestion actually assumes no physical swapping will occur, and is just there to trick an application that demand plenty of swap but won't write anything to it. As you might know, Solaris is not overcommiting memory so each reservation must be backed by some storage (RAM or swap) but there is no physical I/O as long as that reserved memory is not accessed.

1 Like

Hi jilliare,

Thanks for your reply.
Reason for not using a swapfile is mostly due to standardization. We have a few solaris servers running and none of them are using swapfile.

The 100GB partition is totally empty, except that I have newfs it. Probably touch some files in it, but I have rm -r *.

Thus i am thinking of using it to replace my current 32GB swap partition.
The only concern I have is (-- the UFS filesystem on it ) and if there will be any problem if the OS actually start utilizing the swap space.

Regards,
Noob

Well, if your 100Gb partition is empty, you can either create a swapfile in it, or trash the filesystem on it and use the partition as swap. The former method (swapfile) would be simpler to implement.

You should never configure a partition containing a file system as a raw swap device, especially if it is mounted at the same time. In any case, any actual paging operation will corrupt the file system.

1 Like

Hi MadeInGermany,

Yeap. I am using SPARC and i managed to add the UFS partition as swap. It did not prompt me any error (but i am not sure if it is because the swap is not used yet)

I have also change the partition flag from wm to wu.

Regards,
Noob

---------- Post updated at 06:50 AM ---------- Previous update was at 06:47 AM ----------

Hi Jilliagre,

Thanks. Sorry for my poor english, but what do you mean by "trash the filesystem on it" ?
Do you mean to mount the 100GB partition as swap and ignore the fact of the UFS filesystem on it ?
(p.s. the 100GB is already umounted from its original mountpoint)

Regards,
Noob

You do not need to manually trash anything. Swap does not care about any pre-existing data.

1 Like

Hi MadeinGermany,

Thanks for your reply. Seeing the word trash make me curious.
How do you trash a filesystem ? What do you guys mean by trash ?:rolleyes:

Regards,
Noob

trash ~= wipe

While as MadeInGermany already rightly stated, the swap command will ignore the fact a file system is present on the raw partition, I would nevertheless recommend to wipe the file system, at least enough for it not to be recognized as such, for example with:

dd if=/dev/zero of=/dev/xxx bs=128k count=10

With /dev/xxx being the actual device storing the old file system (beware about mistake here!)

1 Like

Hi Jilliagre,

Sorry for the late reply and thank you for your advice !
I have already change the swap disk to the partition.

Can I still do a dd to it ?
dd if=/dev/zero of=/dev/md/dsk/50 bs=128k count=10

Regards,
Noob

To be 100% sure there is no risk, you should temporarily remove it as a swap device before wiping it.

swap -d /dev/md/dsk/50 && { dd if=/dev/zero of=/dev/md/dsk/50 bs=128k count=10 ; swap -a /dev/md/dsk/50 ; }
1 Like

The key thing here is that if you created a UFS filesystem, mounted it, maybe put some files in it, maybe removed some or all of those files, and then decide to use that partition as swap space; you MUST unmount that UFS filesystem before declaring that partition to be swap space. And, after telling the OS it can use that partition as swap space, you MUST assume that that partition can never be mounted as a filesystem again until you tell the OS it can no longer use that partition as swap space AND you use something like newfs to create a new filesystem on that partition before you mount it as a filesystem again.

1 Like