Hi guys!

I have what I’d consider a beefy gaming PC. AMD 7700 CPU, 32GB RAM, 7800XT 16GB, NVMe 1TB for OS, mSATA SSD 2TB for storage/games.

So…whenever I get a while using the computer, with a bunch of windows open, say firefox taking 4GB of RAM, total for everything a bit over 16GB…I’m prone to get a whole system slowdown/freeze, which can take a few full minutes until it settles. I can see the storage red led on the whole time without blinking, so it really looks like swapping.

However sometimes I don’t see movements in the system process viewer, in usage from RAM/swap, I’d imagine those graphs would change if the data in swap has changed.

Swapping is set in the mSATA, taking 8GB, so I reckon that migth not be the fastest. Still, that’s an SSD. I’m not sure how can I check/troubleshoot whatever is tanking my computer performance?

  • Possibly linux@lemmy.zip
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    2 hours ago

    An SSD is a few thousand times slower than ram

    What’s your ram usage look like? Your system shouldn’t need swap unless you are running something very ram intensive

  • Sims@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    11 hours ago

    Been enjoying Linux for ~25 years, but have never been happy with how it handled low memory situations. Swapping have always killed the system, tho it have improved a little. It’s been a while since I’ve messed with it. I’ve buckled up and are using more ram now, but afair, you can play with:

    (0. reduce running software, and optimize them for less memory, yada yada)

    1. use a better OOM (out of memory) manager that activates sooner and more gracefully. Search in your OS’ repository for it.
    2. use zram as a more intelligent buffer and to remove same (zero) pages. It can lightly compress lesser used memory pages and use a partition backend for storing uncompressible pages. You spend a little cpu, to minimize swap, and when needed, only swap out what can’t be compressed.
    3. play with all the sysctl vm settings like swappiness and such, but be aware that there’s SO much misinformation out there, so seek the official kernel docs. For instance, you can adapt the system to swap more often, but in much smaller chunks, so you avoid spending 5 minutes to hours regaining control - the system may get ‘sluggish’, but you have control.
    4. use cgroups to divide you resources, so firefox/chrome (or compilers/memory-hogs) can only use X amount before their memory have to swap out (if they don’t adapt to lower mem conditions automatically). That leaves a system for you that can still react to your input (while ff/chrome would freeze). Not perfect, tho.
    5. when gaming, activate a low-system mode, where unnecessary services etc are disabled. I think there’s a library/command that helps with that (and raise priority etc), but forgot its name.

    EDIT: 6. when NOT gaming, add some of your vram as swap space. Its much faster than your ssd. Search github or your repository for ‘vram cache’ or something like that. It works via opencl, so everyone with dedicated vram can use it as super fast cache. Perhaps others can remember the name/link ?

    Something like that anyway, others will know more about each point.

    Also, perhaps ask an AI to create a small interface for you to fiddle with vm settings and cgroups in an automated/permanent way ? just a quick thought. Good luck.

  • mox@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    10
    ·
    2 days ago

    Rather than guessing at whether it’s swapping, why not check your swap usage? Running free -h in a shell will give you a brief overview of memory usage. Various GUI system monitors will graph it.

    You can also find out what process is hitting your storage so hard with a tool like iotop.

  • tal@lemmy.today
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    2 days ago

    In the sysstat package, there’s a command, iostat, that shows the amount of time that the average CPU (core) is waiting for something.

    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               0.57    0.01    0.55    3.14    0.00   95.73
    

    “User” is the CPU time used by regular processes. “Nice” is the time used by “niced” processes, stuff running at low priority. “System” is time used by the kernel. “Iowait” is the time waiting for I/O operations to complete.

    If you’re bounded on I/O, then the iowait number is probably going to be relatively high.

    It’ll also show you I/O load on each device (and the sysstat package can log this over time, let you use sar to see historical numbers).

    You can artificially induce load on a given I/O device to see whether load on it induces your problem. Something like this:

    $ dd if=/dev/zero of=filename-that-you-want bs=1M
    

    That’ll start your system just writing zeroes to a file. If it’s I/O contention on the mSATA drive, then I’d expect you to see the problems you mentioned.

    One thing you might check is whether your system is logging errors during this time. I don’t know what a failing SSD looks like, but in my experience a failing rotational drive would often see errors and then attempts to re-perform I/O operations. That produces seriously-degraded disk I/O performance. These errors will show up in the kernel log. To see kernel errors since the current boot:

    $ journalctl -kb
    

    The smartmontools package contains a command, smartctl, which will let you see what your drive thinks of its own health. I’m not really familiar with what a failing SSD would look like, but with rotational drives, it can indicate that something’s wrong with the drive, and it looks like my SSDs do report SMART status.

    # smartctl -a /dev/sda
    

    Moving swap

    Linux can, if it needs to, use a swap file instead of a swap partition, so you don’t need to repartition your NVMe if you just want to try putting your swap on the NVMe.

    If you want to, first, for the current boot, disable all the active swap partitions.

    # swapoff -a
    

    If you run top, you’ll see the available swap be at zero.

    Then you want to create the swap file. Say we drop it in /var:

    # mkswap --file /var/swapfile --size 32GiB
    

    And then you can enable it:

    # swapon /var/swapfile
    

    Then see how things perform.

    If it makes your problem go away and you want to make the change persistent:

    In /etc/fstab, you’ll have a line for your swap partition that the system reads at each boot. Will probably look something like this:

    /dev/mapper/system--vg-swap_1 none            swap    sw              0       0
    

    Comment that out by sticking a “#” at the beginning of your line, and put a line in for your new swapfile on the NVMe:

    /var/swapfile none            swap    sw              0       0
    
    • iturnedintoanewt@lemm.eeOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 days ago

      Thanks for the very detailed guide. Would you advice to have such a large swapfile? If I remember correctly, the old advice was to have double the storage in swap than in RAM. But after 4 or 8GB of RAM or so, this is no longer needed and just a generic amount of swap is kinda needed.

      I’m moving now my swapfile to the nvme. I might put it in /var indeed. Thanks!

      • tal@lemmy.today
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        2 days ago

        Would you advice to have such a large swapfile

        On laptops, you normally want at least as much swap space as you do physical memory, as when you hibernate the thing, that’s where the hibernation data is stored, and if you don’t have enough space there, hibernation will fail. IIRC, it’s also required for some kernel debugging technique (where, as hazy memory indicates, I believe the kernel can basically “dump core” to swap space, then reboot and write it out to regular storage). So it certainly works, because there are a lot of Linux systems out there that use that much relative to physical memory. Though I admit that I’ve never tried using a swap file instead of a swap partition, myself.

        It’s not quite like the old days, with rotational drives, and pre-OOM killer, where having a huge amount of swap would let the system bog down to the point where it couldn’t be used.

        Do you need 32GB swap? Probably not, if you don’t plan to hibernate the system. But unless you need the storage for something else, probably doesn’t hurt. And if you’ve got a 1TB system drive, I doubt that you’re short on space.

        I have 128GB of main memory and 128GB of swap on this system. Same 1:1 ratio, and I normally use that on Linux systems.

        For the example, I just chose an arbitrary, “reasonable” size. Feel free to pick a size that you feel is better, if you’d prefer something else.

  • highball@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 day ago

    What is your swappiness? If you have all that ram you should not be swapping. You are probably still at a swappiness for an average system, 60. Try 10. sudo sysctl vm.swappiness=10

    • mox@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      20 hours ago

      It reduces the drive’s lifespan.

      Let’s remember that swapping frequency and volume are system-dependent; practically zero on many systems. On a well-provisioned system that doesn’t swap much, having swap space on an SSD can be easier on the environment and wallet than buying and powering a separate device for it.

      Nevertheless, I agree that minimizing SSD writes is worthwhile, and reject the notion that an SSD’s useful lifetime ends when I’m done with it. (See my other comment.)

    • mybuttnolie@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 day ago

      An SSD also throttles as it heats up, going as slow as an old HDD. I thought I broke mine when it took an hour to copy 100 gigs of files, but it just slowed down to keep under 60C. Idk how much swapping heats it up though.

    • catloaf@lemm.ee
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 days ago

      While true, you’re still unlikely to see significant wear from a typical PC use case over the typical replacement time.

      • mox@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        15 hours ago

        I try to keep in mind that replacement shouldn’t mean landfill. When my needs have outgrown an SSD, it gets repurposed, donated, or sold. Old ones still work great in computers used in education, special-purpose systems, test environments, refurbished laptops, appliance-like machines, etc.

        In the long run, conserving SSD life while I own it translates into less waste and pollution in the world.

        • Justin@lemmy.jlh.name
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 day ago

          most people aren’t using 64gb ssds anymore, so I would say that the 64gb ssd I bought in 2014 has outlived its usable life, even though it is not worn out.

  • Fubarberry@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 days ago

    Probably not it, but what DE/WM are you using? I had a very similar issue on KDE, but it would go away if I switched DEs.

      • Fubarberry@sopuli.xyz
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 day ago

        It still might be worth trying another DE/WM for a bit to see if the issue is KDE exclusive. It might help you narrow down the cause.

  • just_another_person@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 days ago

    Have any metrics on your heat? Dmesg logs? Power? Minutes of freezing certainly seems like a heat problem, but could also be a device going offline until power is restored.