I'm a programmer by trade with twenty years of experience, having first used Linux in 2004 (iirc), and I thought I knew the game pretty well. There are CPU-bound tasks, memory-bound tasks, network-bound tasks, and disk-bound tasks. I'm doing async programming and it's working fine, offloading i/o to the kernel while my app is doing cpu stuff. Except, I'm now using a laptop with 8 GB of memory and Linux Mint-Cinammon on HDD as my main machine, and somehow shit is constantly in the swap and waits for the disk. Right now I'm moving a Windows partition, I have quit everything except four Firefox tabs, Emacs, and Double Commander — and I still think I might kill myself before the ordeal is over. The entire system is completely and totally fucked. Barely anything moves, nothing responds in any kind of a timely fashion. Emacs freezes when typing, with two open buffers. Audio playback stutters. VPN is nonresponsive. I closed all the hundreds of buffers in Emacs, I set the priority and io priority of Gparted to the minimum, and the other apps to the max. I set swappiness to zero, and turned off the swap altogether with swapoff. All of this barely helps. I'm drunk right now, and still this affair bugs me beyond measure. I could maybe deal with this as a one-time thing if swapping and disk i/o weren't incapacitating the system every day.

Is Linux kernel so ridiculously single-threaded that any i/o cripples the entire thing? Or is something tuned horribly wrong in Mint by default? Can I unfuck this somehow? I live close to a river, I can't take this much temptation.

you are viewing a single comment's thread
view the rest of the comments
[–] [S] 1 point 15 hours ago (6 children)

Please do tell then. What do apps do after they handle i/o out to the kernel in a dedicated thread? Do they just sit around and wait, in your opinion?

  • source
  • parent
  • hideshow 6 child comments
  • [–] 1 point 10 hours ago (5 children)

    Well first, the linux kernel is open-source. This is not my opinion and everything I'm telling you is auditable.

    programs are generally written to wait for writes to close. There are good reasons for this. The simplest example I can think of would be a basic text editor's "save and exit" function. It writes the data, and then closes. If it didn't wait for the write to finish, and it closed mid-write, you'd lose half your data. Now remember that this doesn't just apply to editors. It applies to logging functions, updating programs, creating a shortcut, changing a setting in a menu, etc... The program relies on kernel signaling to know when a file has "finished" writing. In the case of datacenter high-performance filesystems or raid controllers, it will use memory (think: ram) as cache for the writes and the kernel will report back to the process that the write is finished, even while a little bit of the file is still in ram and waiting to be flushed to disk. This is safe because those systems have multiple redundant power supplies and/or backup batteries. In the case of a desktop, you typically don't do this because a power flicker or a system crash could take data with it. Modern SSDs make this somewhat of a non-issue because they're still relatively fast at small writes while under load. The difference on a small write between a thrashing ssd and a thrashing hdd can be the difference between 200 nanoseconds (nvme ssd) and 15 milliseconds (hdd).

    Programs need to block on writes sometimes as a mater of procedure to ensure data integrity, and you're hitting the worst case possible. 50,000-500,000 times slower than a modern enterprise filesystem, 1,000-10,000 slower than a bog-standard, modern consumer-grade nvme ssd.

    Operating systems are generally built with the assumption of mid-range consumer hardware from 4-6 years ago, and spinning disk root volumes haven't been standard for over a decade. There are absolutely things you can do to make a system play nicely with a spinning root volume but modern general-purpose operating systems tune for different assumptions. Almost none of them tune for a 15ms write penalty on logging.

  • source
  • parent
  • hideshow 5 child comments
  • [–] [S] -1 points 8 hours ago* (last edited 7 hours ago) (4 children)

    Thanks for the info, but I'm quite familiar with how i/o works in general. I know what the write cache is. I know what journaling is, and FYI it's doing its job on desktop systems too. I know how flushing affects performance (for the worse). I know how to disable flushing in databases to gain performance, and how to force it to gain durability. I even know about onboard batteries in some disks. I know about the orders of magnitude in delay between different interfaces, I'm obligated to be versed in that for my job. The only problem is, I'm not a sysadmin.

    None of this explains why Firefox is constantly swapping in and out when it just displays pages on the screen, presumably writing slightly more than bupkis on the disk, and why the entire system is slow as molasses when some disk i/o is happening but I'm not saving anything.

    It applies to logging functions, updating programs, creating a shortcut, changing a setting in a menu, etc…

    None of that applies to Firefox when it's just displaying pages, and Emacs when it's showing me buffers and running code that's already in the memory.

    There are absolutely things you can do to make a system play nicely with a spinning root volume

    Thanks again for the info. One might even think that I created the whole post to ask what specifically I could do about it, explicitly saying so in the text, and fortunately you're here to inform me that there are indeed things I can do. How lucky I am to receive this knowledge that there is something I can tune somewhere.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 2 points 7 hours ago (1 child)

    firefox does a lot of disk caching during regular use, mostly from webapps trying to be clever about using your disk space to cache chats, media, etc. there's functionally nothing you can do about this per-site. It also does a lot of journaling in local sqlite databases for its own cookies, history, caching, etc.

    if you want actual solutions:

    use a DE like lxde to free up system memory as much as possible.

    move firefox's caching and profile directories to /dev/shm and accept the memory footprint penalty on launch. accept that a crash or shutdown without flushing back to disk will result in losing this data.

    add an override to journald.conf.d to move the journal to volatile storage with a functionally nonexistant rolling size, but just big enough not to crash (~128mb)

    disable rsyslog

    create a systemd service to move /tmp /var/tmp /var/log and /var/cache/apt/archives to ramdisk on boot.

    disable any systemctl timer that you don't absolutely need (apt-daily.timer apt-daily-upgrade.timer, logrotate.timer etc...)

    increase the journal commit interval on your root filesystem to something like ~60s

  • source
  • parent
  • hideshow 1 child comment
  • [–] [S] 1 point 5 hours ago*

    Thanks for proper advice. I think LXDE wouldn't help much, since most memory is likely used by the apps instead of the system. Curiously, I enabled memory compression which was off by default and which helped me a lot with low-memory machines in the past — it's set to use 40% of the memory currently, but I might need to raise that. Unfortunately, I don't think it makes too much difference in the end.

    I'll probably fiddle with the journaling parameters and rsyslog's options first, since those seem fairly harmless. Don't want to lose useful functionality right away.

    I'm gonna move the system partition to an SSD sooner or later just to save what remains of my sanity, except the swap won't be there to avoid the device being hammered to death in a month or two before I can splurge on some mem upgrades. It's remarkable how twenty years ago I could glide through the filesystem as fast as my fingers diddled the cursor keys; or switch through images at 60 fps or so like a Terminator — but now I somehow have to constantly wait for the apps even with an SSD. Not quite sure what happened, but shit's wack.

    firefox does a lot of disk caching during regular use, mostly from webapps trying to be clever about using your disk space to cache chats, media, etc. there’s functionally nothing you can do about this per-site. It also does a lot of journaling in local sqlite databases for its own cookies, history, caching, etc.

    Ironically, I'm a webdev, so I'm somewhat sure that the sites I use don't behave that badly — and I just can't move so fast as to cause much i/o with the history and whatnot, exactly because it's barely responding when shit hits the fan. But I need to trace FF one of these days to figure out what the hell it's doing. Maybe the extensions are the culprits.

  • source
  • parent
  • [–] 0 points 7 hours ago (1 child)
  • [–] [S] -1 points 6 hours ago* (last edited 5 hours ago)

    So you're now following me around to chime in with your bullshit when I'm talking to someone who has actual knowledge, because your fragile ego's self-worth is tied to the OS you like and you can't accept it being scrutinized a little? You should probably stop using Lemmy, because I never did such pathetic crap even when on a bender.

    By the way, MacOS is optimized way better than Linux in every way. Deal with it.

  • source
  • parent