Linux oracle swap size

Linux oracle swap size

Swap spaces are a way by which the operating system manages resources in the system to ensure efficient performance.

Oracle Linux uses swap space if your system does not have enough physical memory for ongoing processes. When available memory is low, the operating system writes inactive pages to swap space on the disk, and thus free up physical memory.

However, swap space is not an effective solution to memory shortage. Swap space is located on disk drives, which have much slower access times than physical memory. Writing to swap space effectively degrades system performance. If your system often resorts to swapping, you should add more physical memory, not more swap space.

Swap space can be either in a swap file or on a separate swap partition. A dedicated swap partition is faster, but changing the size of a swap file is easier. If you know how much swap space your system requires, configure a swap partition. Otherwise, start with a swap file and create a swap partition later when you know what your system requires.

Creating a Swap File

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1000000
1000000+0 records in 1000000+0 records out 1024000000 bytes (1.0 GB, 977 MiB) copied, 6.10298 s, 168 MB/s
mkswap: /swapfile: insecure permissions 0644, 0600 suggested. Setting up swapspace version 1, size = 976.6 MiB (1023995904 bytes) no label, UUID=43964855-e81f-414c-a61c-370408085ba4
/swapfile swap swap defaults 0 0
sudo systemctl daemon-reload

Creating a Swap Partition

  1. Create the swap partition by using either fdisk or parted .
    • If using fdisk , create the partition as discussed in Creating Partitions. Then use t to change the partition type from the default to 82 Linux swap / So .
    • If using parted , specify linux-swap at the File system type? prompt as shown in Partitioning Disks by Using parted.
  2. Initialize the partition as a swap partition. For example, if the partition is /dev/sda2 , use the following command:
/dev/sda2 swap swap defaults 0 0

Viewing Swap Space Usage

To view a system’s usage of swap space, examine the contents of /proc/swaps :

Filename Type Size Used Priority /dev/sda2 partition 4128760 388 -1 /swapfile file 999992 0 -2

In this example, the system is using both a 4GB swap partition on /dev/sda2 and a 1GB swap file, /swapfile . The Priority column shows that the operating system to write to the swap partition rather than to the swap file.

Читайте также:  Linux get timezone name

You can also view /proc/meminfo or use utilities such as free , top , and vmstat to view swap space usage, for example:

SwapCached: 248 kB SwapTotal: 5128752 kB SwapFree: 5128364 kB

Removing a Swap File or Swap Partition

To remove a swap file or swap partition from use:

    Disable swapping to the swap file or swap partition, for example:

Источник

Increasing swap space on Oracle Linux

Matthias Hoys

Matthias Hoys

Whenever you increase the physical memory of a Linux server, you probably also need to increase the swap space. There are several ways you can do this. In most cases, the swap space is present as a separate swap partition, which can be a stand-alone partition or part of a logical volume inside of a volume group. The swap space can also be present as a swap file, or even a combination of swap partitions and swap files with priorities.

1) Investigating the system

You can use the commands swapon and free to display information about your currently configured swap space. You can also have a look at the system files /etc/fstab and /proc/swap.

Let’s have a look at my system:

$ swapon -s Filename Type Size Used Priority /dev/dm-1 partition 3571704 59144 -1 $ cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 3571704 59144 -1 $ cat /etc/fstab|grep swap /dev/mapper/vg_ol6ora11g02-lv_swap swap swap defaults 0 0

So, in my case, I have one swap partition of 3,5GB which is part of a logical volume (lv_swap) inside a logical volume group.

2) First option: adding a swap partition

To create a new swap area on a disk partition, you need the command mkswap. After the swap area is created, you have to activate it using the command swapon. Finally, to enable the swap area after a server reboot, you have to add it to the system file /etc/fstab.

In my example, I first added a 2GB virtual disk to my VirtualBox installation. This new disk was visible under Oracle Linux as disk device /dev/sdb. I used this disk device to create my new swap area on. Note: please make sure you use the correct disk device!

$ mkswap -c /dev/sdb mkswap: /dev/sdb: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 2097148 KiB no label, UUID=8e6f61c3-1070-450f-b89a-3af8d646e985 $ swapon /dev/sdb $ swapon -s Filename Type Size Used Priority /dev/dm-1 partition 3571704 133296 -1 /dev/sdb partition 2097144 0 -2 $ cat /etc/fstab|grep /dev/sdb /dev/sdb swap swap defaults 0 0

3) Second option: adding a swap file

Читайте также:  Geforce 8400 gs linux driver

When you have no free disk or disk partitions available, it’s also possible to increase your swap area by creating a swap file. First, you need to create an empty file with the required size using the dd command. Then you need to activate the swap file using mkswap and finally add it to the /etc/fstab file (same as with swap partitions).

Let’s check my example where I add a 2GB swap file under /root:

$ dd if=/dev/zero of=/root/swapfile count=1024 bs=2097152 1024+0 records in 1024+0 records out 2147483648 bytes (2.1 GB) copied, 245.797 s, 8.7 MB/s $ mkswap -c /root/swapfile mkswap: /root/swapfile: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 2097148 KiB no label, UUID=99076d49-9893-425f-b0b1-1f21c7e9f8be $ swapon /root/swapfile $ swapon -s Filename Type Size Used Priority /dev/dm-1 partition 3571704 298532 -1 /root/swapfile file 2097144 0 -2 $ cat /etc/fstab|grep swapfile /root/swapfile swap swap defaults 0 0

4) Third option: increasing the size of a logical volume

If your swap area is on a logical volume, you can increase it by extending the logical volume using the command lvextend. However, things are a bit more complicated. First, if you don’t have any free extents available, you need to add a physical volume to the volume group where the logical volume is located in. Second, to increase the size of the swap area, you need to temporarily disable it first (swapoff) followed by the recreation of the swap area using mkswap.

In my example, I first add the device /dev/sdb to my volume group, next I increase the logical volume to 4.5GB using lvextend, and then I disable and recreate the swap area:

lvm> vgextend vg_ol6ora11g02 /dev/sdb No physical volume label read from /dev/sdb WARNING: swap signature detected on /dev/sdb. Wipe it? [y/n] y Wiping swap signature on /dev/sdb. Writing physical volume data to disk "/dev/sdb" Physical volume "/dev/sdb" successfully created Volume group "vg_ol6ora11g02" successfully extended lvm> vgs VG #PV #LV #SN Attr VSize VFree vg_ol6ora11g02 2 2 0 wz--n- 21.50g 2.00g $ swapoff /dev/mapper/vg_ol6ora11g02-lv_swap $ lvextend -L 4.5G /dev/mapper/vg_ol6ora11g02-lv_swap Extending logical volume lv_swap to 4.50 GiB Logical volume lv_swap successfully resized $ mkswap -c /dev/mapper/vg_ol6ora11g02-lv_swap mkswap: /dev/mapper/vg_ol6ora11g02-lv_swap: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 4718588 KiB no label, UUID=04fa98f4-c72e-4bb6-94b4-57f9384f779f $ swapon /dev/mapper/vg_ol6ora11g02-lv_swap $ swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4718584 0 -1

Источник

Читайте также:  Открыть локальную сеть linux

How Much Swap Space to Add for Oracle Database on Linux

There are also lot of other parameters come into play when you are configuring your database for performance. If your database needs large SGA size for performance reasons, you may want to consider using HugePages. By default the SGA page size is chunked into 4k. When you use HugePages, you the SGA page size is chuncked into a minimum of 2MB. You have to keep this in mind, when you are configuring your database.

You can view the current HugePagesize as shown below.

$ grep Huge /proc/meminfo HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 Hugepagesize: 4096 kB

This Oracle article will give you an introduction to hugepages, which you may want to consider, when you are using large memory.

On Linux, execute the free command, to identify the current RAM size and SWAP size. By default free command shows output in kb. Since we gave -m option, it is displaying the output in MB. As shown below, this system has 3 GB of RAM and 2 GB of swap.

$ free -m total used free shared buffers cached Mem: 3034 2907 126 0 107 1103 -/+ buffers/cache: 1696 1338 Swap: 2047 85 1962

You can also get the total RAM size, and swap size of your system from the /proc/meminfo file as shown below. This displays the output in kilo bytes.

$ egrep 'MemTotal|SwapTotal' /proc/meminfo MemTotal: 3107636 kB SwapTotal: 2096472 kB

You can add swap space to your system using any one of the two methods that explained in this How to add swap space article.

The following example will add 1 GB of swap file to your Linux system.

dd if=/dev/zero of=/root/myswapfile bs=1M count=1024 chmod 600 /root/myswapfile mkswap /root/myswapfile swapon /root/myswapfile

Источник

Оцените статью
Adblock
detector