From 7d17cfbc46306a106dbda0f3e92fbc0792d1e9e9 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sun, 15 Jan 2012 10:53:49 +0100 Subject: 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. --- src/swap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/swap.c') diff --git a/src/swap.c b/src/swap.c index 4fa30a3e32..202c4e6625 100644 --- a/src/swap.c +++ b/src/swap.c @@ -334,7 +334,8 @@ int swap_add_one( assert(m); assert(what); - if (!(e = unit_name_from_path(what, ".swap"))) + e = unit_name_from_path(what, ".swap"); + if (!e) return -ENOMEM; u = manager_get_unit(m, e); @@ -348,15 +349,18 @@ int swap_add_one( if (!u) { delete = true; - if (!(u = unit_new(m))) { + u = unit_new(m, sizeof(Swap)); + if (!u) { free(e); return -ENOMEM; } - if ((r = unit_add_name(u, e)) < 0) + r = unit_add_name(u, e); + if (r < 0) goto fail; - if (!(SWAP(u)->what = strdup(what))) { + SWAP(u)->what = strdup(what); + if (!SWAP(u)->what) { r = -ENOMEM; goto fail; } @@ -1341,6 +1345,7 @@ DEFINE_STRING_TABLE_LOOKUP(swap_exec_command, SwapExecCommand); const UnitVTable swap_vtable = { .suffix = ".swap", + .object_size = sizeof(Swap), .sections = "Unit\0" "Swap\0" -- cgit v1.2.3-54-g00ecf