This repository has been archived on 2022-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
blog.old/output/swap-on-ssd-done-right.html

185 lines
9.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Swap on SSD done right</title>
<link rel="stylesheet" href="https://murtezayesil.me/theme/css/main.css" />
<link rel="stylesheet" href="https://murtezayesil.me/theme/css/tooltip.css" />
<link href="https://murtezayesil.me/feeds/atom.xml" type="application/atom+xml" rel="alternate" title="Ali Murteza Yesil Atom Feed" />
<link href="https://murtezayesil.me/feeds/rss.xml" type="application/rss+xml" rel="alternate" title="Ali Murteza Yesil RSS Feed" />
<!-- This border added via BLACK_LIVES_MATTER toggle in site settings -->
<style>
body {
border-width: 5em ;
border-color: #000000 ;
border-style: none solid solid solid ; /* top border : none, right bottom left : solid */
}
</style>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="index" class="home">
<!-- This banner added via BLACK_LIVES_MATTER toggle in site settings -->
<div style="background-color: black; padding: 1em; margin-bottom: .8em">
<h1 style="text-align: center; margin-bottom: 0em"><a href="https://blacklivesmatter.com/" style="color: #fce21b; font-size: 2em">Black Lives Matter</a></h1>
</div>
<header id="banner" class="body">
<h1><a href="https://murtezayesil.me/">Ali Murteza Yesil <strong>Blog</strong></a></h1>
<nav><ul>
<li><a href="https://murtezayesil.me/pages/about.html">About</a></li>
<li><a href="https://murtezayesil.me/pages/contact.html">Contact</a></li>
</ul>
<form id="search" action"#" onsubmit="javascript:window.open('https://duckduckgo.com/?q='+document.getElementById('keywords').value+'+site:https://murtezayesil.me');">
<input id="keywords" type="text" />
</form>
</nav>
<div id="submenu">
<ul>
<li><a href="https://murtezayesil.me/category/draft.html">draft</a></li>
<li><a href="https://murtezayesil.me/category/notes.html">Notes</a></li>
<li><a href="https://murtezayesil.me/category/personal.html">Personal</a></li>
<li class="active"><a href="https://murtezayesil.me/category/tech.html">Tech</a></li>
</ul>
<div>
</header><!-- /#banner -->
<section id="content" class="body">
<article>
<header>
<h1 class="entry-title">
<a href="https://murtezayesil.me/swap-on-ssd-done-right.html" rel="bookmark"
title="Permalink to Swap on SSD done right">Swap on SSD done right</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<span>Sat 01 August 2020</span>
<span>| in <a href="https://murtezayesil.me/category/tech.html">Tech</a></span>
<span>| tags: <a href="https://murtezayesil.me/tag/100daystooffload.html">100DaysToOffload</a></span> <span>| Day <strong>12</strong> of #100DaysToOffload</span>
</footer><!-- /.post-info --> <p>TL;DR : If you have SSD and need swap, you should use swapspace daemon for healthier SSD. Btw, you want SSD and you need swap.</p>
<p>Note: I expect you to be familiar with <a href="https://en.wikipedia.org/wiki/Random-access_memory">RAM</a>, <a href="https://en.wikipedia.org/wiki/Paging#Unix_and_Unix-like_systems">swap</a> and concept of <a href="https://en.wikipedia.org/wiki/Paging">paging</a>.</p>
<p>Here is the short edition:<br>
<strong>RAM</strong> is fast memory for currently running programs.<br>
<strong>Swap</strong> is kinda like backup RAM. In case of RAM is filling up, swap will be uyilized to move less often accessed data off the RAM.<br>
<strong>Paging</strong> is moving data between RAM and swap memory. It occurs when RAM is close to full and needs emptying into the swap or when a data in swap is needed in RAM.</p>
<p>Since swap is located on HDD or SSD, it is much slower than RAM and we want to utilize RAM as much as we can. But sometimes RAM fills up and computer runs into <a href="https://en.wikipedia.org/wiki/Out_of_memory" title="Out Of Memory"><strong>OOM</strong></a> state. Even though it is slow, swap can be a life (or work) saver in such cases. </p>
<h3>Estimated Memory Speeds</h3>
<table>
<thead>
<tr>
<th>Device Type</th>
<th>Speed (MB/s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>HDD</td>
<td>100</td>
</tr>
<tr>
<td>SSD - SATA</td>
<td>560</td>
</tr>
<tr>
<td>SSD - NVMe</td>
<td>2000-3000</td>
</tr>
<tr>
<td>RAM DDR2</td>
<td>3000-8000</td>
</tr>
<tr>
<td>RAM DDR3</td>
<td>8000-12000</td>
</tr>
<tr>
<td>RAM DDR4</td>
<td>19000-35000</td>
</tr>
</tbody>
</table>
<p>Data of RAM speeds is from <a href="https://www.crucial.com/support/memory-speeds-compatability">this article of Crucial</a>. HDD and SSD speeds are commonly observed speeds. Not from the Crucial's testing.</p>
<p>You definitely want swap memory to avoid possible OOM issue. You also may want to use SSD for swap memory since it is much faster than HDD or your computer only has SSD. But SSDs have one weak spot. Storage blocks of the SSD that is being read and wrote 100s of times will fail. Thankfully SSDs got smarter. Instead of using a single block too often and causing it to die early, SSDs tend to utilize every block equally. This is called Garbage Collection. And together with <a href="https://www.invidio.us/watch?v=Q15wN8JC2L4" title="Techquickie video on overprovisioning">overprovisioning</a>, they increase longevity of the SSD.</p>
<p>I don't think fixed swap partitions and files are good for SSD's health. We need a system to dynamically allocate swap. So that swap file will be erased when notneeded and created in lesser degraded blocks when needed.</p>
<h1>Meet Swapspace</h1>
<p><a href="http://manpages.org/swapspace/8" title="read manpage">Swapspace</a> is a background service that understands swap needs and either creates or removes swap files on the fly.</p>
<p>Swapspace is available on many <em>local repos</em>, <em>AUR</em> and on <a href="https://github.com/Tookmund/Swapspace"><em>GitHub</em></a>. </p>
<hr>
<p><strong>Note</strong>: How aggressively the Kernel should use swap memory can be controlled via a value called swappiness. Read about <a href="https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/">changing swappiness</a> for better RAM utilization.</p>
</div><!-- /.entry-content -->
<!-- #100DaysToOffload message -->
<p>Day <strong>12</strong> of <a href="https://100daystooffload.com/" title="click to read about the challenge">#100DaysToOffload</a></p>
<!-- Comments -->
<hr>
<h2>Comments</h2>
<p>Toot on <a href="https://fosstodon.org/@murtezayesil/104613505063011977">this thread</a> to comment. This blog is a static site. Comments won't appear here.</p>
</article>
</section>
<section id="extras" class="body">
<div class="blogroll">
<h2>blogroll</h2>
<ul>
<li><a href="https://kevq.uk">Kev Quirk</a></li>
<li><a href="https://mikestone.me">Mike Stone</a></li>
<li><a href="https://yarmo.eu/">Yarmo Mackenbach</a></li>
</ul>
</div><!-- /.blogroll -->
<div class="social">
<h2>social</h2>
<ul>
<li><a href="https://murtezayesil.me/feeds/atom.xml" type="application/atom+xml" rel="alternate">atom feed</a></li>
<li><a href="https://murtezayesil.me/feeds/rss.xml" type="application/rss+xml" rel="alternate">rss feed</a></li>
<li><a href="https://fosstodon.org/@murtezayesil" rel="me">Fostodon</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<p>Powered by <a href="http://getpelican.com/">Pelican</a>. Theme <a href="https://github.com/blueicefield/pelican-blueidea/">blueidea</a>, inspired by the default theme.</p>
</footer><!-- /#contentinfo -->
<!-- IndieWeb Profile -->
<!-- ToDo : Make IndieWeb Profile auto generating according to site preferences -->
<!-- This profile is created by following https://kevq.uk/how-to-create-an-indieweb-profile/ blog post. Thanks to Kev Quirk -->
<section style="display: none;" class="h-card">
<!-- About me -->
<span class="p-name">Ali Murteza Yesil</span>
<span class="p-note">I'm a student, privacy advocate and SysAdmin wannabe. I was born in Turkey but I live abroad.</span>
<!-- Profile picture -->
<img class="u-photo" src="https://murtezayesil.me/images/avatar_polygon_128x128.png"/>
<!-- My location -->
<!-- <span class="p-locality">City, Country or Country</span> -->
<!-- Links -->
<a class="u-url u-uid" href="https://murtezayesil.me"></a>
<!-- Mail Template <a class="u-email" rel="me" href="mailto:USERNAME@SERVICEPROVIDER"></a> -->
<a class="u-url" rel="me" href="https://fosstodon.org/@murtezayesil"></a>
<!-- Twitter Example <a class="u-url" rel="me" href="https://twitter.com/USERNAME"></a> -->
<!-- Template <a class="u-url" rel="me" href="https://URL"></a> -->
<!-- Categories -->
<span class="p-category">Blogging</span>
<span class="p-category">Open Source Software</span>
<span class="p-category">Privacy</span>
</section>
</body>
</html>