back to article Improve Linux performance with this one weird trick

A cryptic website with a single line of text promises to make your Linux box more responsive – if you are willing to accept some risk. Another day, another bleed-ing vulnerability. New speculative-execution attacks keep being discovered, and OS kernel developers keep finding ways to block them – at the cost of some CPU …

  1. A Non e-mouse Silver badge

    I can make my car faster by:

    - Removing all the air bags

    - Removing all the padding in the cabin

    - Removing the seat belts

    - Replaing the padded seats with bare-bones bucket racing seats.

    - etc.

    Doesn't mean I should...

    1. John Robson Silver badge

      Depends what you are doing with the car... if you're trying to set a robotically driven quarter mile then it's a good plan.

      The issue is that most systems aren't standalone.

    2. Kurgan

      It all depends on what you want. As the article states, if you are the ONLY user on that machine, it's fine. In your example, if your car is a racing car, then it might be fine. (execpt for seat belts)

      I use this configuration on my laptop but not on my servers. I's easy.

      1. Greybearded old scrote Silver badge

        If it downloads and runs any one else's code, like say the JS on this web site, then you're not the only user.

        As the article says, it's only for machines that aren't connected at all. How much use is one of those?

        1. Phil O'Sophical Silver badge

          only for machines that aren't connected at all

          Well, aren't connected when you boot like that, at least. If you have a big CPU-intensive job like an image render, or some video processing, you may want to get everything downloaded & setup, unplug the network, and reboot into a fast unprotected mode while running that one job. Then back to 'normal' & reconnect.

          1. Anonymous Coward
            Anonymous Coward

            This won’t speedup rendering or image processing or anything math intensive. This is about improving the performance of Linux system calls

        2. Anonymous Coward
          Anonymous Coward

          You're right.

          It is generally servers which run controlled workloads rather than clients. Lots of these bleed attacks have been demonstrated from JS, so most web browsing is out.

          On the other hand lots of servers never have any "logged in users" so there is no chance of extra SW being installed and run unless some other bug in your apps can be exploited by which time you're largely dead anyway.

          The days when server meant hundreds of users with login access is long gone.

          1. Duke of Source

            > On the other hand lots of servers never have any "logged in users" so there is no chance of extra SW being installed and run unless some other bug in your apps can be exploited by which time you're largely dead anyway.

            In a properly laid out zero trust architecture the effect of an exploit can be limited, by employing a rigid process isolation and RBAC least privilege scheme. For the protections to be meaningful you depend on kernel services. Therefore the kernel must be fortified.

            The usual process isolation being done is to put the service in its own container, e.g. one HTTP server process processing all requests, privileged and unprivileged. An unprivileged request with the exploit could still gain access to privileged requests. To limit the exploits reach, more HTTP server processes for different privilege levels would be required.

            1. Netgeezer
              Happy

              Least privilege rocks

              Although more work is made for the brilliant IT technical people running everything for many thousands of users in our organisation, with the principle of least privilege it's really been helping to mitigate unncessary access.

        3. Dave 126 Silver badge

          > As the article says, it's only for machines that aren't connected at all. How much use is one of those?

          For sure. Possibly a task that benefits from the user ignoring the outside world, such as writing a novel, illustrating, playing a single player game.

          But yeah. Maybe like the above sports car with the headlights removed - legal on a closed track, fun even, but not useful in the sense of nipping to the shops on the public highway network.

          1. quxinot

            There's an old adage about the tool and the job needing to be matched for best performance.

    3. naive

      We Linux guys live in the true land of the free, unlike those poor souls suppressed in a Stalinistic dictatorship like Windows or Apple land.

      We Linux guys think for ourselves, do not need some corporate bot determining what we should or should not do.

      If we want safe, we make safe, if fast is needed, for instance a database server in a secure network without internet, we make it fast.

      We are free and keep money for expensive licenses in our pocket, what can be better ?.

  2. UCAP Silver badge

    Unless you are using OpenSUSE ...

    ... which forces mitigations=auto on to the kernel command line regardless.

    1. ArLi

      Re: Unless you are using OpenSUSE ...

      In OpenSUSE it is as easy as starting yast, going to System/Boot Loader and switching to Kernel Parameters tab and setting CPU Mitigations control to OFF.

  3. Pete 2 Silver badge

    Go faster strips

    > that's what you want: a computer that is sealed off to the outside world.

    That's what I want for my Windows machines.

    It's (not) surprising how much faster they run without any anti-virus software. And there is joy to be found in not being nagged every five minutes to apply this update or that. Although the scourge of seemingly continuous updates has not infected my Linux machines, too.

  4. Will Godfrey Silver badge
    Meh

    Hmmm.

    I think I prefer to take the hit on performance - slightly less risk of an oops!

    P.S. wouldn't it be nice if someone designed a new architecture that was simple and fast without all the crud?

    1. A Non e-mouse Silver badge

      Re: Hmmm.

      That was the idea of RISC. It didn't stay "Reduced" for very long.

    2. Charlie Clark Silver badge

      Re: Hmmm.

      Define crud for CPU. Generally, if you can get something to run in hardware directly, it will be significantly faster than doing it in software: encryption, vectoring, transcoding, etc. And that means more complex chips and instruction sets.

      Some of the other stuff, especially speculative branch prediction, is trickier but almost essential to get things to go fast.

    3. ThatOne Silver badge
      Devil

      Re: Hmmm.

      > wouldn't it be nice if someone designed a new architecture

      OMG no! Not only would that spend an awful lot of R&D money, it also would make all the existing stock* obsolete. It's way more profitable to keep using the old architecture.

      To make it simple: Old architecture = bonus, new architecture = getting fired...

      * You don't replace your whole line of products in one fell swoop: Last year's high-end CPUs become next year's mid level offerings, and so on.

    4. Dave 126 Silver badge

      Re: Hmmm.

      >P.S. wouldn't it be nice if someone designed a new architecture that was simple and fast without all the crud?

      And it would be simple and fast. For ten minutes, by which time someone will have found a flaw that needs patching. Design a better mousetrap and the universe conspires to throw better mice at you.

      There are attempts at writing formally verified code - code proven to be as per spec just as 2 plus two equals four can be proved - but it's very hard work.

      1. Phil O'Sophical Silver badge

        Re: Hmmm.

        There are attempts at writing formally verified code - code proven to be as per spec just as 2 plus two equals four can be proved - but it's very hard work

        And doesn't help if the bug is due to something that wasn't taken into account in the spec.

        1. Claptrap314 Silver badge

          Re: Hmmm.

          I interviewed with Sonos about 5 years ago. Their original security model was: "Don't connect to a computer."

          What happens when end users ignore the spec is a closely-related matter.

    5. david 12 Silver badge

      Re: Hmmm.

      That would be the 80186 architecture. Simple, fast, and without all the crud.

      That is, without all the parallel threads, pipelining, branch prediction, and caching, so it run very fast at the speed of your RAM, not like your existing compute, which runs 100s faster than the speed of your ram, due to parallel threads, pipelining, branch prediction, and caching.

  5. Rich 2 Silver badge

    Disable swap

    “… then it probably occasionally swaps to disk…”

    I have run my Linux box with swap disabled for ages. These days with gobs of RAM, I see no point at all in having swap enabled on a personal machine (and I’m not even convinced most servers need swap any more - though obviously some do). If I ever get to the point where I’m running out of RAM then I either have a virus or I’m doing something really stupid.

    You have to remember what swap was invented for - a backstop when RAM was small and very expensive. If you are going to run out of memory then swap really just delays the inevitable. The size/cost issue just doesn’t exist any more

    1. Anonymous Coward
      Anonymous Coward

      Re: Disable swap

      > , I see no point at all in having swap enabled on a personal machine

      Hibernate. Though there are probably swap less ways of doing it these days.

      For the rest, agreed.

    2. VoiceOfTruth Silver badge

      Re: Disable swap

      Swap is not just about being the equivalent of extra RAM on disk.

      For example, in the FreeBSD world (and some other UNICES), if you have a swap partition (not a swap file) and you have a kernel panic, that panic can be saved to the swap partition for later debugging. You can't do the same on a file system during a panic, at least it is not safe to, as the kernel may have an invalid view of the file system. It has no such problem with a swap partition.

      I don't know how Linux handles kernel panics (don't tell me they never happen).

      1. Anonymous Coward
        Anonymous Coward

        Re: Disable swap

        > I don't know how Linux handles kernel panics (don't tell me they never happen).

        They never happen. >:)

        My kernel doesn't panic during a crash. It expresses concern while in a spot of bother.

      2. Anonymous Coward
        Anonymous Coward

        Re: Disable swap

        Kernel Panic, isn't that the newest Marvel super hero? Or maybe that's DC - or AC if that works.

        1. Aussie Doc
          Coffee/keyboard

          Re: Disable swap

          Kernel Panic is gonna be the name of my new Heavy Metal band.

          On lead guitar is Chad the cad, Nic Arsen on bass, Aggie on the silver, chromium drums, with Van the Man providing vocals.

          Hope to go platinum soon.

          Nobody on keyboard --->

    3. MacroRodent
      Holmes

      Deals with bloatware Re: Disable swap

      I usually keep a classic swap partition just in case. With a 8Gb machine, it is almost never used (one can check this with "top" for example), and consequently does not cause any performance degradation.

      However, there is one situation where it is useful: You have some modern piece of desktop bloatware with lots of data open, and you wish to use something else for a while with the intention of getting back. So you launch the other program, things are sluggish for a while (swapeti-swap) but then you can do your thing in the other program and then return to the original bloatware. Again things are slow for a while, but you do get eventually to a state where you get work done, after the necessary pages have been restored from swap.

      In other words, you swap from one big task to another and back. Like the name "swap" says. If I did not have a swap partition, the dreaded OOM of Linux might have decided to kill the first program. (Or something else).

      Of course, the idea of using swap to run two active, huge programs in an interleaved fashion does not work nowadays, you might as well be running Babbage's mechanical computer.

    4. Missing Semicolon Silver badge

      Re: Disable swap

      It makes OOM less painful. No swap, and an OOM situation is very likely going to be an instant hard-lock.

      With some swap, the memory manager has the chance to leave you enough to type "kill -9 <bad-process>" at a console.

    5. Kevin McMurtrie Silver badge

      Re: Disable swap

      Swap removes unused data that would compete with more useful caches. It's generally best to leave it on. You can tune the "swappiness" parameter if the balance between data and cache isn't where you want it.

      My personal server usually has a few GB of cruft that pages out over a period of several days and never pages back in.

    6. Bitsminer Silver badge

      Re: Disable swap

      And some software uses shared memory which needs to be "backed" by swap if not an actual file.

      Lesson learned the hard way when trying to use NFS for swap....it didn't.

      1. Anonymous Coward
        Anonymous Coward

        Re: Disable swap

        > trying to use NFS for swap

        I admire you.

    7. Grogan Silver badge

      Re: Disable swap

      You're defeating the most significant and important purpose of swap. It's not so much for giving yourself "extra memory" nowadays. (If you're actually working with data paging in and out of swap, that's not viable. A big compile job can take days, for example)

      The most significant use of swap is to aid in memory management. The kernel can't free up anonymous pages. It has no idea if that data is there for a process, or if it's orphaned and it's data that could be lost since it's not backed by data on disk, if you don't have swap. It can't just be dropped.

    8. Anonymous Coward
      Anonymous Coward

      Re: Disable swap

      Spoken like a true Linux user.

      We get it, Linux has traditionally been crap and buggy at swapping, but it's much better these days. Here is an article on why swap is good, from a Linux perspective: https://chrisdown.name/2018/01/02/in-defence-of-swap.html

      Swap space usage is good. All proper systems use it. Don't confuse that with frequent swapping, which is obviously bad.

  6. Anonymous Coward
    Anonymous Coward

    Yes, I clicked through

    Just because of the headline.

  7. Anonymous Coward
    Anonymous Coward

    > it took a zero off the amount of data placed into swap

    From the left or from the right?

    1. Zolko Silver badge
      Boffin

      From the left or from the right?

      litlle- or BIG-endian ?

      1. spireite Silver badge

        Re: From the left or from the right?

        Servers in Barbados?

        West-endian.

    2. ChrisC Silver badge

      Before or after the decimal point?

    3. zuckzuckgo Silver badge

      I solved that dilemma, I just store all my bytes vertically.

  8. Howard Sway Silver badge

    My advice, as ever

    If it ain't broke, don't fix it.

    Hacking around with the kernel can be great fun, IF YOU KNOW WHAT YOU'RE DOING / DON'T MIND REINSTALLING EVERYTHING IF IT FAILS.

    And we should have all had plenty of experience warning our less technical friends to never, ever do what they read in a "here's a magic trick which will enormously speed up your computer" article - because too many of them are ways of actively inflicting harm.

    This article obviously isn't trying to do that, it's for interested techies. However, proper caveats should still be given, even though nearly all Linux users here will not need them.

    1. A Non e-mouse Silver badge

      Re: My advice, as ever

      Who can remember the fun we had with DOS & Smartdrive

      1. Evil Auditor Silver badge
        Paris Hilton

        Re: My advice, as ever

        Indeed I do remember the fun! But not why and what for I used to fiddled with Smartdrive - pretty clueless nowadays...

  9. Eric Kimminau TREG

    Back in the day....

    I was hired because of my knowledge and experience using QEMM to load drivers into high memory so that Windows 3.1(x) would load and run better.

    1. Binraider Silver badge

      Re: Back in the day....

      I don't know if it's a skill or a curse that I can still remember how to do such optimisation - and more to the point have had cause to do it in the last couple of years for anything other than historical curiosity.

      Legacy DOS, Autoexec.bat and config.sys still linger in the PLC world for various reasons.

      Finding minimally-sized drivers for mouse and CDROM are easy starting points. Super-compact soundcard drivers are the remaining item on the wish list maxing out the 640k.

  10. Pirate Dave Silver badge
    Pirate

    Interesting

    If for no other reason that letting us benchmark how much "oomph" these workarounds eat away at all that proce$$or power we bought.

  11. Claptrap314 Silver badge
    Megaphone

    I'm pretty sure

    I mentioned this in my FIRST reply to the FIRST article that came out about SPECTRE. The drip, drip, drip of these exploits is precisely why NIST recommended (for twelve hours) turning speculative execution off. These partial mitigations add up, and in a big way.

    I've interviewed with multiple companies who have gone this route for protected database servers and the like. The cost savings are enormous, and, as alluded to above, with proper least-access privileges implemented network-wide, quite safe.

    What surprises me is that a mere kernel option can really do it. To really see the benefit, you need to turn off things like retpoline when you compile your applications and libraries. I would strongly urge something like Yggdrasil if a company I was advising was considering going this route.

  12. Doctor Evil

    zswap change rocks!

    On an old laptop with 4 MB RAM and a spinning rust hard drive running under Mint 20.3 Cinnamon, I just enabled the zswap change ( (2nd-to-last paragraph) with 2x compression (not 3x) + Firefox cache switch from disk to memory cache, and the difference is ... phenomenal! Cool!

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Other stories you might like