LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   swap space (or) swap file (http://www.linuxquestions.org/questions/linux-newbie-8/swap-space-or-swap-file-654791/)

yusufs 07-10-2008 03:05 AM

swap space (or) swap file
 
Dear Friends,

I have a requirement that I have to increase swap in my production Linux RHEL ES 4.0 server. Currently,


[root@oracle ~]# swapon -s
Filename Type Size Used Priority
/dev/cciss/c0d0p3 partition 8217236 160 -1

Now , I understand that I can add swap space or swap file to achieve this.. Can anyone let me know which one is the best option to work with ?..adding swap space or adding swap file ?


Thanks
Yusuf

Mr. C. 07-10-2008 03:11 AM

You can swap to an entire partitiion, or to a file.

Swapping to a partition has much better performance.

matthewg42 07-10-2008 03:30 AM

Swap partitions are a little faster, but you have to have some unpartitioned space on your disks to add another swap partition.

It is also more difficult to change the amount of space used for swap if you are using swap partitions, since it requires a change in partitioning on the disk.

So it depends - which is more important for you - a small increase in speed, or flexibility?

yusufs 07-10-2008 03:36 AM

Quote:

Originally Posted by matthewg42 (Post 3209790)
Swap partitions are a little faster, but you have to have some unpartitioned space on your disks to add another swap partition.

It is also more difficult to change the amount of space used for swap if you are using swap partitions, since it requires a change in partitioning on the disk.

So it depends - which is more important for you - a small increase in speed, or flexibility?

Thanks Mathew and Mr.c ,


[root@oracle ~]# fdisk -l

Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
255 heads, 63 sectors/track, 8920 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 3 3201 25695967+ 83 Linux
/dev/cciss/c0d0p2 4225 8920 37720620 83 Linux
/dev/cciss/c0d0p3 3202 4224 8217247+ 82 Linux swap

Partition table entries are not in disk order

Disk /dev/sda: 293.6 GB, 293630353408 bytes
255 heads, 63 sectors/track, 35698 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 35698 286744153+ 5 Extended
/dev/sda5 1 12450 100004562 83 Linux
/dev/sda6 12451 24900 100004593+ 83 Linux
/dev/sda7 24901 35698 86734903+ 83 Linux


I dont think I have unpartitioned space here , so the only option is to create a swap file ?.. Right ?.. I created swap file many times, but I feel that the system is slow after doin this ?..

Any comments ?


Yusuf

matthewg42 07-10-2008 03:57 AM

Quote:

Originally Posted by yusufs (Post 3209797)
I dont think I have unpartitioned space here , so the only option is to create a swap file ?.. Right ?.. I created swap file many times, but I feel that the system is slow after doin this ?..

Any comments ?


Yusuf

You can add another hard disk and create a swap partition on that. I would not recommend using a flash drive for swap as they have a fairly limited number of read/write cycles, and a swap device might kill one pretty quick.

What swap does is enable you to run programs for which you do not have enough physical memory, or allowing you to run more concurrent processes than you would be able to without swap.

If you are not having "out of memory" problems with your current system load, and do not need to change this, then you do not need to add more swap.

Adding more swap if you are not changing the load on he system may change how the OS allocates physical RAM, which may affect performance, but it may not.

If you are adding swap so that you can run more or larger programs, then it is likely that you will get a performance hit on any given process. If this is the case then you must decide which is more important - performance for a given process or the ability to run more/larger processes.

If your system's physical memory can be expanded, this is probably a better option, given that RAM is pretty cheap these days. Of course, this won't help you if your system is already loaded with as much RAM as it can take.

syg00 07-10-2008 04:27 AM

Quote:

Swapping to a partition has much better performance.
This may have been true for 2.4 kernels, but certainly isn't for 2.6
There is no difference - the way the (physical) swap I/O is handled was changed markedly in the 2.5 timeframe. All the swap I/O is now handled by the normal block driver - no filesystem entanglement.

Choose whatever is most convenient.

Vit77 07-10-2008 04:59 AM

I've found that the system performance depends on number of swap places (partitions, files).
So, I'd recommend to create a swap file. Then, in case you need more swap space, it'd be better not to create a new file, but enlarge the current one.

Some other ideas:
- to use LVM (allows to resize partitions dynamically)
- to add a new HDD (in this case it's recommended to have some swap space on each drive)

syg00 07-10-2008 06:08 AM

If you are actually swapping, look at assigning the same priority for multiple swap extents. The swap daemon will "soft stripe" across all that are at the same priority - works well.
Best is not to have (any of) your swap on a disk that has other I/O - especially active binaries.

Don't know about using LVM - just another level of software to get in the way. I've never tested it tho', as I don't use LVM.

yusufs 07-17-2008 02:02 AM

Quote:

Originally Posted by syg00 (Post 3209901)
If you are actually swapping, look at assigning the same priority for multiple swap extents. The swap daemon will "soft stripe" across all that are at the same priority - works well.
Best is not to have (any of) your swap on a disk that has other I/O - especially active binaries.

Don't know about using LVM - just another level of software to get in the way. I've never tested it tho', as I don't use LVM.

Thanks Mathew,syg00 and Vit77.. It helped me in getting a better understanding.



Yusuf


All times are GMT -5. The time now is 06:24 PM.