summaryrefslogtreecommitdiff
path: root/src/mount.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-01-15 10:53:49 +0100
committerMichal Schmidt <mschmidt@redhat.com>2012-01-16 13:34:42 +0100
commit7d17cfbc46306a106dbda0f3e92fbc0792d1e9e9 (patch)
tree44cb574e7d149a306287c51c7d57f4eff41c5a98 /src/mount.c
parent1637a8be5570dff7ce402451240b28ddb54e5dca (diff)
unit: reduce heap usage for unit objects
The storage of the unit objects on the heap is currently not very efficient. For every unit object we allocate a chunk of memory as large as the biggest unit type, although there are significant differences in the units' real requirements. pahole shows the following sizes of structs: 488 Target 496 Snapshot 512 Device 528 Path 560 Timer 576 Automount 1080 Socket 1160 Swap 1168 Service 1280 Mount Usually there aren't many targets or snapshots in the system, but Device is one of the most common unit types and for every one we waste 1280 - 512 = 768 bytes. Fix it by allocating only the right amount for the given unit type. On my machine (x86_64, with 39 LVM volumes) this decreases systemd's USS (unique set size) by more than 300 KB.
Diffstat (limited to 'src/mount.c')
-rw-r--r--src/mount.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mount.c b/src/mount.c
index 12c0710f1..f94c0eb27 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -1395,13 +1395,16 @@ static int mount_add_one(
if (!is_path(where))
return 0;
- if (!(e = unit_name_from_path(where, ".mount")))
+ e = unit_name_from_path(where, ".mount");
+ if (!e)
return -ENOMEM;
- if (!(u = manager_get_unit(m, e))) {
+ u = manager_get_unit(m, e);
+ if (!u) {
delete = true;
- if (!(u = unit_new(m))) {
+ u = unit_new(m, sizeof(Mount));
+ if (!u) {
free(e);
return -ENOMEM;
}
@@ -1412,7 +1415,8 @@ static int mount_add_one(
if (r < 0)
goto fail;
- if (!(MOUNT(u)->where = strdup(where))) {
+ MOUNT(u)->where = strdup(where);
+ if (!MOUNT(u)->where) {
r = -ENOMEM;
goto fail;
}
@@ -1837,6 +1841,7 @@ DEFINE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
const UnitVTable mount_vtable = {
.suffix = ".mount",
+ .object_size = sizeof(Mount),
.sections =
"Unit\0"
"Mount\0"