Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    swapon -a and swapoff -a

    Scheduled Pinned Locked Moved General pfSense Questions
    swap
    4 Posts 4 Posters 264 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonathanLeeJ
      JonathanLee
      last edited by

      Hello fellow Netgate Community members,

      I just noticed that if the swap is accessed for example during a Snort IPS/IDS update and bogon update with ClamAV updates once the system normalizes and no longer needs swap it does not automatically turn off it sits with a small amount of use having the user manually running swapoff -a and swapon -a

      I created a cron job to turn it off and on after updates. I was under the impression that it would automatically turn off swap once it was not needed, example being my ran use went back down to 23% so disable swap use but it does not do that it sits at 23% swap and like .5% swap use until I run those commands.

      Shouldn't the system automatically normalize swap after it is not needed anymore?

      Make sure to upvote

      1 Reply Last reply Reply Quote 0
      • stephenw10S
        stephenw10 Netgate Administrator
        last edited by

        No it doesn't disable swap and only enable it when needed. It's either enabled or disabled. I think what you're looking for is to free the used SWAP after some time. That's not something I've looked into but might be possible. That should all be automatic though if the swap is used older swapped data would be freed.
        However I'd argue that using SWAP at all is a bad idea and usually a sign that something is misconfigured.

        1 Reply Last reply Reply Quote 0
        • K
          kprovost
          last edited by

          You don't actually want that swap space to be freed. If it's not being freed "by itself" that means no process tried to access that memory, which would cause it to be paged back in.
          That is, that data isn't used, so there's no point at all in having it back in memory.

          Of course, Steve is also right that you really don't want to be enabling swap in the first place.

          1 Reply Last reply Reply Quote 1
          • GertjanG
            Gertjan
            last edited by

            Add to what is said above,
            The "swap off" will disable swap usage, see it as a flag information to the kernel.
            Not like "Windows", FreeBSD (the nix systems) use a dedicated swap partition, so you cant' see it, use it , or do something else with it.
            The "swap off" command just tells the kernel to start OOM processes as soon as there is not enough free RAM anymore, A process is elected to be 'terminated', using a selection criteria somewhat better as 'Russian roulette', but the result will be the same as nearly all processes are essential to the system : things will go downhill fast.
            On pfSense, the process with loads of RAM (the DNS cache) is often unbound, so unbound is asked to leave, leaving you without DNS (and unbound gets yelled at again ...).

            If "swap" gets used on a pfSense system, you can interpret this as a pretty solid confirmation that your system is 'to small' for the tasks you asked it to do. The solution has been identified, it's " add more RAM " .....

            "swapon -a" is actually that little extra safely net, that can do the little extra more for you when needed, and its warns you that you'll need to buy more DIMMs

            No "help me" PM's please. Use the forum, the community will thank you.
            Edit : and where are the logs ??

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.