Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Selfhosted
  3. Why is my server using all my Swap but I have RAM to spare?

Why is my server using all my Swap but I have RAM to spare?

Scheduled Pinned Locked Moved Selfhosted
selfhosted
23 Posts 18 Posters 136 Views
  • 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.
  • M [email protected]

    This is an old desktop I use for some small self hosting services. I never use all my RAM and I don't see any RAM spikes other than when I install/compile things which I haven't done in months. I restarted the machine a couple of times, but the SWAP will eventually go right back up to 100%.

    I have an Ubuntu server/yunohost setup and found: https://askubuntu.com/questions/157793/why-is-swap-being-used-even-though-i-have-plenty-of-free-ram

    My cat /proc/sys/vm/swappiness value is indeed 60. Im not sure what would reduce the SWAP space usage.

    Would changing this swappiness value help? Anyone come across this issue before?

    L This user is from outside of this forum
    L This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #14

    No reason to remove something from swap which is already there. It does this for files too.

    1 Reply Last reply
    0
    • mhzawadi@lemmy.horwood.cloudM [email protected]

      Depending on what your server is doing, swap use is normal. But if it's into swap cuz ram is full, you will find it grinds to a halt.

      Use free -mh to see what the memory use is, there is a way to reduce the swapiness if your running a database server and is advised.

      S This user is from outside of this forum
      S This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #15

      And how does cache space figure in to this? I have a server with 64GB of RAM, of which 46GB is being used by system cache, but I only have 450MB of free memory and 140MB of free swap. The only 'volatile' service I have running is slapd which can run in bursts of activity, otherwise the only thing of consequence running is webmin and some VMs which collectively can use up to 24GB (though they actually use about half that) but there's no reason those should hit swap space. I just don't get why the swap space is being run dry here.

      mhzawadi@lemmy.horwood.cloudM 1 Reply Last reply
      0
      • N [email protected]

        I though that the recommended swap partition was to double until 16 GB? So at 32GB of ram use 32GB of swap?

        gnulinuxdude@lemmy.mlG This user is from outside of this forum
        gnulinuxdude@lemmy.mlG This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #16

        You should just maintain awareness of how much you're using. I think 32gb ram + 32gb swap is ridiculous, frankly. Fedora by default sets zram up to 8gb, with no other swap space configured. Works very well that way.

        Personally I'd also probably not ever set up more than 16gb of swap space. If I'm somehow hitting that limit it's because I actually just need to buy more RAM.

        1 Reply Last reply
        0
        • M [email protected]

          This is an old desktop I use for some small self hosting services. I never use all my RAM and I don't see any RAM spikes other than when I install/compile things which I haven't done in months. I restarted the machine a couple of times, but the SWAP will eventually go right back up to 100%.

          I have an Ubuntu server/yunohost setup and found: https://askubuntu.com/questions/157793/why-is-swap-being-used-even-though-i-have-plenty-of-free-ram

          My cat /proc/sys/vm/swappiness value is indeed 60. Im not sure what would reduce the SWAP space usage.

          Would changing this swappiness value help? Anyone come across this issue before?

          naomi@lemmy.amethyst.nameN This user is from outside of this forum
          naomi@lemmy.amethyst.nameN This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #17

          The naive approach of thinking of swap as "extra ram that is slow" and so "why is my system using swap when I have ram" is not really the best analogy. It's better to think of ram as a place that holds memory pages, and disk as a place that holds file blocks/extents. Ram happens to be very fast and disk happens to be very slow, but conceptually programs access both memory pages and file blocks as they are running.

          There is no reason that memory pages must live in ram, and no reason that file blocks must live on disk, especially in the modern world with virtual memory, and so sometimes it is more efficient for the kernel to say "hey, this memory page is never used and this file block is used a lot, so I'm going to put the memory page on disk and the file block in memory and everything will be faster."

          When a memory page is moved to disk, this is called swapping and the place it is stored on disk is swapspace. When a file block is stored in memory, this is called cache (or in some cases, buffers). So if you have plenty of ram free, it can still be beneficial for the kernel to move unused memory pages to swap to make space for cache. And once it is in swap, there's no good reason to move it back until you need it, so even if space frees up in ram, the kernel won't preemptively move it back into ram.

          S W 2 Replies Last reply
          0
          • naomi@lemmy.amethyst.nameN [email protected]

            The naive approach of thinking of swap as "extra ram that is slow" and so "why is my system using swap when I have ram" is not really the best analogy. It's better to think of ram as a place that holds memory pages, and disk as a place that holds file blocks/extents. Ram happens to be very fast and disk happens to be very slow, but conceptually programs access both memory pages and file blocks as they are running.

            There is no reason that memory pages must live in ram, and no reason that file blocks must live on disk, especially in the modern world with virtual memory, and so sometimes it is more efficient for the kernel to say "hey, this memory page is never used and this file block is used a lot, so I'm going to put the memory page on disk and the file block in memory and everything will be faster."

            When a memory page is moved to disk, this is called swapping and the place it is stored on disk is swapspace. When a file block is stored in memory, this is called cache (or in some cases, buffers). So if you have plenty of ram free, it can still be beneficial for the kernel to move unused memory pages to swap to make space for cache. And once it is in swap, there's no good reason to move it back until you need it, so even if space frees up in ram, the kernel won't preemptively move it back into ram.

            S This user is from outside of this forum
            S This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #18

            It also takes a while to move stuff between RAM and disk, so it'll park stuff in swap of it's not used much to make room for burst RAM needs.

            Generally speaking, don't worry about it as long as the system is responsive, but if things start sucking, consider closing stuff so the kernel can free it.

            1 Reply Last reply
            0
            • shimitar@downonthestreet.euS [email protected]

              1gb swap is way too small...

              I usually setup swap to be 2x the total ram size. So, 32gb swap in your case.

              Nothing wrong here, seems normal. With such little swap.

              Actually Linux kernel works better with swap, the more the better. It will lalso perform better than zero swap. Counterintuitive indeed, but that's how it works.

              If you don't want swap, use zram.

              S This user is from outside of this forum
              S This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #19

              32GB of swap is huge, I wouldn't bother with that much unless you're suspending to disk regularly. I personally just suspend to RAM and call it a day.

              On my laptop with 24GB RAM, I have about 20GB swap, which matches the system memory (rest is dedicated to my APU). On my desktop with 16GB RAM, I have 16GB swap, because that's what my OS picked (I would otherwise go with 10GB). On both systems, I usually only have 2-3GB in swap anyway.

              1 Reply Last reply
              0
              • naomi@lemmy.amethyst.nameN [email protected]

                The naive approach of thinking of swap as "extra ram that is slow" and so "why is my system using swap when I have ram" is not really the best analogy. It's better to think of ram as a place that holds memory pages, and disk as a place that holds file blocks/extents. Ram happens to be very fast and disk happens to be very slow, but conceptually programs access both memory pages and file blocks as they are running.

                There is no reason that memory pages must live in ram, and no reason that file blocks must live on disk, especially in the modern world with virtual memory, and so sometimes it is more efficient for the kernel to say "hey, this memory page is never used and this file block is used a lot, so I'm going to put the memory page on disk and the file block in memory and everything will be faster."

                When a memory page is moved to disk, this is called swapping and the place it is stored on disk is swapspace. When a file block is stored in memory, this is called cache (or in some cases, buffers). So if you have plenty of ram free, it can still be beneficial for the kernel to move unused memory pages to swap to make space for cache. And once it is in swap, there's no good reason to move it back until you need it, so even if space frees up in ram, the kernel won't preemptively move it back into ram.

                W This user is from outside of this forum
                W This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #20

                "hey, this memory page is never used and this file block is used a lot, so I'm going to put the memory page on disk and the file block in memory and everything will be faster."

                except when not, like when I just copied a multi GB file, it was cached in RAM to be not read again for long, but at least half of my running programs are swapped out. Additionally if swap is o SSD, it has put totally unnecessary wear into it by doing this

                M 1 Reply Last reply
                0
                • W [email protected]

                  "hey, this memory page is never used and this file block is used a lot, so I'm going to put the memory page on disk and the file block in memory and everything will be faster."

                  except when not, like when I just copied a multi GB file, it was cached in RAM to be not read again for long, but at least half of my running programs are swapped out. Additionally if swap is o SSD, it has put totally unnecessary wear into it by doing this

                  M This user is from outside of this forum
                  M This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #21

                  That's why you can adjust swappiness, or designate a different high-endurance storage device for it.

                  1 Reply Last reply
                  0
                  • shimitar@downonthestreet.euS [email protected]

                    1gb swap is way too small...

                    I usually setup swap to be 2x the total ram size. So, 32gb swap in your case.

                    Nothing wrong here, seems normal. With such little swap.

                    Actually Linux kernel works better with swap, the more the better. It will lalso perform better than zero swap. Counterintuitive indeed, but that's how it works.

                    If you don't want swap, use zram.

                    D This user is from outside of this forum
                    D This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #22

                    +1 for zramswap, especially if you're tight on RAM but have a few CPU cycles to spare.

                    1 Reply Last reply
                    0
                    • S [email protected]

                      And how does cache space figure in to this? I have a server with 64GB of RAM, of which 46GB is being used by system cache, but I only have 450MB of free memory and 140MB of free swap. The only 'volatile' service I have running is slapd which can run in bursts of activity, otherwise the only thing of consequence running is webmin and some VMs which collectively can use up to 24GB (though they actually use about half that) but there's no reason those should hit swap space. I just don't get why the swap space is being run dry here.

                      mhzawadi@lemmy.horwood.cloudM This user is from outside of this forum
                      mhzawadi@lemmy.horwood.cloudM This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #23

                      That's how Linux manages it memory, it will use free memory as file cache till it needs it. Then free up memory for process use.

                      If your only half using the memory for actual services, you may want to reduce it.

                      1 Reply Last reply
                      0
                      • System shared this topic on
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups