Project

General

Profile

polkit uses too much memory

nona - about 3 years ago -

Hello,

I would like to know if there is a way to find out why polkitd keeps increasing the use of memory (RAM). Thanks.


Replies (17)

RE: polkit uses too much memory - freemor - about 3 years ago -

Your question is a little to vague for people to be able to answer it meaningfully.

For Example I do not know how you determined the "memory usage" which can be a tricky thing in Linux.
I do not know why you think it is too high.
I do not know what you tried to diagnose or resolve the issue.
I do not know what hardware you are running on, what is installed that may be interacting with Polkit, etc.

For example on my system htop (not a good tool for Dx'ing memory) show Polkit as the Second item:

polkitd    20   0 2523M 17760 13456 S  0.0  0.2  0:00.62 /usr/lib/polkit-1/polkitd --no-debug

Now if someone looked at the fact it was second and the 2523M they might assume
it's being a memory hog. But that is M_VIRT The second number 17760 which is
M_RES shows that is is actually not really using anywhere near that much. The
third number 13456 M_Shared is similarly low.

So Despite the M_VIRT being high and looking scary it is not actually using
much physical ram on my machine so Htop putting it second is very misleading.

If Polkit is eating all the physical RAM on your system that is definitely
something that needs to be resolved. But without moew info U don't know if it
actually is or if there is some other process driving Polkit crazy. Or if it is
some actual bug in Polkit.

RE: polkit uses too much memory - lukeshu - about 3 years ago -

I have found sudo ln -s /dev/null /etc/systemd/system/polkit.service to be effective at cutting polkit's resource usage.

RE: polkit uses too much memory - nona - almost 3 years ago -

(Sorry for the late reply. I am used to get notifications of replies from my issues, but I forgot that the forum works differently)

Thank you both. Indeed, freemor, it is using a lot of virtual memory. Apologies for calling it RAM. The fact that you send me the amounts on your system makes me think that it is not this which keeps making my system slower bit by bit.

I really don't know what to do when it comes to reducing the memory use of a running application other than killing it, really. I tried with a HUP signal, to see if it would restart, restarting other services and such.

How do I know what is interacting with polkitd?

Regarding @lukeshu's comment, I use OpenRC. I don't think that there is a service for polkitd (did not find it in /etc/init.d), but isn't polkit needed to run my system? can I have a safe system without it? are there replacements for it?

So, thank you both. I'm very glad that I asked. I apologise for the delay again. I will come back sooner.

RE: polkit uses too much memory - bill-auger - almost 3 years ago -

I really don't know what to do when it comes to reducing the memory use of a running application

for multi-document programs such as web browser, you can reduce
the number of open tabs - but for most programs, there generally
is not anything you can do - the applications uses what it
needs, no more and no less

do you believe that you are running out of memory? - is your
computer acting sluggish? or locking up? - swap space can help
if you are running out of memory sometimes - do you have some
swap mounted?

$ sudo swapon -s

what exactly is the problem you are trying to solve? - or are
you just trying to learn how stuff works?

How do I know what is interacting with polkitd?

probably nothing is using it silently - it is mainly used to
allow unprivileged users to do certain dangerous things to the
system, such as mounting disks - most of the time it is probably
doing nothing

as freemor explained, it is probably not using very much memory

could you show us what this command prints:

$ top -b -n1 | grep polkitd

RE: polkit uses too much memory - nona - almost 3 years ago -

bill-auger wrote:

---8<--- snip ---
the applications uses what it
needs, no more and no less

The thing is that the memory is usually not freed. Then, I eventually run out of RAM ... (see below)

do you believe that you are running out of memory? - is your
computer acting sluggish? or locking up?

(contd.) ... and it becomes slow up to the point of freezing

---8<--- snip ---- do you have some
swap mounted?

Yep, and I think that it some times tries to pass the data from swap to RAM, thus becoming slow.

what exactly is the problem you are trying to solve? - or are
you just trying to learn how stuff works?

More on the side of solving, but I think that knowing how it works (learning) is the way to eventually deal with it.

---8<--- snip ---
most of the time it is probably
doing nothing

Someone is going to get killed

$ top -b -n1 | grep polkitd

7826 polkitd 20 0 2975588 21544 16956 S 0.0 0.3 0:00.23 polkitd

which makes me think that this is expected, as I mentioned before.

Thanks a lot.

RE: polkit uses too much memory - lukeshu - almost 3 years ago -

nona wrote:

Regarding @lukeshu's comment, I use OpenRC. I don't think that there is a service for polkitd (did not find it in /etc/init.d), but isn't polkit needed to run my system? can I have a safe system without it? are there replacements for it?

I don't recall off the top of my head what starts polkitd on OpenRC systems, I'll check and get back to you.

Regarding polkit being necessary: What it does is essentially allowing you to poke holes in traditional user+process based permissions (à la sudo). If you don't want to poke any holes in traditional permissions, then polkit isn't doing anything for you and there's no reason to keep it around. What polkit lets you do set permissions on individual D-Bus API calls, which to be fair, lets you do things a lot more granularly in some cases, which is a security win. But for many users who keep their computer KISS, the only thing polkit is doing for them is letting them run systemctl ${whatever} as their regular user, instead of running it with sudo; and for OpenRC systems where D-Bus isn't so much a core part of the system, the value is even less.

Now, I never "got" why so many OpenRC users use NetworkManager, IMO NetworkManager actually embodies everything that everyone says is wrong with systemd (even the things that aren't actually true of systemd!), but since it is D-Bus based, perhaps you need polkit for NetworkManager?

RE: polkit uses too much memory - nona - almost 3 years ago -

lukeshu wrote:

I don't recall off the top of my head what starts polkitd on OpenRC systems, I'll check and get back to you.

Thank you.

---8<--- snip ---
for OpenRC systems where D-Bus isn't so much a core part of the system, the value is even less.

Yes, someone is definitely going to get killed!

Now, I never "got" why so many OpenRC users use NetworkManager, IMO NetworkManager actually embodies everything that everyone says is wrong with systemd (even the things that aren't actually true of systemd!), but since it is D-Bus based, perhaps you need polkit for NetworkManager?

Preach it! preach it all day long! I don't have NetworkManager for those very good reasons. Thank you for everything, and particularly for this last part.

RE: polkit uses too much memory - freemor - almost 3 years ago -

What you describe definitely sounds like "Swap Death".

Basically swap is a very slooow form of storage compared to physical RAM. When
you couputer run low on RAM it'll start using the HD (swap) as RAM.

The problem is that stuff storrred on the swap need to be brought into the
physicla ram to work on it. Which means that the spot in RAM that it is going
to take needs to be saved (swapped) out to the HD. So as swap fills your system
slows down exopnentially due to all the reads and writes. if your HDs are older
models. you your motherboard wasn't optomized for heavy I/O things get slow
even faster. Basically you end up in an ever increasing downward spiral of I/O
waits. thus everything grinds to a halt.

I'd be surprised if polkitd was eating that much swap. But clearly something
is.

One way to find the culprit, if you have sufficient ram to bring up your
system. Is to disable swap. This has two effects. It prevents swap death. and
It tends to cause memory hogs to crash and burn because they can not keep asking
for more and more RAM. You have to be a little careful interpreting the
results, (as in run other tests to verify) because the bad app could have
strangled out a good one. A good test would be to reboot and not use the app
that died.

The Linux Kernel also has a built in OOM (out of memory) killer that you can
tweak. it should kill apps that are taking too much memory. but is sounds like
you are hitting swap death before it gets the chance.

If you are in a low ram system the size of your swap should not exceed 2x the
RAM. On machines with more RAM I usually don't alot more swap then there is
ram. Unless I'm doing a stupid heavy build or something like that. and those
builds often fall over into swap death.

RE: polkit uses too much memory - bill-auger - almost 3 years ago -

Now, I never "got" why so many OpenRC users use NetworkManager

NetworkManager is the only high-level abstraction available with
parabola openrc - arch dropped wicd a while back too, so even
for systemd, it the only user-friendly option, if one wants a
desktop widget to select a wifi station, for example

RE: polkit uses too much memory - freemor - almost 3 years ago -

On Sun, Apr 04, 2021 at 05:01:28AM +0000, wrote:

https://labs.parabola.nu/boards/5/topics/869?r=908#message-908
bill-auger

Now, I never "got" why so many OpenRC users use NetworkManager

NetworkManager is the only high-level abstraction available with
parabola openrc - arch dropped wicd a while back too, so even
for systemd, it the only user-friendly option, if one wants a
desktop widget to select a wifi station, for example

There is also connman which has GUI FEs, but even without then it is easy to
use. it is also very compact and quite feature rich.

I first came across it when working with embeded devices.

--

RE: polkit uses too much memory - nona - almost 3 years ago -

freemor wrote:

What you describe definitely sounds like "Swap Death".

Sounds more like the name of a movie :P .

---8<--- snip ---
One way to find the culprit, if you have sufficient ram to bring up your
system. Is to disable swap. This has two effects. It prevents swap death. and
It tends to cause memory hogs to crash and burn because they can not keep asking
for more and more RAM.

A bit drastic, but I think that I can do that with 8 GB

You have to be a little careful interpreting the
results, (as in run other tests to verify) because the bad app could have
strangled out a good one. A good test would be to reboot and not use the app
that died.

polkitd has to die! and we'll bury some others with it, just to see if they are alive after exhumation. ;)

The Linux Kernel also has a built in OOM (out of memory) killer that you can
tweak. it should kill apps that are taking too much memory. but is sounds like
you are hitting swap death before it gets the chance.

New concept, thanks.

If you are in a low ram system the size of your swap should not exceed 2x the
RAM. On machines with more RAM I usually don't alot more swap then there is
ram. Unless I'm doing a stupid heavy build or something like that. and those
builds often fall over into swap death.

    (doctored result from `free')
                   total
    Mem:           7.5Gi
    Swap:           13Gi

I guess I'll unmount it for a bit and see what happens. I'll let you know (I fear for my over-bloated Emacs). Thanks!

RE: polkit uses too much memory - nona - almost 3 years ago -

freemor wrote:

---8<--- snip ---
There is also connman which has GUI FEs, but even without then it is easy to
use. it is also very compact and quite feature rich.
---8<--- snip ---

Looks promising.

This is just a kind observation (I understand about priorities and such): the [[Connman]] wiki page (https://wiki.parabola.nu/Connman) needs an update (compare to this ConnMan)

RE: polkit uses too much memory - nona - almost 3 years ago -

nona wrote:

I guess I'll unmount it for a bit and see what happens. I'll let you know (I fear for my over-bloated Emacs). Thanks!

Indeed, Emacs died and my browser did too; not at the same time. Not too bad, much better than the computer slowing down or completely freezing. It will force me to find the part of the Emacs' configuration which is causing this. Thanks!

RE: polkit uses too much memory - nona - almost 3 years ago -

lukeshu wrote:

I don't recall off the top of my head what starts polkitd on OpenRC systems, I'll check and get back to you.

In my case, it was at least in ~/.config/lxdession/LXDE/desktop.conf (by default)

[update]
but the polkitd comes from init, somehow. I am still unable to trace it.

RE: polkit uses too much memory - bill-auger - almost 3 years ago -

In my case, it was at least in ~/.config/lxdession/LXDE/desktop.conf (by default)

there is actually a GUI for that - it is the "polkit agent"
entry, on the "core applications" tab of the "default
applications for lxsession" program, launched from the
"preferences" menu

RE: polkit uses too much memory - nona - almost 3 years ago -

nona wrote:

[update]
but the polkitd comes from init, somehow. I am still unable to trace it.

I think that I found it:
/usr/share/dbus-1/system-services/org.freedesktop.PolicyKit1.service:
Exec=/usr/lib/polkit-1/polkitd --no-debug

RE: polkit uses too much memory - nona - almost 3 years ago -

This is just merely informative: Disabling polkitd prevents the power off and reboot options from the lxsession menu

[update 27 days later: 14/05/2021]

may be this will help others: without polkitd and with openrc, one can do

loginctl hibernate 

[another update: 26/12/2022]
This provides some hints
https://forums.gentoo.org/viewtopic-p-8508139.html?sid=d4b783fbcef9e1a3bebced964237df4f#8508139

    (1-17/17)