Implement free memory notifier
Needs ReviewPublic

Authored by McPain on Nov 28 2018, 2:04 PM.

Details

Reviewers
broulik
ngraham
Group Reviewers
VDG
Summary

FreeMemoryNotifier will warn when free RAM is running out.
By default, it is 25% without swap space.

Like freespacenotifier, it will check every 5 seconds for amount of free memory and
warn every time when it drops below limit and when free space amount drops more than half of previous value

User can either kill most greedy process immediately or open a task manager to kill unneeded processes manually.
Task manager was patched to ignore global config and show only user own processes, sorted by memory used in descending order.

The settings are available at new KCM located in Desktop Behavior category.
KCM and KDED modules are linked through DBus - committed settings are applied immediately.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
McPain created this revision.Nov 28 2018, 2:04 PM
Restricted Application added a project: Plasma. · View Herald TranscriptNov 28 2018, 2:04 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
McPain requested review of this revision.Nov 28 2018, 2:04 PM
ngraham added a reviewer: VDG.Nov 28 2018, 2:46 PM
ngraham added a subscriber: ngraham.

Thanks for all the work!

...But is this actually useful or actionable for the majority of users? Free space is a fairly understandable concept: if you run out, you need to delete things to make more room before you can add more stuff. It won't fix itself unless the user does something. But memory pressure requires a much greater technical understanding and isn't subject to the same conditions. When the system is using up 75% of the available memory, there isn't necessarily a problem at all. Apps will move to swap automatically. Even if there is a problem, it's only temporary, and it may fix itself if the user does nothing as the system shuffles things around.

I worry that this notifier would just be yet another annoying pop-up that people dismiss because they don't understand it.

Thanks for all the work!

...But is this actually useful or actionable for the majority of users? Free space is a fairly understandable concept: if you run out, you need to delete things to make more room before you can add more stuff. It won't fix itself unless the user does something. But memory pressure requires a much greater technical understanding and isn't subject to the same conditions. When the system is using up 75% of the available memory, there isn't necessarily a problem at all. Apps will move to swap automatically. Even if there is a problem, it's only temporary, and it may fix itself if the user does nothing as the system shuffles things around.

I worry that this notifier would just be yet another annoying pop-up that people dismiss because they don't understand it.

Sometimes I see what happens if you're running out of memory and oom can't do anything - the whole system halts and only solution for this is hard reset with all unsaved data lost.
25% is not hardcoded value, you can reduce threshold down to 1% and also you can include your swap space in settings.

abetts added a subscriber: abetts.Nov 28 2018, 2:58 PM

Is having this feature an optional feature? Can it be turned off?

Is having this feature an optional feature? Can it be turned off?

I'll make the notification "disableable" tomorrow

Sometimes I see what happens if you're running out of memory and oom can't do anything - the whole system halts and only solution for this is hard reset with all unsaved data lost.
25% is not hardcoded value, you can reduce threshold down to 1% and also you can include your swap space in settings.

The problem is that none of this is appropriate to expose regular users to. If this feature goes in, it needs perfect defaults, because 99.99% of users will never change the defaults even if they are annoyed by them.

I would recommend changing the default threshold from 25% to 10%, and automatically detect swap space rather than making the user configure it.

I don't think that this is useful - sorry. I run out of memory about once every five years, so polling every five seconds is way too often and a waste of resources. On the other hand the time when it happens polling 5 sec is way too low as then we are already dead. This can only happen if an application eats memory and then it's going fast.

I don't think that this is useful - sorry. I run out of memory about once every five years, so polling every five seconds is way too often and a waste of resources. On the other hand the time when it happens polling 5 sec is way too low as then we are already dead. This can only happen if an application eats memory and then it's going fast.

Agreed.

ngraham requested changes to this revision.Nov 28 2018, 6:01 PM
This revision now requires changes to proceed.Nov 28 2018, 6:01 PM

Given there is some negativity in the feedback I do want to point out that it's cool to still upload whatever to the KDE store/wider ecosystem. Not everything run in plasma needs to be from plasma; we go to great lengths to make sure that's the case.

There's also an alternative that I'd like to suggest:
According to https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt there's a system called "memory pressure" you can watch for events on a specific FD with various levels of out-of-memory-ness. A lot cheaper than polling, far more reliable, and following the system's OOM configuration. Getting that in at a frameworks level so it can be hooked up to notifications in this case, but also garbage collections in UI code could be pretty cool.

plasma-workspace/freememorynotifier/freememorynotifier.cpp
56

how is that 1 minute?

There's also an alternative that I'd like to suggest:
According to https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt there's a system called "memory pressure" you can watch for events on a specific FD with various levels of out-of-memory-ness. A lot cheaper than polling, far more reliable, and following the system's OOM configuration. Getting that in at a frameworks level so it can be hooked up to notifications in this case, but also garbage collections in UI code could be pretty cool.

Thanks. Any examples in KDE? I can't implement this from scratch right now.

McPain updated this revision to Diff 46892.Dec 5 2018, 11:10 AM

Default limit: 25% -> 10%
Fix typos
Auto detect swap, removed "includeSwap" setting
KSysGuard: show kill button (implemented in D17366)

McPain marked an inline comment as done.Dec 5 2018, 11:12 AM

Thanks. Any examples in KDE? I can't implement this from scratch right now.

There is not, it would requires writing new C code.
It's something I can help with.

Thanks. Any examples in KDE? I can't implement this from scratch right now.

There is not, it would requires writing new C code.
It's something I can help with.

What/where I can start with?

rooty added a subscriber: rooty.Feb 15 2019, 12:37 AM

My two cents - I really like this idea and this would be a very useful feature for those of us that really dislike swap space and have OOM problems (one too many browser tabs). But I'd set the intervals at 5-10 or even 20 minutes (not seconds).

Also, I suggest renaming it to "Memory Limit" or something else (a better description).

Otherwise, nice work!

have OOM problems

dislike swap space

Erm, I think I may have found your problem. :)

I still think this should be something that we don't ship or have on by default. It seems to be catering to extremely niche, nerdy use cases. Not that there's anything wrong with this! But these kinds of messages about the internal state of the system are not appropriate to show a to more casual users, who rightfully expect the system to take care of things like this by itself.

rooty added a comment.Feb 15 2019, 4:44 PM

Let me just say that I realize that this is pretty niche, but I would find it extremely useful and a lot of thought and care seem to have gone into this, hence +1.

have OOM problems

dislike swap space

Erm, I think I may have found your problem. :)

Different strokes.

Other reasons too, including the fact that most users nowadays have so much RAM that swap can be done away (if you don't use sleep/hibernate that is? I don't know how that works though).
It would just be nice not to have to think about this stuff and have my computer help me out.

I still think this should be something that we don't ship or have on by default. It seems to be catering to extremely niche, nerdy use cases. Not that there's anything wrong with this! But these kinds of messages about the internal state of the system are not appropriate to show a to more casual users, who rightfully expect the system to take care of things like this by itself.

I'm not suggesting it be shipped as a default setting, and I'd be okay with downloading it from the KDE Store, but we do already have niche widgets in Plasma (Binary Clock? Fuzzy Clock? Comic Strip, Color Picker...), so I don't think that's a reason not to include it.
The niche thing doesn't seem like a good reason either - Hard Disk usage, Hard Disk IO monitor etc. can all seem niche depending on your point of view. And we have tons of those.

ngraham resigned from this revision.Feb 15 2019, 5:08 PM

If it's not enabled by default like the free space notifier is, I'm okay with shipping this.

rooty added a comment.Feb 15 2019, 5:10 PM

If it's not enabled by default like the free space notifier is, I'm okay with shipping this.

I totally agree, it shouldn't be enabled by default

It would just be nice not to have to think about this stuff

Well that's the point.
You're only going to run out of memory on a working system if you have a runaway process. There is an OOM killer. That OOM killer is faster than a human, has access to more info about processes and has higher privileges than userspace.

McPain added a comment.EditedFeb 13 2020, 1:56 PM

It would just be nice not to have to think about this stuff

There is an OOM killer. That OOM killer is faster than a human, has access to more info about processes and has higher privileges than userspace.

(necroposting)
Which usually freezes my PC for 10 seconds or even more.

We need something that warns about OOM-killer pending, letting user manually (and correctly) terminate unused process(-es) while he can still control his system.
Otherwise, a giant freeze happens, random (for user) applications gets killed with unpredictable consequences, including data restoring requirement