Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #179923 > unrolled thread

if you have no swap in your installation this is what you do??? Why???

Started byGiaThnYgeia <GiaThnYgeia@openmailbox.org>
First post2017-04-09 17:00 +0200
Last post2017-04-09 19:00 +0200
Articles 4 — 4 participants

Back to article view | Back to linux.debian.user


Contents

  if you have no swap in your installation this is what you do???  Why??? GiaThnYgeia <GiaThnYgeia@openmailbox.org> - 2017-04-09 17:00 +0200
    Re: if you have no swap in your installation this is what you  do??? Why??? Andy Smith <andy@strugglers.net> - 2017-04-09 18:20 +0200
    Re: if you have no swap in your installation this is what you do???  Why??? Darac Marjal <mailinglist@darac.org.uk> - 2017-04-09 18:20 +0200
      Re: if you have no swap in your installation this is what you do??? Why??? Sven Hartge <sven@svenhartge.de> - 2017-04-09 19:00 +0200

#179923 — if you have no swap in your installation this is what you do??? Why???

FromGiaThnYgeia <GiaThnYgeia@openmailbox.org>
Date2017-04-09 17:00 +0200
Subjectif you have no swap in your installation this is what you do??? Why???
Message-ID<tumtQ-490-9@gated-at.bofh.it>
A while ago while Thomas Schmitt was helping me with dd and xorriso in
backing up systems and partitions into usb and back the issue of not
having a swap partition in my system came up, since I chose not to
during the installation, and how to create one, lead me into a search of
doing just that.

In the page
https://askubuntu.com/questions/33697/how-do-i-add-a-swap-partition-after-system-installation
there are instructions that I believe work just as well on Debian to
either create a new partition for swap or create a swap file, which I
did not know it was an option.
I chose the second as my partitioning has become complex and most of the
drive is not available during boot-up.  So I assume it would run to an
error if I did this on a partition that is not available during boot.

Below you will find the exact instructions I used and worked fine for me
on Stretch (I believe to be true for all Debian).

But here come some questions:
1	What is the difference functionally of having a swap partition from
having a swap file?  Is it that you can use a separate physical disk
that will take the wear and tear of swaping?
2	Is swap size relevant to ram, should it be equal, greater, smaller?
Advantages disadvantages?  I rarely see in a workstation and my/our use
anywhere close to 4GB being used, it usually maxes out around 2,5GB. No,
no killing games here, maybe some chess and gnubg. Is it that a Ram of
1GB would benefit from 2-4GB swap space while with 16GB or Ram swap
would never be used?

3	chmod 600 for the swapfile.  Why?
4	Is "dd bs=1M count=4M" that defines the 4,000Mb of space/size of the file?

I am now going to use gnubg to test my mem capabilities.  I think making
it calculate best move 4-5 moves ahead in bg or chess will stress the
system out :)

_______________________________________________________

#    Create an empty file (1K * 4M = 4 GiB)
    sudo mkdir -v /var/cache/swap
    cd /var/cache/swap
    sudo dd if=/dev/zero of=swapfile bs=1K count=4M
    sudo chmod 600 swapfile

#    Convert newly created file into a swap space file.
    sudo mkswap swapfile

#    Enable file for paging and swapping.
    sudo swapon swapfile

#    Verify by: swapon -s or top:
top -bn1 | grep -i swap
#    KiB Swap:  4194300 total,  4194300 free

#    To disable, use
sudo swapoff swapfile.

#    Add it into fstab file to make it persistent on the next system
#    boot.
echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a
   /etc/fstab

#    Re-test swap file on startup by:
    sudo swapoff swapfile
    sudo swapon -va
_____________________________________________________________



-- 
 "The most violent element in society is ignorance" rEG

[toc] | [next] | [standalone]


#179928 — Re: if you have no swap in your installation this is what you do??? Why???

FromAndy Smith <andy@strugglers.net>
Date2017-04-09 18:20 +0200
SubjectRe: if you have no swap in your installation this is what you do??? Why???
Message-ID<tunJg-5bL-23@gated-at.bofh.it>
In reply to#179923
Hi,

On Sun, Apr 09, 2017 at 02:58:00PM +0000, GiaThnYgeia wrote:
> 1	What is the difference functionally of having a swap partition from
> having a swap file?  Is it that you can use a separate physical disk
> that will take the wear and tear of swaping?

As long as the filesystem can support swapfiles then there is no
difference in functionality. You can put swap on a block device that
is from a separate physical device to the rest of your storage, or
in a swap  file on a filesystem that is on a separate physical
device to the rest of your storage, so that isn't a distinguishing
feature. It's just down to whatever is most convenient for you.

> 2	Is swap size relevant to ram, should it be equal, greater, smaller?
> Advantages disadvantages?  I rarely see in a workstation and my/our use
> anywhere close to 4GB being used, it usually maxes out around 2,5GB. No,
> no killing games here, maybe some chess and gnubg. Is it that a Ram of
> 1GB would benefit from 2-4GB swap space while with 16GB or Ram swap
> would never be used?

Opinions differ. More than 1GiB to me seems excessive regardless of
how much RAM you have. If you have 1GiB of data swapped out and you
need it again, it's going to take a really long time, which will
equate to dire performance. You'd be better off getting more memory
in that case.

Here is some useful discussion on the matter:

http://unix.stackexchange.com/a/190521

> 3	chmod 600 for the swapfile.  Why?

So that only the root user may read/write it. Swapped-out data can
contain sensitive information.

> 4	Is "dd bs=1M count=4M" that defines the 4,000Mb of space/size of the file?

That is units of 1024*1024 bytes, 4*1024*1024 times. Or
4*1024*1024*1024*1024 bytes. Or 4TiB. I'm guessing from below that
you meant bs=1K, in which case yes, that's 4GiB. This is all quicker
to test than to ask about though. :)

Cheers,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting

[toc] | [prev] | [next] | [standalone]


#179929

FromDarac Marjal <mailinglist@darac.org.uk>
Date2017-04-09 18:20 +0200
Message-ID<tunJg-5bL-25@gated-at.bofh.it>
In reply to#179923

[Multipart message — attachments visible in raw view] — view raw

On 09/04/17 15:58, GiaThnYgeia wrote:
> A while ago while Thomas Schmitt was helping me with dd and xorriso in
> backing up systems and partitions into usb and back the issue of not
> having a swap partition in my system came up, since I chose not to
> during the installation, and how to create one, lead me into a search of
> doing just that.
>
> In the page
> https://askubuntu.com/questions/33697/how-do-i-add-a-swap-partition-after-system-installation
> there are instructions that I believe work just as well on Debian to
> either create a new partition for swap or create a swap file, which I
> did not know it was an option.
> I chose the second as my partitioning has become complex and most of the
> drive is not available during boot-up.  So I assume it would run to an
> error if I did this on a partition that is not available during boot.
>
> Below you will find the exact instructions I used and worked fine for me
> on Stretch (I believe to be true for all Debian).
>
> But here come some questions:
> 1	What is the difference functionally of having a swap partition from
> having a swap file?  Is it that you can use a separate physical disk
> that will take the wear and tear of swaping?

A swap partition is not subject to the controls of a file system. That
is, it can't get fragmented, it can be positioned at the fast (or slow)
end of a disk, it can be (as you suggest) placed on a completely
separate device. It can be shared between dual-booting Linux systems.

A swap file does not take up potentially precious space on the partition
table (for example, you can only have 4 primary partitions).

> 2	Is swap size relevant to ram, should it be equal, greater, smaller?
> Advantages disadvantages?  I rarely see in a workstation and my/our use
> anywhere close to 4GB being used, it usually maxes out around 2,5GB. No,
> no killing games here, maybe some chess and gnubg. Is it that a Ram of
> 1GB would benefit from 2-4GB swap space while with 16GB or Ram swap
> would never be used?

If you want to use suspend-to-disk hibernation, it should be at least
equal to RAM (suspend-to-disk DOES use compression, but if you have a
lot in RAM and a lot in swap and it doesn't compress well, equal-to-RAM
tends to be the sweet spot).

Otherwise, the old rule used to be 1.5×RAM. Again, equal to RAM should
be plenty if you have 4GB. Swap allows the kernel to move
infrequently-used pages out to disk and prioritise the fast RAM for
frequently-used pages. So, even if you have 16GB of RAM, the kernel can
use that for the more important stuff (disk caches for example).

>
> 3	chmod 600 for the swapfile.  Why?

600 means that the owner of the file can read and write to the file, but
no-one else can (rw-------). This improves the security of the file.

> 4	Is "dd bs=1M count=4M" that defines the 4,000Mb of space/size of the file?

No, that would be 4,000,000Mb. "bs=" indicates the "block size" that dd
should write and "count=" indicates the number of /those blocks/ to be
written. So you're asking for four million megabytes. For 4,000Mb, you'd
be best with "dd bs=1M count=4000".

>
> I am now going to use gnubg to test my mem capabilities.  I think making
> it calculate best move 4-5 moves ahead in bg or chess will stress the
> system out :)
>
> _______________________________________________________
>
> #    Create an empty file (1K * 4M = 4 GiB)
>     sudo mkdir -v /var/cache/swap
>     cd /var/cache/swap
>     sudo dd if=/dev/zero of=swapfile bs=1K count=4M
>     sudo chmod 600 swapfile
>
> #    Convert newly created file into a swap space file.
>     sudo mkswap swapfile
>
> #    Enable file for paging and swapping.
>     sudo swapon swapfile
>
> #    Verify by: swapon -s or top:
> top -bn1 | grep -i swap
> #    KiB Swap:  4194300 total,  4194300 free
>
> #    To disable, use
> sudo swapoff swapfile.
>
> #    Add it into fstab file to make it persistent on the next system
> #    boot.
> echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a
>    /etc/fstab
>
> #    Re-test swap file on startup by:
>     sudo swapoff swapfile
>     sudo swapon -va
> _____________________________________________________________
>
>
>

[toc] | [prev] | [next] | [standalone]


#179931 — Re: if you have no swap in your installation this is what you do??? Why???

FromSven Hartge <sven@svenhartge.de>
Date2017-04-09 19:00 +0200
SubjectRe: if you have no swap in your installation this is what you do??? Why???
Message-ID<tuolY-5r2-13@gated-at.bofh.it>
In reply to#179929
Darac Marjal <mailinglist@darac.org.uk> wrote:

> A swap partition is not subject to the controls of a file system. That
> is, it can't get fragmented, it can be positioned at the fast (or slow)
> end of a disk, it can be (as you suggest) placed on a completely
> separate device. It can be shared between dual-booting Linux systems.

A swap file does not get fragmented either, since it has to be allocated
completely before use. Also the myth that a swap file is slower compared
to a partition is not true since at least Linux 2.3.

And the placement of the swap is of just theoretical nature. The speed
of swap is like comparing the movement speed of a glacier with that of
the speed of sound to star with. Even if a swap space in the other
portion of a HDD is 1.5 times faster than a swap space in the inner one,
it still is abysmally slower than RAM. So in the end really does not
matter where you place your swap on your HDD.

Placing swap on an SSD helps, but if your system starts to heavily swap
pages out, you are trashed anyways.

S°

-- 
Sigmentation fault. Core dumped.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web