Difference between revisions of "Adding and Managing Ubuntu 10.x Swap Space"
m (Text replacement - "<htmlet>ezoicbottom</htmlet>" to "") |
m (Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">") |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <table border="0" cellspacing="0"> | + | <table border="0" cellspacing="0" width="100%"> |
<tr> | <tr> | ||
<td width="20%">[[Adding a New Disk Drive to an Ubuntu 10.x System|Previous]]<td align="center">[[Ubuntu 10.x Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Ubuntu 10.x KVM Virtualization|Next]]</td> | <td width="20%">[[Adding a New Disk Drive to an Ubuntu 10.x System|Previous]]<td align="center">[[Ubuntu 10.x Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Ubuntu 10.x KVM Virtualization|Next]]</td> | ||
Line 97: | Line 97: | ||
+ | <htmlet>ezoicbottom</htmlet> | ||
<hr> | <hr> | ||
− | <table border="0" cellspacing="0"> | + | <table border="0" cellspacing="0" width="100%"> |
<tr> | <tr> | ||
<td width="20%">[[Adding a New Disk Drive to an Ubuntu 10.x System|Previous]]<td align="center">[[Ubuntu 10.x Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Ubuntu 10.x KVM Virtualization|Next]]</td> | <td width="20%">[[Adding a New Disk Drive to an Ubuntu 10.x System|Previous]]<td align="center">[[Ubuntu 10.x Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Ubuntu 10.x KVM Virtualization|Next]]</td> |
Latest revision as of 19:58, 27 October 2016
Previous | Table of Contents | Next |
Adding a New Disk Drive to an Ubuntu 10.x System | Installing and Configuring Ubuntu 10.x KVM Virtualization |
An important part of maintaining the performance of an Ubuntu system involves ensuring that adequate swap space is available relative to the memory demands placed on the system. The goal of this chapter, therefore, is to provide an overview of swap management on Ubuntu.
What is Swap Space?
Computer systems have a finite amount of physical memory that is made available to the operating system. When the operating system begins to approach the limit of the available memory it frees up space by writing memory pages to disk. When any of those pages are required by the operating system they are subsequently read back into memory. The area of the disk allocated for this task is referred to as swap space.
Identifying Current Swap Space Usage
The current amount of swap used by an Ubuntu system may be identified in a number of ways. One option is to cat the /proc/swaps file:
$ cat /proc/swaps Filename Type Size Used Priority /dev/sda5 partition 492540 0 -1
Alternatively, use the swapon command:
$ swapon -s Filename Type Size Used Priority /dev/sda5 partition 492540 0 -1
Finally, the free command may also be used:
$ free total used free shared buffers cached Mem: 1023064 447472 575592 0 21268 166108 -/+ buffers/cache: 260096 762968 Swap: 492540 0 492540
Adding a Swap File to an Ubuntu System
Additional swap may be quickly added to the system by creating a file and assigning it as swap. This is achieved as follows.
Create the swap file using the dd command (the size can be changed by adjusting the count= variable; the following creates a 131MB file):
$ sudo dd if=/dev/zero of=/newswap bs=1024 count=128000 128000+0 records in 128000+0 records out 131072000 bytes (131 MB) copied, 1.7639 seconds, 74.3 MB/s
Configure the file as swap:
$ sudo mkswap /newswap mkswap: /newswap: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 127996 KiB no label, UUID=683aa598-4922-490d-ac39-01d5cc5b419e
Add the swap file to the system in real-time:
$ swapon /newswap
Finally, modify the /etc/fstab file to automatically add the new swap at system boot time by adding the following line:
/newswap none swap sw 0 0
Once the swap space has been activated, verify that it is in use using the swapon –s command:
$ swapon -s Filename Type Size Used Priority /dev/sda5 partition 492540 0 -1 /newswap file 127996 0 -2
De-activate the additional swap space at any time using the swapoff command as follows:
$ sudo swapoff /newswap
Previous | Table of Contents | Next |
Adding a New Disk Drive to an Ubuntu 10.x System | Installing and Configuring Ubuntu 10.x KVM Virtualization |