diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-01-15 10:53:49 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-01-16 13:34:42 +0100 |
commit | 7d17cfbc46306a106dbda0f3e92fbc0792d1e9e9 (patch) | |
tree | 44cb574e7d149a306287c51c7d57f4eff41c5a98 /src/unit.c | |
parent | 1637a8be5570dff7ce402451240b28ddb54e5dca (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/unit.c')
-rw-r--r-- | src/unit.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/unit.c b/src/unit.c index 1fbfb1dea5..fa3c2649b3 100644 --- a/src/unit.c +++ b/src/unit.c @@ -57,15 +57,18 @@ const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { [UNIT_PATH] = &path_vtable }; -Unit *unit_new(Manager *m) { +Unit *unit_new(Manager *m, size_t size) { Unit *u; assert(m); + assert(size >= sizeof(Meta)); - if (!(u = new0(Unit, 1))) + u = malloc0(size); + if (!u) return NULL; - if (!(u->meta.names = set_new(string_hash_func, string_compare_func))) { + u->meta.names = set_new(string_hash_func, string_compare_func); + if (!u->meta.names) { free(u); return NULL; } |