summaryrefslogtreecommitdiff
path: root/src/shared/util.h
AgeCommit message (Collapse)Author
2014-10-31hashmap: rewrite the implementationMichal Schmidt
We reintroduce hashmap.{h,c}, list.h and set.h verbatim from upstream, before we punt dead code. The following is the upstream message: This is a rewrite of the hashmap implementation. Its advantage is lower memory usage. It uses open addressing (entries are stored in an array, as opposed to linked lists). Hash collisions are resolved with linear probing and Robin Hood displacement policy. See the references in hashmap.c. Some fun empirical findings about hashmap usage in systemd on my laptop: - 98 % of allocated hashmaps are Sets. - Sets contain 78 % of all entries, plain Hashmaps 17 %, and OrderedHashmaps 5 %. - 60 % of allocated hashmaps contain only 1 entry. - 90 % of allocated hashmaps contain 5 or fewer entries. - 75 % of all entries are in hashmaps that use trivial_hash_ops. Clearly it makes sense to: - store entries in distinct entry types. Especially for Sets - their entries are the most numerous and they require the least information to store an entry. - have a way to store small numbers of entries directly in the hashmap structs, and only allocate the usual entry arrays when the direct storage is full. The implementation has an optional debugging feature (enabled by defining the ENABLE_HASHMAP_DEBUG macro), where it: - tracks all allocated hashmaps in a linked list so that one can easily find them in gdb, - tracks which function/line allocated a given hashmap, and - checks for invalid mixing of hashmap iteration and modification. Since entries are not allocated one-by-one anymore, mempools are not used for entries. Originally I meant to drop mempools entirely, but it's still worth it to use them for the hashmap structs. My testing indicates that it makes loading of units about 5 % faster (a test with 10000 units where more than 200000 hashmaps are allocated - pure malloc: 449±4 ms, mempools: 427±7 ms). Here are some memory usage numbers, taken on my laptop with a more or less normal Fedora setup after booting with SELinux disabled (SELinux increases systemd's memory usage significantly): systemd (PID 1) Original New Change dirty memory (from pmap -x 1) [KiB] 2152 1264 -41 % total heap allocations (from gdb-heap) [KiB] 1623 756 -53 % Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-30util: unify how we see srand()Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-26label: move is_dir() to util.cLennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-25src/shared/util.h: import realloc_multiply() from upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-09-18src/shared: import upstream code needed for recent commitsAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-22util: change return value of startswith() to non-consteudev/v1.10Lennart Poettering
This way we can use it on non-const strings, and don't end up with a const'ified result. This is similar to libc's strstr() which also takes a const string but returns a non-const one. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-14src/shared: import more code cleanups from upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-14src/shared: import many code cleanups from upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-12udev: modernize net_id builtin a bitLennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-05src/shared: refactor shared codeAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2012-11-17Rename src/shared to src/include, a saner nameAnthony G. Basile
2012-11-15Final step of revamping the build systemAnthony G. Basile
The structure of the source tree is basically correct and this is about as far as we can go without hacking at the C code.
2012-11-15Isolation of udev code from remaining systemdAnthony G. Basile
This commit is a first attempt to isolate the udev code from the remaining code base. It intentionally does not modify any files but purely delete files which, on a first examination, appear to not be needed. This is a sweeping commit which may easily have missed needed code. Files can be retrieved by doing a checkout from the previous commit: git checkout 2944f347d0 -- <filename>
2012-11-14util: add strreplace() to replace a substring by another stringLennart Poettering
2012-11-12util: nicer tree drawingsMichal Schmidt
Draw trees more similar to pstree/findmnt/lsblk/...
2012-11-04shared: add is_efiboot()Kay Sievers
2012-11-02util : fallback to plain ASCII drawing if locale is not UTF-8Michal Schmidt
When printing cgroup and sysfs hierarchies, avoid using UTF-8 box drawing characters if the locale is not UTF-8. https://bugzilla.redhat.com/show_bug.cgi?id=871153
2012-11-02util: add is_locale_utf8()Michal Schmidt
journalctl and vconsole-setup both implement utf8 locale detection. Let's have a common function for it. The next patch will add another use.
2012-10-30shared: "max" in the string->number conversion is meant to be inclusiveMichal Schmidt
2012-10-30shared, core: do not always accept numbers in string lookupsMichal Schmidt
The behaviour of the common name##_from_string conversion is surprising. It accepts not only the strings from name##_table but also any number that falls within the range of the table. The order of items in most of our tables is an internal affair. It should not be visible to the user. I know of a case where the surprising numeric conversion leads to a crash. We will allow the direct numeric conversion only for the tables where the mapping of strings to numeric values has an external meaning. This holds for the following lookup tables: - netlink_family, ioprio_class, ip_tos, sched_policy - their numeric values are stable as they are defined by the Linux kernel interface. - log_level, log_facility_unshifted - the well-known syslog interface. We allow the user to use numeric values whose string names systemd does not know. For instance, the user may want to test a new kernel featuring a scheduling policy that did not exist when his systemd version was released. A slightly unpleasant effect of this is that the name##_to_string conversion cannot return pointers to constant strings anymore. The strings have to be allocated on demand and freed by the caller.
2012-10-28logind: support for hybrid sleep (i.e. suspend+hibernate at the same time)Lennart Poettering
2012-10-27util: return the remaining string in startswith()Lennart Poettering
2012-10-26coredumpctl: show timestamps in listLennart Poettering
2012-10-22util: add (x)bsearch_r(), the missing counterpart of qsort_r()Kay Sievers
2012-10-19util: change endswith() to return a pointer to the suffixLennart Poettering
2012-10-19util: unify line caching and column cachingLennart Poettering
2012-10-19util: unify usage of on_tty() in util.cLennart Poettering
2012-10-19util: simplify column caching logicLennart Poettering
2012-10-11journalctl: implement --since= and --until for filtering by timeLennart Poettering
2012-10-03dbus: add some more safety checks before accepting data from bus clientsLennart Poettering
2012-09-24journalctl: reset cached column count on SIGWINCHDave Reisner
This requires a little bit of tip-toeing around to explicitly avoid touching the environment from a sig handler. Instead, simply create a function to reset the var to its "unset" state, allowing the next call to columns() to recalculate and cache the new value.
2012-09-20util: fix overflow checksLennart Poettering
2012-09-20util: overflow hardeningLennart Poettering
2012-09-20util: make sure heap allocators fail when array allocations are out of boundsLennart Poettering
https://bugzilla.redhat.com/show_bug.cgi?id=858777
2012-09-19util: define union dirent_storage and make use of it everywhereLennart Poettering
Make sure to allocate enough space for readdir_r(). https://bugzilla.redhat.com/show_bug.cgi?id=858754
2012-09-18util: introduce get_process_gid()Lennart Poettering
2012-09-17util: various cleanups for printing boot statusLennart Poettering
2012-09-16nspawn: use automatic cleanup for umaskZbigniew Jędrzejewski-Szmek
2012-09-14timedate: assorted improvementsLennart Poettering
- Make writing/reading of /etc/timezone dependendent of HAVE_SYSV_COMPAT - Introduce symlink_atomic() after all, and use it - Use relative symlink for /etc/localtime
2012-09-14util: various additional modernizationsLennart Poettering
2012-09-14util: modernize a few functions with automatic cleanup variablesLennart Poettering
Just trying to get the feel for it. And it's pretty cool.
2012-09-13macro: introduce _cleanup_free_ macro for automatic freeing of scoped vars ↵Lennart Poettering
and make use of it
2012-08-22journal: move syslog specific calls out of util.cLennart Poettering
2012-08-22journald: split /dev/kmsg related stuff into its own .c fileLennart Poettering
2012-08-09journald: properly unescape messages from /dev/kmsgLennart Poettering
2012-07-26cgtop: use full terminal widthZbigniew Jędrzejewski-Szmek
2012-07-19use #pragma once instead of foo*foo #define guardsShawn Landden
#pragma once has been "un-deprecated" in gcc since 3.3, and is widely supported in other compilers. I've been using and maintaining (rebasing) this patch for a while now, as it annoyed me to see #ifndef fooblahfoo, etc all over the place, almost arrogant about the annoyance of having to define all these names to perform a commen but neccicary functionality, when a completely superior alternative exists. I havn't sent it till now, cause its kindof a style change, and it is bad voodoo to mess with style that has been established by more established editors. So feel free to lambast me as a crazy bafoon. v2 - preserve externally used headers
2012-07-16unit: introduce %s specifier for the user shellLennart Poettering
2012-07-16util: add getusername_malloc(), get_shell(), get_home_dir()Lennart Poettering
2012-07-13util: rename join() to strjoin()Lennart Poettering
This is to match strappend() and the other string related functions.