Compare commits

...

2 Commits

Author SHA1 Message Date
BBaoVanC 86c4b1ea18
a 2023-04-03 14:35:49 -05:00
BBaoVanC 3be325b34d
Merge the other swapfile post into References section 2023-04-03 12:42:35 -05:00
2 changed files with 26 additions and 62 deletions

View File

@ -1,53 +0,0 @@
---
title: Swapfile guide explained
date: 2023-01-23T20:26:18-06:00
lastmod: 2023-01-23T20:26:18-06:00
toc: true
comments: true
draft: true
authors:
- bbaovanc
categories:
- linux
tags:
- linux-swap
- swapfile
series:
- swapfile-guide
# this will be shown for the article in list pages and in the page metadata
# it can be either an image or video (this might change in the future, however)
resources:
- name: feature
src: something.webp
title: Some image (image format can be anything; webp is just an example)
---
This page is about something. All the content before the "more" HTML comment
below will become the summary, which will be used in list pages and in the meta
tags on the article.
Or, if you don't want your description to be at the top of the article, you can
set your own `description` in the front matter and it will override this. See
the [Content Summaries](https://gohugo.io/content-management/summaries/) page on
the Hugo docs for more information.
<!--more-->
## Allocating the file
- use `dd` instead of `fallocate`
- https://man7.org/linux/man-pages/man8/swapon.8.html#NOTES
- https://man.archlinux.org/man/core/util-linux/swapon.8.en#Files_with_holes
## Options field
- https://unix.stackexchange.com/a/365961/525130
- https://unix.stackexchange.com/a/365954/525130
- https://github.com/util-linux/util-linux/blob/2ea397239683270a0fc8cd3b72ed5457f52dbda8/sys-utils/swapon.c#L699

View File

@ -32,16 +32,17 @@ resources:
---
This is a step-by-step tutorial on how to create or remove a swapfile on a Linux
machine. Also included is the correct `fstab` entry (most articles get this
"wrong", though it doesn't really make a difference) and reasons to use
swap(file) in the first place.
machine, and whether you should create swap space in the first place.
Also included is the most correct `fstab` entry: most articles get this "wrong"
(but it doesn't actually matter).
<!--more-->
## Should you use swap?
A common misconception is that adding swap to your system can reduce
performance. In reality, even if you aren't running out of RAM, it can still be
performance. However, even if you aren't running out of RAM, it can still be
beneficial to add swap.
See these points according to [an article by Hayden James][always-add-swap]:
@ -59,12 +60,12 @@ See these points according to [an article by Hayden James][always-add-swap]:
[always-add-swap]: https://haydenjames.io/linux-performance-almost-always-add-swap-space/
### Should you use a swapfile?
### Should you use a swap file or partition?
Swap partitions should be preferred because swapfiles tend to be slower and more
complex, especially if hibernating. A swapfile might be preferred due to its
flexibility (easy to resize), but if you use [LVM][lvm-archwiki] then you can
easily resize the swap partition anyways.
Swap partitions should be preferred because swapfiles tend to be slower and
slightly more complex to set up, especially if hibernating. A swapfile might be
preferred due to its flexibility (ease to resize), but if you use
[LVM][lvm-archwiki] then you can easily resize the swap partition anyways.
[lvm-archwiki]: https://wiki.archlinux.org/title/LVM
@ -251,3 +252,19 @@ want to remove, and delete it. For example:
```bashsession
# rm /swapfile
```
## References
### Use `dd` instead of `fallocate`
See ["Files with holes" under the man page][swapon-holes-man].
[swapon-holes-man]: https://man.archlinux.org/man/core/util-linux/swapon.8.en#Files_with_holes
### The options field in fstab
On Linux, `sw` doesn't mean anything for `swapon`, so it gets ignored. See:
- [StackExchange answer 1](https://unix.stackexchange.com/a/365961/525130)
- [StackExchange answer 2](https://unix.stackexchange.com/a/365954/525130)
- [`parse_options` in the `swapon` source code](https://github.com/util-linux/util-linux/blob/2ea397239683270a0fc8cd3b72ed5457f52dbda8/sys-utils/swapon.c#L699)