summaryrefslogtreecommitdiffstats
path: root/src/basic/mempool.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* mempool: fix tile alignment checkLennart Poettering2023-02-241-2/+4
| | | | | | | | | | We should check alignment *after* determining the pointer points into our pool, not before. Otherwise might might end up checking alignment of the pointer relative to our base, even though it is taken relative to some other base. Follow-up for: a2b052b29f8bc141e94a4af95d1653a38a57eaeb See: https://github.com/systemd/systemd/pull/26393#issuecomment-1442295012
* mempool: rework mempool_cleanup() to only release freed tilesLennart Poettering2023-02-171-7/+87
| | | | | | | | | | | | | | | | | | This substantially reworks mempool_cleanup() so that it releases pools with all freed tiles only, but keeps all pools with still-allocated tiles around. This is more correct, as the previous implementation just released all pools regardless if anything was still used or not. This would make valgrind shut up but would just hide memory leaks altogether. Moreover if called during regular runtime of a program would result in bad memory accesses all over. Hence, let's add a proper implementation and only trim pools we really know are empty. This way we can safely call these functions later, when under memory pressure, at any time.
* mempool: make mempool_free_tile() return NULLLennart Poettering2023-02-171-2/+9
| | | | | | | To match how we usually do this current allocation code. (Also, make it accept a NULL pointer, also in order to match behaviour in the rest of our codebase)
* mempool: introduce new helper pool_ptr()Lennart Poettering2023-02-171-1/+5
| | | | | | | This new helper returns the beginning of the usable area of the pool object. For now this is only used once, a later commit will use it more.
* mempool: rename local variable to match current coding styleLennart Poettering2023-02-171-4/+5
|
* hashmap: expose helper for releasing memory pools independently of valgrindLennart Poettering2023-02-171-2/+0
| | | | | Let's clean this up and export this always, so that we can later call when we are under memory pressure.
* Turn mempool_enabled() into a weak symbolZbigniew Jędrzejewski-Szmek2022-06-291-17/+0
| | | | | | | | | | | | | | | Before we had the following scheme: mempool_enabled() would check mempool_use_allowed, and libsystemd-shared would be linked with a .c file that provides mempool_use_allowed=true, while other things would linked with a different .c file with mempool_use_allowed=false. In the new scheme, mempool_enabled() itself is a weak symbol. If it's not found, we assume false. So it only needs to be provided for libsystemd-shared, where it can return false or true. test-set-disable-mempool is libshared, so it gets the symbol. But then we actually disable the mempool via envvar. mempool_enable() is called to check its return value directly.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* util: split out memcmp()/memset() related calls into memory-util.[ch]Lennart Poettering2019-03-131-0/+1
| | | | Just some source rearranging.
* mempool: only enable mempool use when linked to libsystemd-shared.soZbigniew Jędrzejewski-Szmek2018-10-111-0/+2
| | | | | | | | | | | Mempool use is enabled or disabled based on the mempool_use_allowed symbol that is linked in. Should fix assert crashes in external programs caused by #9792. Replaces #10286. v2: - use two different source files instead of a gcc constructor
* Move use_pool() to mempool.c and rename to mempool_enabled()Zbigniew Jędrzejewski-Szmek2018-10-111-2/+14
| | | | The only user is in hashmap.c, but it's a mempool thing.
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-06-201-3/+0
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-1/+1
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-1/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* Turn VALGRIND variable into a meson configuration switchZbigniew Jędrzejewski-Szmek2018-05-171-1/+1
| | | | | | | | | | Configuration through environment variable is inconvenient with meson, because they cannot be convieniently changed and/or are not preserved during reconfiguration (https://github.com/mesonbuild/meson/issues/1503). This adds -Dvalgrind=true/false, which has the advantage that it can be set at any time with meson configure -Dvalgrind=... and ninja will rebuild targets as necessary. Additional minor advantages are better consistency with the options for hashmap debugging, and typo avoidance with '#if' instead of '#ifdef'.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-0/+3
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* tree-wide: sort includesThomas Hindoe Paaboel Andersen2015-11-161-1/+1
| | | | Sort the includes accoding to the new coding style.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-0/+103
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/