Giter Site home page Giter Site logo

add a guide to swap about docs HOT 15 CLOSED

coreos avatar coreos commented on September 27, 2024 1
add a guide to swap

from docs.

Comments (15)

coderfi avatar coderfi commented on September 27, 2024 1

FYI, to disable COW, I followed the instructions from: https://wiki.archlinux.org/index.php/Btrfs

So this is what I did:

sudo fallocate -l 2048m /2GiB.swap
sudo chmod 600 /2GiB.swap
sudo chattr +C /2GiB.swap
sudo mkswap /2GiB.swap
# ... added the swap.service unit to /var/lib/coreos-install/user_data ...
sudo reboot

After the reboot, I took a look at top and saw the swap active and used

    Swap:  2097148k total,    10144k used,  2087004k free,   245512k cached

Not sure if COW was actually disabled, nor do I know the actual performance gain.

Here is the units snippet in my user_data file (per the above comments):

units:
    - name: swap.service
      command: start
      content: |
        [Unit]
        Description=Turn on swap

        [Service]
        Type=oneshot
        Environment="SWAPFILE=/2GiB.swap"
        RemainAfterExit=true
        ExecStartPre=/usr/sbin/losetup -f ${SWAPFILE}
        ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
        ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
        ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"

        [Install]
        WantedBy=local.target

Hope this helps.

  • Fi

from docs.

ClashTheBunny avatar ClashTheBunny commented on September 27, 2024

This no longer works due to btrfs not being compatible with swap files. To make it work, I had to adjust the directions so that I created the file somewhere on btrfs (/4GiB.swap) and then used this unit file:

[Unit]
Description=Turn on swap

[Service]
Type=oneshot
Environment="SWAPFILE=/4GiB.swap"
RemainAfterExit=true
ExecStartPre=/usr/sbin/losetup -f ${SWAPFILE}
ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"

[Install]
WantedBy=local.target

It's important to have the "RemainAfterExit" or else the Stop stanzas will be executed immediately.

They say that btrfs performs poorly in this situation, but if it's all you got...

from docs.

marineam avatar marineam commented on September 27, 2024

Should work a little better if you disable COW for the swap file when you create it.

from docs.

marineam avatar marineam commented on September 27, 2024

You may need to disable cow before using fallocate, you can only disable
cow on zero length files and off the top of my head I don't know if
fallocate counts towards that restriction or not.
On Aug 5, 2014 3:22 AM, "coderfi" [email protected] wrote:

FYI, to disable COW, I followed the instructions from:
https://wiki.archlinux.org/index.php/Btrfs

So this is what I did:

  • sudo fallocate -l 2048m /2GiB.swap
  • sudo chmod 600 /2GiB.swap
  • sudo chattr +C /2GiB.swap
  • sudo mkswap /2GiB.swap
  • added the swap.service unit to /var/lib/coreos-install/user_data
  • sudo reboot
  • took a look at top and saw the swap active and used Swap: 2097148k
    total, 10144k used, 2087004k free, 245512k cached

Not sure if COW was actually disabled, nor do I know the actual
performance gain.

Here is the units snippet in my user_data file (per the above comments):

units:

  • name: swap.service
    command: start
    content: |
    [Unit]
    Description=Turn on swap

    [Service]
    Type=oneshot
    Environment="SWAPFILE=/2GiB.swap"
    RemainAfterExit=true
    ExecStartPre=/usr/sbin/losetup -f ${SWAPFILE}
    ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
    ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
    ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"

    [Install]
    WantedBy=local.target


Reply to this email directly or view it on GitHub
#52 (comment).

from docs.

cboettig avatar cboettig commented on September 27, 2024

Thanks for this, worked like a charm for me. Is it possible to have the commands sudo fallocate... also specified in the cloud-config file instead of having to issue these manually? I see there is no runcmd in a coreos cloud-config file...

from docs.

romaninsh avatar romaninsh commented on September 27, 2024

@cboettig Here, I used the following service, which also executes fallocate: https://gist.github.com/romaninsh/118952ce61643914fb00

from docs.

joshperry avatar joshperry commented on September 27, 2024

Why not support the canonical swap configuration? http://cloudinit.readthedocs.org/en/latest/topics/examples.html#adjust-mount-points-mounted

Using this: https://gist.github.com/tsertkov/573d077012ae76443cbf but 50 lines of config just for a swapfile seems excessive.

from docs.

crawford avatar crawford commented on September 27, 2024

Related coreos/bugs#429 (comment).

from docs.

joelchen avatar joelchen commented on September 27, 2024

Are minimum of round(sqrt(RAM)) and maximum of twice the amount of RAM from https://help.ubuntu.com/community/SwapFaq recommendations we should follow on CoreOS?

from docs.

crawford avatar crawford commented on September 27, 2024

@joelchen most CoreOS instances don't use swap at all, so the minimum is zero. Canonical's recommended upper bound seems reasonable.

from docs.

joelchen avatar joelchen commented on September 27, 2024

@crawford What are the recommended use cases for no swap, as well as for using swap in CoreOS?

from docs.

crawford avatar crawford commented on September 27, 2024

@joelchen it depends heavily on how you plan on using the machine and the physical characteristics of the machine. I would suggest taking a look at what Linux recommends and then going with that.

from docs.

HaleTom avatar HaleTom commented on September 27, 2024

Do not try what @coderfi suggested, namely, disabling CoW to try to use a swapfile with btrfs, until you read that it is supported in the official documentation.

swap file support relies on one function that btrfs intentionally does not implement due to potential corruptions.

However:

A workaround, albeit with poor performance, is to mount a swap file via a loop device.

from docs.

philips avatar philips commented on September 27, 2024

Someone just mentioned losteup leads to lockups https://groups.google.com/d/msg/coreos-user/xw4aeC68k6Q/vy8Iv0jWCAAJ. Can someone please write this guide? It is clearly tripping up a lot of users on something very simple. cc @ElijahCaine

from docs.

pop avatar pop commented on September 27, 2024

@philips I'm writing and testing a doc now. PR should be up by the end of the day.

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.