Skip to content

core: cleanup unit's dropin directories from global cache#40845

Open
msekletar wants to merge 1 commit intosystemd:mainfrom
msekletar:dropin-mem-leak
Open

core: cleanup unit's dropin directories from global cache#40845
msekletar wants to merge 1 commit intosystemd:mainfrom
msekletar:dropin-mem-leak

Conversation

@msekletar
Copy link
Contributor

When user creates dropin files via API (e.g. systemctl set-property ...) we put the dropin directory path into unit_path_cache. Drop those directories from the cache in unit_free() and prevent memory leak.

Follow-up for fce94c5.

@github-actions github-actions bot added the please-review PR is ready for (re-)review by a maintainer label Feb 26, 2026
@msekletar msekletar changed the title core: cleanup unit's drop dropin directories from global cache core: cleanup unit's dropin directories from global cache Feb 26, 2026
@msekletar
Copy link
Contributor Author

Btw, leak is easily reproducible. Starting a transient unit and calling systemd set-property afterwards is enough to trigger it. Put it in the loop and keep running for a day and systemd can eat up 100s of MiBs of memory.

@msekletar
Copy link
Contributor Author

@yuwata PTAL.

free(u->source_path);

/* Maybe we have put unit specific dropin dir into unit_path_cache. */
STRV_FOREACH(dropin, u->dropin_paths) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only apply to transient units, no? i.e. should also be done in unit_remove_transient. Otherwise if a static unit gets GC'ed and then loaded again we suddenly ignore all the drop-ins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is quite generic, we put dropin directory into cache in unit_write_settings() which can be called via bus_cgroup_set_property() for non-transient units.

Regarding ignoring dropins, I don't think that is the case on top of that if the unit is GCed and then loaded again as part of loading all dropins should be freshly resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is quite generic, we put dropin directory into cache in unit_write_settings() which can be called via bus_cgroup_set_property() for non-transient units.

Sure, but those drop-ins stick around. We really shouldn't willy-nilly discard data we initially cache...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding ignoring dropins, I don't think that is the case on top of that if the unit is GCed and then loaded again as part of loading all dropins should be freshly resolved.

This does have an impact btw. We only GC unit objects, not cache built during unit load. That's the whole point of the cache after all, so that we don't have to look into whether certain files/dirs exist if we need to load a unit back in again...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but those drop-ins stick around. We really shouldn't willy-nilly discard data we initially cache...

Well, it is not willy-nilly per say, unit is gone and we free drop-in paths because drop-in paths are lifecycle bound to the unit object, directories those drop-in reside in should be deleted too. Btw, notice that I am deleting only unit specific drop-in directories not global ones like .../service.d/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is not willy-nilly per say, unit is gone and we free drop-in paths because drop-in paths are lifecycle bound to the unit object, directories those drop-in reside in should be deleted too.

They really aren't. Again this is what unit path cache is about after all... To flush out old records for static unit files you must issue a daemon-reload.

See unit_file_find_dirs() why this actually matters. We'd skip the drop-in dir if the cache is supplied and doesn't contain the dir.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree with @YHNdnzj. I think it is better to do that in unit_remove_transient().

BTW, CIs are red...

@YHNdnzj YHNdnzj added pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Feb 26, 2026
When user creates dropin files via API (e.g. systemctl set-property ...)
we put the dropin directory path into unit_path_cache. Drop those
directories from the cache in unit_free() and prevent memory leak.

Follow-up for fce94c5.
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Feb 26, 2026
@YHNdnzj YHNdnzj added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Feb 26, 2026
@yuwata yuwata added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks

Development

Successfully merging this pull request may close these issues.

3 participants