[HN Gopher] AMD has a one-liner to help speed up Linux system re...
___________________________________________________________________
AMD has a one-liner to help speed up Linux system resume time
Author : sharjeelsayed
Score : 102 points
Date : 2023-05-24 12:46 UTC (10 hours ago)
(HTM) web link (www.phoronix.com)
(TXT) w3m dump (www.phoronix.com)
| samsquire wrote:
| I've been thinking there must be a generic approach to waiting
| for events rather than sleeping and registering actions on
| events.
|
| Like epoll for events
| interlinked wrote:
| any guesses about how soon this will be available in
| distributions like pop os?
| zamalek wrote:
| You'll probably spend more time setting up bleeding edge kernel
| PPAs and what-have-you than this will save you. If "when will I
| get?" is ever a question for you, then an Ubuntu-based distro
| is probably the wrong choice: Ubuntu is about stability, not
| features.
| nonethewiser wrote:
| Ok.
|
| But back to the question. When might PopOS get this?
| PrimeMcFly wrote:
| When did this change? I remember the opposite being true,
| i.e. jumping on Wayland, PulseAudio when it still had issues,
| etc.
| jeroenhd wrote:
| While this is true, they do occasionally backport some stuff
| from newer kernels (usually for security reasons). This looks
| like a reasonably easy-to-backport patch, assuming the code
| hasn't been refactored since Ubuntu pinned their kernel
| version for a release of choice.
| danudey wrote:
| If you wanted to compile your own kernel, that's an option. You
| can use the `make oldconfig` target to import the kernel config
| from your OS; you'd lose any distribution patches that were
| made, but generally speaking it would be fine in every way I
| can think of.
|
| You can find basic instructions here:
| https://www.baeldung.com/linux/oldconfig-target-kernel-makef...
|
| Is it worth going to all the trouble of doing this to save
| slightly over 1/10th of a second on wake from sleep? Probably
| not. Is it fun to experiment with? That's up to you to decide.
| dogleash wrote:
| How often does your distro update the kernel? Does your distro
| ship stable or an LTS kernel? Will this patch even get
| backported into LTS kernels? How often does your distro cut new
| disto releases?
|
| tl;dr: I think pop is a Ubuntu flavor, so ~6 months and/or it's
| already available today if you're not afraid to compile your
| own kernel.
| Shared404 wrote:
| > tl;dr: I think pop is a Ubuntu flavor, so ~6 months and/or
| it's already available today if you're not afraid to compile
| your own kernel
|
| Pop isn't currently following the Ubuntu release cadence,
| they've got some internal development that their focusing on
| instead currently.
| arnon wrote:
| I'm not sure what news value this has - what is there to talk
| about?
| hardware2win wrote:
| Ah, the most powerful optimization technique: add random sleeps
| to the code and when people start complaining remove them and
| collect your bonus
|
| </joke>
| alberth wrote:
| Or you become known as the person who ships slow/laggy
| products.
| techwiz137 wrote:
| Reminds me of the post about the loop which did nothing but
| take up cycles. And reducing the number of loops sped up the
| software.
|
| Can't remember which one it was.
| Zinggi wrote:
| Pretty sure you mean this one:
| https://thedailywtf.com/articles/The-Speedup-Loop
| pluijzer wrote:
| When I was a child writing games with QBasic, my simple text
| adventures would load up instantly. Though all the
| professional made games I played had loading screens. So I
| added a progressbar with some for loops to make my game more
| professional. 500 iterations was about 1 second I remeber (on
| my specific 386 that is).
| 0xbadcafebee wrote:
| you joke, but it's the most powerful promotion technique.
| create something insanely efficient but still provides business
| value, and then spend 2-3 years "increasing efficiency" and
| publicizing it, then get promoted because you're so great at
| efficiency, repeat. "I saved $20,000 with this one neat trick!"
| (neat trick: turn off the servers you don't need)
| marcusjt wrote:
| Presumably you meant to say "insanely inefficient"?
| derefr wrote:
| No, that's kind of the trick of it. To be able to do this,
| the thing you create has to be, on a base level, insanely
| efficient compared to what came before. You're frontloading
| years of optimizations in one big leap.
|
| _On top of that solid basis_ , you can introduce
| artificial inefficiencies, and then gradually remove them.
|
| But you can't do the trick at all, if your rewrite doesn't
| start off being an orders-of-magnitude efficiency
| improvement.
| 0xbadcafebee wrote:
| yes :)
| dabluecaboose wrote:
| I actually pulled the reverse of this at my last job.
|
| Surprisingly, a lot of aerospace engineers are not super
| computer-literate. We used a clunky maneuver planning software
| for the geostationary sats that spit out our plans in an ASCII
| printout, which we then had to copy/paste out and manipulate
| using several consecutive shell scripts. I got annoyed doing it
| and so I rewrote the whole deal in Python, and just had it
| locate the file that had the printout.
|
| When I first ran it, it had turned a 3-4 hour affair into about
| 10 minutes (depending on network connectivity). I showed it to
| my boss, and he was asking why it said "working...done"
| instantly. He said it looked like it wasn't doing anything.
|
| So I added an aesthetic wait variable to the config and made it
| 1.25 seconds. So the user got to see "Working..." and then
| "done" would pop out, making it seem more like it was actually
| doing things to the layperson.
|
| Last I heard they were still using that script for maneuver
| planning to this day.
| jareklupinski wrote:
| when they ask for stuff like that, what they really want is
| more juice
|
| https://garden.bradwoods.io/notes/design/juice
|
| "..." is a kind of juice
| dabluecaboose wrote:
| Oh for sure. The giant ASCII satellite name every time you
| run it is definitely juice, too. Even changes colors on my
| birthday, so i get a yearly happy birthday text from my old
| coworkers haha
| pixl97 wrote:
| I mean, honestly having the pause, or some other conformation
| that work was completed is useful. If you ever had a system
| 'fail successfully', finishing to fast does become a concern.
| p4l4g4 wrote:
| Having meaningful output is useful, artificial pauzes like
| this are only for dramatic effect. I rather have a linear,
| timestamped log, so I can confirm my suspicions, than a
| progress bar with artificial delays, that suggest progress.
|
| But that's the techy point of view. Most non-techies will
| probably prefer feel over functionality. I think most
| people do. If something is instant, it feels too good to be
| true. If something takes ages, you'll get bored or
| frustrated. While things that take a proportional amount of
| time feel satisfying.
| w4rh4wk5 wrote:
| Productivity gap at its finest ^^
| mixmastamyk wrote:
| _Kirk: Mr. Scott. Have you always multiplied your repair
| estimates by a factor of four?
|
| Scott: Certainly, sir. How else can I keep my reputation as a
| miracle worker?
|
| Kirk: Your reputation is secure, Scotty._
| consp wrote:
| Good to see general resume improvements but ...
|
| Can we not try to force s2idle? It uses way too much power. I've
| not yet seen a laptop which is capable of staying "sleeping" in
| s2idle as long as in s3 sleep. Correct me if I'm wrong though.
|
| I also don't really get why: s3 is more than fast enough to be
| awake when my laptop is open and I'm ready to login, the only
| "need to be faster" way I can see is when you do not lock you
| laptop and go straight to desktop but that has ... issues.
| fulafel wrote:
| S3 was mature so it had to be innovated away.
| bbarnett wrote:
| I literally have no issue if, for example, Microsoft wanted
| to stop supporting S3. But instead, they demanded
| manufacturers remove the option from bioses?!
|
| People say Microsoft isn't the same as 20 years ago, that
| they are not pure evil, but this is proof...
| akiselev wrote:
| _> People say Microsoft isn 't the same as 20 years ago,
| that they are not pure evil, but this is proof..._
|
| People haven't been paying attention since their consent
| decree expired over a decade ago.
| tpxl wrote:
| Can I get my S4 back? I've never had issues with it, as opposed
| to constant S2/3 issues, and the startup is still faster than
| having to look for a cable because S2/S3 managed to drain all
| the battery.
| aimor wrote:
| What is the current situation with sleep states? I've been
| seeing lots of conversations the last two years and I just
| don't have a big level picture of why it's such an issue now.
|
| I only use S4 (hibernate) because I can ignore my laptop for
| weeks at a time, unplugged, and jump right back in to where I
| left off. Microsoft seems to have changed some things in
| Windows to hide the hibernate option for some reason I can't
| figure out.
| secondcoming wrote:
| Hibernate isn't great if you have lots of RAM. Windows
| won't allow you put the hiberfil.sys anywhere other than
| C:\\. I was confused as to why my C: SSD appeared full
| until I figured it was because of hibernation (I have 128GB
| RAM).
| justsomehnguy wrote:
| It's always amuses me when the systems are unbalanced.
|
| 'Gaming PC' with a latest i7 but a $200 video card.
|
| 'DB Server' with gigantic core count each at 2.0GHz (for
| less than 30 people of course). Of HDDs as a primary
| storage.
|
| Laptop with 128Gb of RAM yet insufficient storage to hold
| 128Gb hiberfil.sys.
| fulafel wrote:
| People also use hibernation on desktops, servers and VMs
| (traditionally when normal suspend has problems, but
| maybe nowadays when s2idle has insomnia problems).
| justsomehnguy wrote:
| If you managed to get 128Gb of RAM in your desktop then
| you can manage to get a 1Tb SSD.
|
| Hibernation on a server? Pointless most of the time,
| because the bulk of the startup time is pre-OS. And
| hibernating VMs is just retarded.
| fulafel wrote:
| Depends on the vintage. Up to about 2015 a 128 GB
| workstation config typically had a <= 512 GB boot SSD and
| some spinning disk as well.
|
| In servers it's actually quite nice in homelab style
| setups where you might want to preserve your working
| session states, or just doing it on a nightly schedule
| without worrying about losing work.
|
| For VMs it's of course useful to persist vm state to disk
| and suspend for lots of reasons (don't keep the RAM
| reseved, or free up VFIO passhthrough hardware for
| instance). But people often use hypervisor based snapshot
| for this. One advantage guest OS supported hibernation
| has it that your guest is aware of its own power state
| changes and can run your configured power management
| event hooks on suspend and wake. In the VFIO reddit it
| seems to be common for people who do windows vm gaming
| with gpu passthrough to prefer guest hibernate to
| hyprevisor side snapshots as well, not sure what are the
| main advantage there.
| justsomehnguy wrote:
| > In servers it's actually quite nice in homelab style
| setups where you might want to preserve your working
| session states, or just doing it on a nightly schedule
| without worrying about losing work.
|
| At this point it's a server in the name only. Even
| Supermicro takes ages to boot up, HPE and DELL can take
| up to 5-10 minutes to boot depending on the config.
|
| Sure, there are some situations where it can be used for
| server, but hibernate is a middle ground between a full
| boot and STR and loses on the most important metric - the
| actual boot time.
|
| > For VMs it's of course useful to persist vm state to
| disk and suspend for lots of reasons
|
| But again it's quite niche. You trade the RAM for the
| disk space and if you are short on RAM then something
| gone wrong with planning the resources in the first
| place. _Sure_ , in some situations (homelab again,
| *sigh*) it can be useful, but again it's not the popular
| option. With VDI you still get the bootstorm and lose the
| caching of the golden image.
|
| > Depends on the vintage. Up to about 2015 a 128 GB
| workstation config typically had a <= 512 GB boot SSD and
| some spinning disk as well.
|
| And again this is not 2015 anymore and surely you can
| have a $50 M.2 (or even SATA) 1Tb QLC SSD for the system
| drive (and your fancy whatever Tbs SSD for the actual
| workload).
|
| > not sure what are the main advantage there.
|
| The main difference is what the hardware is initialized
| again (instead of relying on the hypervisor to restore
| everything) so I bet it's some GPU shenanigas.
|
| I would like to clarify: sure, in some cases hibernating
| works^W is useful, but my initial point was about
| 'unbalanced' configurations and having 128Gb RAM with a
| boot drive < 512Gb AND requiring hibernate is what would
| constitute as unbalanced for me.
|
| PS for the sake of it, checked my notebook:
| TM420 C:\Users\amc>dir c:\hiberfil.sys /ahs
| Volume in drive C is Windows Volume Serial
| Number is DEAD-BEEF Directory of c:\
| 07.05.2023 03:03 4,901,584,896 hiberfil.sys
| 1 File(s) 4,901,584,896 bytes 0
| Dir(s) 62,332,203,008 bytes free
|
| Even if it was a full file for 12Gbs of RAM (damn those
| soldered modules) I would be fine with my 256Gb SSD.
| Dylan16807 wrote:
| > Depends on the vintage. Up to about 2015 a 128 GB
| workstation config typically had a <= 512 GB boot SSD
|
| 2015 was a long time ago in terms of SSD technology, but
| even then the space needed to hibernate 128GB was only
| $50.
|
| If it's 'typical' to make a workstation that can't spare
| that space then that's even funnier than if it wasn't
| typical.
| secondcoming wrote:
| Ha! I have several 2TB SSDs that I use for daily work
| stuff, the boot SSD is 235GB.
| jeroenhd wrote:
| It's a shame hyberfil.sys can't be moved, but as I
| understand it, the reason behind it is that the kernel
| only has an extremely rudimentary NTFS driver at the
| point it resumes so I don't think it'll change soon.
|
| That said, with modern SSD prices I think the size it
| takes up is quite reasonable these days. For a while,
| when people were running 64GiB SSDs, the situation was a
| lot worse.
| jeroenhd wrote:
| Who took your S4? I can't say what other operating systems do
| these days, but both Linux and Windows support suspending to
| disk out of the box.
| cesarb wrote:
| > but both Linux and Windows support suspending to disk out
| of the box.
|
| At least with Linux, out of the box all you'll have is the
| message "Lockdown: systemd-logind: hibernation is
| restricted; see man kernel_lockdown.7" in your logs.
|
| (The trick is to either disable Secure Boot, or AFAIK make
| use of an encrypted swap partition; IIRC, there's a bug
| which makes it not recognize a swap volume within LVM
| within LUKS as encrypted swap, so it has to be directly on
| a disk partition.)
| mecsred wrote:
| I've run both a Secure Boot/encrypted boot partition
| NixOS and plain LVM on LUKS archlinux on my Framework and
| neither had any issues or bugs with hibernating. Just add
| a resume hook to mkinitcpio and a kernel parameter to the
| UUID of the swap vol and it works fine.
| flipbrad wrote:
| I'm a longtime Linux user, but even I had to chuckle at
| this reply - very much living up to our caricature!
| jeroenhd wrote:
| Microsoft tried very hard to make desktop chips behave like
| mobile phones. I can see why, especially with SSDs, there's
| absolutely no reason why we should shut down a computer but
| keep our phones on 24/7 with instant wake.
|
| The problem is that a lot of laptop manufacturers, driver
| authors, UEFI firmware vendors, and you name it, don't exactly
| have power savings as a first priority. On some select devices,
| s2idle works great and it's just like sleep but faster. On many
| other devices, there are bugs and issues that just break shit.
|
| At this point, I have more faith in a brand new Linux install
| going to sleep successfully than a Windows install staying the
| fuck off. It's quite annoying, especially since I know every
| modern CPU has full support for this and the issues just lie in
| software elsewhere on the board.
|
| If you've got an SSD, the easiest fix is to switch to
| S4/hibernation/suspend to disk. You can remap the power
| button/laptop close handler. You may need to enter your drive
| encryption key again when you resume (which is probably more
| secure anyway) but your sleep will work reliably and it'll
| consume no power at all, unlike S3 sleep.
| m463 wrote:
| I remember working on sleep/wake and resume bugs and they can
| be hairy, especially when a device powers off. Some devices
| have firmware initialization, hidden state and it's corner
| cases all the way down.
| Natsu wrote:
| They also tried to screw over Linux when standardizing it:
|
| > In 1999, then Microsoft CEO Bill Gates stated in an e-mail
| that Linux would benefit from ACPI without them having to do
| work and suggested to make it Windows-only.
|
| My Windows laptop from work loves to have the mouse, keyboard
| and/or wifi fail to wake up properly if it gets disconnected
| from its badly-designed power cord, despite constantly making
| me install the latest drivers.
| bordercases wrote:
| Did Apple adopt an approach like this more successfully?
| jraph wrote:
| Hibernating when you have 32 G of requires more than that for
| swap. That's not negligible on a 512 G SSD.
|
| And copying 32 G is not instantaneous neither. I bet a fresh
| boot is faster, defeating a big part of the purpose of
| suspend for me (part of it is finding my workspace where I
| left it, sure, but also being able to quickly wake up the
| laptop).
|
| And 64 G laptops are sold now.
| jandrese wrote:
| Seems like the OS should be able to store only the active
| working memory and silently discard stuff like disk cache
| when hibernating, so the hibernate would only be slow if
| you really had the machine seriously loaded up with work.
| Maybe if you're doing heavy duty video editing? Or VMs I
| guess.
|
| I wish I had more trust in laptops to properly handle
| putting itself into S2 when I close the lid, and then after
| 30 minutes (or if the battery gets low) go down into S3.
| But I've seen far too many laptops just fail to properly
| suspend for whatever reason.
| binkHN wrote:
| On my aging Windows ThinkPad with 32GB of RAM, my
| hiberfil.sys is ~12GB, so you would be correct. As for S2
| moving to S3, this is similar to how I've been using the
| system for years; close the lid and I get S2 or S3
| (haven't looked to see which one)--if the battery charge
| hits a certain level, the system moves to S4/hibernates.
| Bjartr wrote:
| Yup, I stopped using hibernate when I got a laptop with
| 32GB of ram. It took longer than a cold boot to come back
| from hibernate.
| deckard1 wrote:
| systemd supports "suspend-then-hibernate" which I think
| works now.
|
| That said, systemd fucked the hell out of this feature
| and then the devs started gaslighting people about
| it[0][1]. That was on top of the fact that their "fix"
| broke the setting entirely and when you suspended your
| laptop it would _never_ resume, guaranteeing a reboot and
| lost data (which ironically was their premise for
| "fixing" it in the first place). They really tried to get
| people to believe that a nearly dead battery 8 hours from
| now was preferable to hibernating after X minutes and
| resuming with a nearly full battery. On a motherfucking
| laptop.
|
| Sigh. Just when I was starting to accept systemd they go
| and do that shit. Words cannot express how pissed I
| _still_ am from that github thread and them breaking my
| laptop from a basic ass fucking system fucking mother
| fucking fucking upgrade. Fuck systemd.
|
| [0] https://www.reddit.com/r/archlinux/comments/zczdnq/sy
| stemctl...
|
| [1] https://github.com/systemd/systemd/issues/25269
| Dylan16807 wrote:
| > That's not negligible on a 512 G SSD.
|
| Yes but in 2023 a 1TB SSD is $40.
|
| > And copying 32 G is not instantaneous neither. I bet a
| fresh boot is faster, defeating a big part of the purpose
| of suspend for me (part of it is finding my workspace where
| I left it, sure, but also being able to quickly wake up the
| laptop).
|
| How much you need to copy should depend on how much you
| have open, which should relate pretty strongly to how
| annoying a reboot is.
| jandrese wrote:
| > Yes but in 2023 a 1TB SSD is $40.
|
| Depends where you're buying it. If it's soldered to the
| motherboard of the laptop it's going to be a lot more
| expensive.
| hawski wrote:
| I have an employer issued Windows laptop. I have it connected
| to a charger on my desk almost all day. It is very often the
| case, that I close the lid and after some time it gets hot
| and the fan gets very loud. I always wonder: "what the fuck
| is this stupid machine doing?", it can't be an update,
| because Windows is incapable of doing unattended updates
| without a restart. After I open the lid the next day nothing
| seems to have happened. Same with my wife's work laptop. Her
| laptop is even worse, because sometimes it will play the
| sound of an incoming e-mail in the middle of the night.
|
| It is entirely bizarre.
| eightysixfour wrote:
| Corporate AV set to run when not being used?
| hawski wrote:
| That sounds plausible. Will have to check what a sibling
| comment suggested with getting the reason of the wake-up.
| formerly_proven wrote:
| S4/hibernate - shutdown /h - should still work on machines
| with S0ix, right?
| viraptor wrote:
| This is a decent collection of ideas if you want to dig
| into your specific case: https://www.pcmag.com/how-to/stop-
| your-computer-from-randoml...
|
| But yes, the active sleep idea is terrible in windows at
| the moment.
| nonethewiser wrote:
| Same with my wifes old macbook
| programmarchy wrote:
| It may be a "one-liner", but it's the kind where the engineer had
| to have broad and detailed knowledge about the system and how it
| works. Well done!
| nonethewiser wrote:
| So many bugs are like this. Spend 1 or 2 days on it and then
| ship a 1 line change.
| kevincox wrote:
| The classic:
|
| 1. Doing the thing $5/h
|
| 2. Knowing what thing to do $500/h
| greiskul wrote:
| Yup. One of the most complex bug I ever fixed was caused by a
| race condition. It took me 2 weeks to investigate and fix it.
| The final result was a couple of lines (like 5).
| hexo wrote:
| How much have you been paid for it? $4k? I'd be brutally
| laughed at in this "awesome" country for that. Some just
| cannot understand it. How do you get them actually pay for
| that time? Thats a mystery for me.
| nightowl_games wrote:
| I just upgraded my Linux kernel and had major suspend issues due
| to the XHCI driver. I ended up having to disable the ability for
| XHCI to wake my machine.
|
| On fedora cinnamon, I was getting random freezes on resume, and
| momentary freezes on resume on Linux Mint. Disabling the ability
| for XHCI to wake my machine fixed it.
|
| This sleep() looks like bad code designed to work around a race
| condition. Perhaps it's related to the issue I had.
|
| This issue was the worst Linux issue I've had in ~10+ years.
|
| (I'm on ryzen first gen cpu)
___________________________________________________________________
(page generated 2023-05-24 23:02 UTC)