Skip to content

40 comments

On the AUR: https://aur.archlinux.org/packages/psi-notify/

Posting here in particular since this uses some pretty new kernel features (specifically PSI, which is enabled in the default Arch kernel) that I think will be of interest to Arch Linux users. :-)

I think we've all had situations where the desktop environment has become so slow as to be unusable, usually because some application has started eating up system resources quickly. Fellow Chrome users, I'm especially looking at you.

My wife is certainly someone in that position. Often she gets into scenarios where unwieldy applications like Chrome would unexpectedly eat memory over time, eventually ending with her desktop suddenly slowing to a crawl. Usually the only way out of this situation is to manually trigger an OOM kill with Alt + SysRq + F, and even then that's not foolproof, since the OOM killer may not pick the right target to kill. Even if it does pick the right target to kill, system responsiveness after the fact can still be impacted since the thrashing has pushed many pages into swap.

Logging PSI metrics on her machine leading up to these incidents, it was pretty obvious that there was always an opportunity to alert her ahead of time that the situation was becoming a problem, and allow her to manually select which applications to kill, since it might not always just be the one using the most memory or with the highest memory usage in a desktop scenario. Since prioritisation of "what to kill" is so dynamic on the desktop, it's very hard to write a one-size-fits-all policy about what to do in these scenarios, so these notifications allow you to avoid that problem entirely.

To that extent, psi-notify will warn you using whatever desktop notifier you have running (eg. GNOME notifications, dunst, xfce4-notifyd) when resources are starting to become contended, so that you can do something about that. A facetious demo is shown in the readme.

Feature requests and bug reports are welcome. I've been using it for the last week and already found it useful in keeping death-by-Chrome at bay. :-)

43 points

I am a linux noob here. But could you tell me what desktop notifier I could use on i3 for this to work?

8 points

Hey, this looks super neat - i'm considering pulling this in to the official arch linux repositories in the future.

Though, i've noticed the github repository doesn't ever mention licensing, and the AUR package states MIT - you might want to clarify this in the repo

27 points

I need this so much! Thank you! Here, have some ice cream (┛❍ᴥ❍)┛彡<3

10 points
unknown author

This seems extremely useful! Thank you

8 points

Hey, this is really neat! Since it's on a similar vein, I'll share a little script I just finished writing because I was frustrated that my system was locking up when I'd compile large packages from the AUR. Now my window manager stays responsive because one of the CPUs isn't being hammered (they start counting at 0).

limit-cpu

#!/bin/bash  
# systemd-run clears the environment so copy it manually  
ENV="$(env | sed 's/\(.*\)/"\1"/' | tr '\n' ' ')"  
systemd-run \
    --user \
    --pty \
    --pipe \
    --quiet \
    --property Environment="$ENV" \
    --property AllowedCPUs=1-7 \
    "$@"
limit-cpu yay -S linux-lts419
3 points

Does this work better than nice? I realize the two work differently (controlling CPU affinity whereas nice controls thread priority), but it seems like nice would have the same end result.

1 points

It works much better. Using nice got me from completely non-responsive to barely usable. Basically, I would press a key or move the mouse and then wait several seconds for the input to register.

My theory is that the window manager idles at very low CPU usage even though it has a high priority because it isn't doing anything. Even though the build process has lower priority, it's free to grab the rest of the CPU usage because nothing is using it. Then I make some sort of input that the window manager needs to process. Switching workspaces redraws the whole screen, so there would normally be a small spike in CPU usage. But there isn't any free so it has to ask for it. The nice settings ensure that it gets it, but that evidently takes some time. After finishing redrawing, the window manager drops back to its idling state and the whole process starts over resulting in a jerky and delayed experience.

The script is literally telling whatever you run with it that it isn't allowed to touch the first processor, so assuming you aren't doing anything else CPU intensive, there should always be free processing power for the window manager to grab when it needs it.

2 points

Installed, now anxiously waiting for the Chrome overload. :-)

3 points

I just wish Linux DEs could prevent runaway applications from eating all the memory. On macOS, it works really well. Instead of slowing the whole system to a halt, it allows user to kill the culprit before it's too late. Maybe have something similar for Linux? When some process eats almost all of the memory, pause it, ask user what to do next (continue/abort) and prevent those horrible stutters and slowdowns.

2 points

I'm a Chromium tab hoarder and thought this was a problem unique to me and my ten year old machine... I can usually tell it's coming when my cursor and text inputs start to lag a bit.

I'm torn between checking out the project and trying to fix the underlying problem, either my habits or limiting resource utilization by processes. Not entirely sure how to go about that though.

2 points

One option is systemd slices. You can set both CPU and memory limits for an individual program or a group of processes. Or libcgroup which comes with a set of command line tools to achieve the same things. They're both based on cgroups.

2 points

Damn a little too late. You should have told me before I did this.

I did that mostly because I couldn't run a language server and a browser at the same time

2 points

What you've made is awesome and you are awesome. Aaaand it's installed.

2 points

I just wanted to comment that you might want to separate your code to multiple files. I don't know the layout and workings of your code so I don't know if it's feasible. Also don't know much about C so take this with a grain of salt.

Personally, I just wanted to get a quick idea how the project works, but immediately backed out when I saw the 550 lines of code. Separating it out might make it more welcoming and get you more contributions down the line.

1 points

Thanks, and sure, I can see where you're coming from. There are definitely tradeoffs in both directions, but there are a few nice things about having everything in one file for small projects (let's say <1000 lines):

  • Ease of navigation. People don't have to worry about ctags, an IDE or whatever to find things quickly. They know that if it's provided by this project, it's in this file.
  • Reduction of Makefile complexity and dependency knowledge. Ok, so it doesn't add a whole lot more work to add some more objects to the mix in the Makefile, but I also don't see much reason to add them, either.
  • I'm not convinced splitting into more files makes things much clearer. If I were to do this, we'd probably end up with five files: notify.[ch], psi.[ch], and maybe cli.c. I'm not sure that really achieves much, which functions are part of which of these is already pretty clear.

psi-notify is fundamentally pretty simple in concept. If you trace through main(), I think you'll get there pretty fast :-)

All the functions pretty much do what they say they do:

% ctags -x psi-notify.c | awk '$2 == "function" { print $1 }'                 
alert_destroy
alert_destroy_all_active
alert_stop
alert_user
alert_user_if_new
config_init
config_reset_user_facing
config_update_from_file
configure_signal_handlers
get_pressure_file
is_blank
main
pressure_check
pressure_check_notify_if_new
pressure_check_single_line
request_exit
request_reload_config
threshold_update
watchdog_update_usec
9 points

I had no idea you could list out the definitions that ctags has found for a file. You have just blown my mind.

5 points

These are some good points too. I will try it on my system and see if there is something I would like to contribute.

It's about time I learned C, as it seems I have been learning languages in sort of reverse order. From Python and Bash to Java to webdev and now quite recently Rust.

1 points

For cases like this look into earlyoom too

1 points

Why is this useful? I don't have a new computer but it still never becomes crippled even under heavy loads. One of the benefits of Linux has always been that the kernel is good at distributing resources. Perhaps try a low-latency kernel if you're having issues?

-1 points

Hey! I actually work full time on Linux memory management and am one of the cgroup maintainers, so I'm pretty well versed in in this area. :-)

While it's true we're not bad at distributing resources, the question is about what to do when there is a scarcity of resources, and that's what PSI helps with -- identifying those scarcities as they start to occur and allowing some application or user to do something about it.

Low latency kernels are unlikely to help in these scenarios, because this isn't about latency or throughput, but instead actual resource shortages. That's what PSI has been designed to identify.

You can find out more about why PSI is useful in my talk at SREcon last year. Discussion of PSI is around the 25 minute mark: https://www.youtube.com/watch?v=beefUhRH5lU&feature=youtu.be&t=1505

17 points

Ouch! :)

Well, thanks for the information, I will have a look at the discussion.

5 points

For some reason my brain flagged this as an ad and I almost downvoted... oops!

-4 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.