Swap Space Management

Swap Space Management

Revision for “Swap Space Management” created on May 1, 2023 @ 18:30:52

Title
Swap Space Management
Content
<h1>Swap Space</h1> <strong>Swap space</strong> is a special area for the OS that can be used as additional system <em><strong>random access memory </strong></em>(RAM). The traditional approach to <strong>swap space</strong> used a <strong>swap partition</strong> on your drive system. A modern approach, as used by Bodhi Linux [library term="version"] (based upon Ubuntu [library term="ubuntu-version"]), is the use of a <strong>swap file</strong>. <em>Tip: see <a href="https://www.bodhilinux.com/w/swap-space-management/#Enabling_Zswap">Enabling Zswap</a> for more information on (potentially) speeding up older machines</em> <h2>Swap File</h2> One advantage of a <strong>swap file</strong> (over a <strong>swap partition</strong>), is easier <em>resizing</em>. Below are details of <em>managing</em> the <strong>swap file</strong> using <a href="https://www.bodhilinux.com/w/terminology/">Terminology</a>. <h2>Check Swap Status</h2> <em>Check</em> that your Bodhi Linux installation already has swap <em>enabled</em>: <pre>sudo swapon --show</pre> which should <em>output</em> something like: <pre>NAME TYPE SIZE USED PRIO /dev/sda1 partition 1.0G 0B -2</pre> <h2>Create</h2> If a <strong>swap file</strong> does not exist, <em>create</em> a file which will be used for swap. In this example, a 1GB file will be created name <strong>swapfile</strong>. <p style="padding-left: 30px;"><em>Note: GB: Gigabyte; MB: Megabyte</em></p> <pre>sudo fallocate -l 1G /swapfile</pre> <em>Set</em> the correct permissions for the file: <pre>sudo chmod 600 /swapfile</pre> Now <em>make</em> a swap area within the file and <em>enable</em>: <pre>sudo mkswap /swapfile sudo swapon /swapfile</pre> To make the changes persistent, make an entry into <strong>fstab</strong> (if it is not already there) using your preferred editor (<a href="https://www.bodhilinux.com/a/leafpad/">Leafpad</a>, <strong>Nano</strong>, <strong>Vim</strong>). <p style="padding-left: 30px;"><em>***CAUTION***: extreme care should be taken when modifying <strong>fstab</strong>! An incorrectly stated <strong>fstab</strong> will result in a failure to boot Bodhi Linux.</em></p> <em>Add</em> the following change to <code>/etc/fstab</code> <pre>/swapfile none swap sw 0 0</pre> <em>Verify</em> the swap was <em>created</em> and <em>usable</em> (<em>see</em>: <a href="https://www.bodhilinux.com/w/swap-space-management/#Check_Swap_Status">Check Swap Status</a> above). <h2>Resize</h2> We are effectively <em>deleting</em> the swap file, and <em>recreating</em> the file. <em>Follow</em> <a href="#Remove">Remove</a> (below), omitting the change to <code>/etc/fstab</code> <em>Follow</em> <a href="#Create">Create</a> (above), omitting the change to <code>/etc/fstab</code> <em>Verify</em> the swap was <em>created</em> and <em>usable</em> (<em>see</em>: <a href="https://www.bodhilinux.com/w/swap-space-management/#Check_Swap_Status">Check Swap Status</a> above). <h2>Remove</h2> <em>Delete</em> the swap <pre>sudo swapoff -v /swapfile</pre> <em>Delete</em> the swap file <code> rm -v /swapfile</code> <em>Remove</em> the line <code>/swapfile none swap sw 0 0</code> (using your preferred editor) from the file: <code>/etc/fstab</code> Be sure to <em>save</em> changes. <h1>Swappiness</h1> For most users doing general computing, you will not need to adjust <strong>Swappiness</strong>. <strong>Bodhi Linux</strong> has a default of &lt;code&gt;swappiness=60&lt;/code&gt;. Advanced users are likely aware and now you are too - this is a highly debated topic which is outside of beginner's guide. For a good discussion check out https://askubuntu.com/questions/103915/how-do-i-configure-swappiness. There are lots of <strong>hardware</strong>, <strong>run-time</strong> and <strong>user</strong> variables that will determine your results - explore what works for your system if you are curious! <h1>Enabling Zswap</h1> Our Forum Crew Member, <a href="https://bodhilinux.boards.net/user/20">@kiezel</a>, has a link to his project <a href="https://easylinuxtipsproject.blogspot.com/p/1.html"><em>Easy Linux Tips Project</em></a> that walks a user through <a href="http://redirect.viglink.com/?key=71fe2139a887ad501313cd8cce3053c5&amp;subId=7156301&amp;u=https%3A//easylinuxtipsproject.blogspot.com/p/speed-mint.html%23ID1.2">enabling zswap</a>. - "This should create a noticeable speed boost, especially on older machines." Note: in the how-to, replace: <code>xed admin://</code> with <code>pkexec leafpad</code>. So for <em><code><i>xed admin:///etc/default/grub</i></code> </em> use: <pre>pkexec leafpad /etc/default/grub</pre> <h2>One potential issue:</h2> <code>lz4 not available</code> You definitely want lz4 compression, because that's simply better than the default lzo compression. In Bodhi Linux, the module for the lz4 feature isn't included in the <code>initramfs</code> at boot time. So let's change that: <pre>pkexec leafpad /etc/initramfs-tools/modules</pre> In that text file, create a new bottom line with lz4 in it, so that it becomes: <pre># List of modules that you want to include in your initramfs. # They will be loaded at boot time in the order below. # # Syntax: module_name [args ...] # # You must run update-initramfs(8) to effect this change. # # Examples: # # raid1 # sd_mod lz4</pre> Save the changes and close the text editor. Then in the terminal: <pre>sudo update-initramfs -u</pre> Reboot. After the reboot, test again by running: <pre>dmesg | grep zswap</pre> <a href="https://www.bodhilinux.com/">Bodhi Linux Home</a> <a href="https://www.bodhilinux.com/w/wiki/">Bodhi Linux – Wiki Home Page</a> <a href="https://www.bodhilinux.com/w/bodhi-linux-how-to/">Bodhi Linux – Wiki Table of Contents</a>
Excerpt


OldNewDate CreatedAuthorActions
May 1, 2023 @ 18:30:52 oblio
January 18, 2022 @ 22:47:12 oblio
January 18, 2022 @ 02:42:16 oblio
January 18, 2022 @ 02:41:31 [Autosave] oblio
January 18, 2022 @ 02:37:48 oblio
January 18, 2022 @ 02:34:07 oblio
November 23, 2021 @ 15:59:51 oblio
November 21, 2021 @ 03:15:22 oblio
November 21, 2021 @ 03:10:01 oblio
November 21, 2021 @ 03:05:55 oblio
November 21, 2021 @ 03:04:27 oblio
November 21, 2021 @ 03:00:47 oblio
November 21, 2021 @ 02:43:04 oblio
November 19, 2021 @ 04:44:15 oblio
November 19, 2021 @ 04:43:10 oblio
November 19, 2021 @ 04:42:00 oblio
November 19, 2021 @ 04:40:33 oblio
November 19, 2021 @ 04:35:51 oblio
November 19, 2021 @ 04:17:10 oblio
November 19, 2021 @ 04:16:25 oblio
November 19, 2021 @ 04:14:41 oblio
November 19, 2021 @ 04:09:32 oblio
November 19, 2021 @ 04:01:28 oblio
November 19, 2021 @ 03:59:10 oblio
November 19, 2021 @ 03:57:27 oblio
November 19, 2021 @ 03:52:03 oblio
November 19, 2021 @ 03:30:41 oblio
November 19, 2021 @ 03:27:36 oblio
November 18, 2021 @ 05:26:26 oblio
November 25, 2020 @ 17:40:22 FidoeDidoe
November 25, 2020 @ 17:40:06 FidoeDidoe
November 18, 2020 @ 16:01:47 FidoeDidoe
November 18, 2020 @ 16:01:07 [Autosave] FidoeDidoe
November 18, 2020 @ 15:47:09 FidoeDidoe
November 18, 2020 @ 15:45:53 FidoeDidoe
November 18, 2020 @ 15:32:51 FidoeDidoe