summaryrefslogtreecommitdiff
path: root/src/cgtop
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #8149 from poettering/fake-root-cgroupLennart Poettering2018-03-011-38/+77
|\ | | | | Properly synthesize CPU+memory accounting data for the root cgroup
| * cgroup-util: rework cg_get_keyed_attribute() a bitLennart Poettering2018-02-091-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Let's make sure we don't clobber the return parameter on failure, to follow our coding style. Also, break the loop early if we have all attributes we need. This also changes the keys parameter to a simple char**, so that we can use STRV_MAKE() for passing the list of attributes to read. This also makes it possible to distuingish the case when the whole attribute file doesn't exist from one key in it missing. In the former case we return -ENOENT, in the latter we now return -ENXIO.
| * cgtop: hook up new /proc based emulation code for root cgroup memory/cpu statsLennart Poettering2018-02-091-16/+27
| | | | | | | | Let's make this work.
| * cgtop: tweak root cgroup detection a bitLennart Poettering2018-02-091-1/+23
| | | | | | | | | | Inside a cgroup-namespaced container we shouldn't assume that "/" is really the root cgroup, because it generally is not.
| * cgtop: command line parsing improvementsLennart Poettering2018-02-091-13/+7
| | | | | | | | | | Always output the string we were unable to parse and use log_error_errno()'s return logic to shorten our code a bit.
| * cgtop: add helper for checking if we are operating on the root cgroupLennart Poettering2018-02-091-1/+5
| |
| * cgtop: add "-1" as shortcut for "--iterations=1"Lennart Poettering2018-02-091-1/+6
| | | | | | | | | | This is most likely the most useful use of --iterations, and such use for numeric parameters has precedents, let's make this work for cgtop too.
| * cgtop: correctly order root cgroup always to the topLennart Poettering2018-02-091-3/+7
| | | | | | | | | | | | | | | | Internally, we encode the root cgroup as empty string. However, path_compare() is allergic to comparing absolute and relative paths. Let's clean this up, by always uses "/" as path for the root cgroup when comparing.
* | tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-02-121-2/+2
|/ | | | | | path Let's make use of our new hash_ops!
* cgtop: make sure we can show a tasks number for the root cgroup tooLennart Poettering2018-01-221-12/+20
| | | | | Let's also use our new API in cgtop so that we can finally show a usable tasks count for the root cgroup too. Yay!
* cgtop: minor modernizationLennart Poettering2018-01-221-1/+2
|
* Add set/hashmap helpers for non-trivial freeing and use where straighforwardZbigniew Jędrzejewski-Szmek2017-11-281-4/+1
| | | | | | A macro is needed because otherwise we couldn't ensure type safety. Some simple tests are included. No functional change intended.
* 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.
* build-sys: drop automake supportZbigniew Jędrzejewski-Szmek2017-07-181-1/+0
| | | | | v2: - also mention m4
* cgtop: check cgroups after parsing optionsZbigniew Jędrzejewski-Szmek2017-04-251-10/+10
| | | | | | | | | | | | We would try to determine controllers even if not necessary: <mock-chroot><mock-chroot> sh-4.4# ./systemd-cgtop --help Failed to determine supported controllers: No medium found <mock-chroot><mock-chroot> sh-4.4# ./systemd-cgtop --version Failed to determine supported controllers: No medium found This broke check-help-systemd-cgtop under mock, but even apart from that, the program should be able to print --version in any circumstances.
* cgtop: use PRIu64 to print uint64_t (#5544)Thomas H. P. Andersen2017-03-071-1/+1
| | | | Commit 59f448cf replaced usage of off_t with uint64_t. Change the format string to use PRIu64 to match it.
* cgroup: change cg_unified() to possibly return errors againLennart Poettering2017-02-241-9/+13
| | | | | | | | | We use our cgroup APIs in various contexts, including from our libraries sd-login, sd-bus. As we don#t control those environments we can't rely that the unified cgroup setup logic succeeds, and hence really shouldn't assert on it. This more or less reverts 415fc41ceaeada2e32639f24f134b1c248b9e43f.
* core: simplify cg_[all_]unified()Tejun Heo2017-02-181-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | cg_[all_]unified() test whether a specific controller or all controllers are on the unified hierarchy. While what's being asked is a simple binary question, the callers must assume that the functions may fail any time, which unnecessarily complicates their usages. This complication is unnecessary. Internally, the test result is cached anyway and there are only a few places where the test actually needs to be performed. This patch simplifies cg_[all_]unified(). * cg_[all_]unified() are updated to return bool. If the result can't be decided, assertion failure is triggered. Error handlings from their callers are dropped. * cg_unified_flush() is updated to calculate the new result synchrnously and return whether it succeeded or not. Places which need to flush the test result are updated to test for failure. This ensures that all the following cg_[all_]unified() tests succeed. * Places which expected possible cg_[all_]unified() failures are updated to call and test cg_unified_flush() before calling cg_[all_]unified(). This includes functions used while setting up mounts during boot and manager_setup_cgroup().
* cgtop: use common function to query cgroup rootZbigniew Jędrzejewski-Szmek2017-02-011-61/+6
| | | | | | | | | | | show_cgroup_get_root_and_warn is renamed to show_cgroup_get_path_and_warn because it now optionally allows querying a non-root path. This removes duplicated code and teaches cgtop to combine -M with a root prefix: $ systemd-cgtop -M myprecious /system.slice ...
* tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2016-10-231-1/+1
| | | | | | | | | | | | | This makes strjoin and strjoina more similar and avoids the useless final argument. spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c) git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/' This might have missed a few cases (spatch has a really hard time dealing with _cleanup_ macros), but that's no big issue, they can always be fixed later.
* core: rename cg_unified() to cg_all_unified()Tejun Heo2016-08-151-5/+5
| | | | | | | | | | | A following patch will update cgroup handling so that the systemd controller (/sys/fs/cgroup/systemd) can use the unified hierarchy even if the kernel resource controllers are on the legacy hierarchies. This would require distinguishing whether all controllers are on cgroup v2 or only the systemd controller is. In preparation, this patch renames cg_unified() to cg_all_unified(). This patch doesn't cause any functional changes.
* core: add cgroup CPU controller support on the unified hierarchyTejun Heo2016-08-071-12/+38
| | | | | | | | | | | | | | | | | | | | | | | | | Unfortunately, due to the disagreements in the kernel development community, CPU controller cgroup v2 support has not been merged and enabling it requires applying two small out-of-tree kernel patches. The situation is explained in the following documentation. https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup-v2-cpu.txt?h=cgroup-v2-cpu While it isn't clear what will happen with CPU controller cgroup v2 support, there are critical features which are possible only on cgroup v2 such as buffered write control making cgroup v2 essential for a lot of workloads. This commit implements systemd CPU controller support on the unified hierarchy so that users who choose to deploy CPU controller cgroup v2 support can easily take advantage of it. On the unified hierarchy, "cpu.weight" knob replaces "cpu.shares" and "cpu.max" replaces "cpu.cfs_period_us" and "cpu.cfs_quota_us". [Startup]CPUWeight config options are added with the usual compat translation. CPU quota settings remain unchanged and apply to both legacy and unified hierarchies. v2: - Error in man page corrected. - CPU config application in cgroup_context_apply() refactored. - CPU accounting now works on unified hierarchy.
* cgtop: minimize aux variable scopeLennart Poettering2016-06-061-1/+3
|
* cgtop: fix ret pointer usage (#3443)Alessandro Puccetti2016-06-061-2/+4
|
* cgtop: add option to show a single cgroup subtree (#3413)Alessandro Puccetti2016-06-051-2/+16
| | | | When many services are running, it was difficult to see only the interesting ones. This patch allows to show only the subtree of interest.
* pager: don't start pager if the terminal is explicitly set to TERM=dumbLennart Poettering2016-05-301-1/+1
| | | | | | | | | As suggested here: https://bugs.freedesktop.org/show_bug.cgi?id=64737#c8 This adds a new call terminal_is_dumb() and makes use of this where appropriate.
* core: add io controller support on the unified hierarchyTejun Heo2016-05-051-16/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On the unified hierarchy, blkio controller is renamed to io and the interface is changed significantly. * blkio.weight and blkio.weight_device are consolidated into io.weight which uses the standardized weight range [1, 10000] with 100 as the default value. * blkio.throttle.{read|write}_{bps|iops}_device are consolidated into io.max. Expansion of throttling features is being worked on to support work-conserving absolute limits (io.low and io.high). * All stats are consolidated into io.stats. This patchset adds support for the new interface. As the interface has been revamped and new features are expected to be added, it seems best to treat it as a separate controller rather than trying to expand the blkio settings although we might add automatic translation if only blkio settings are specified. * io.weight handling is mostly identical to blkio.weight[_device] handling except that the weight range is different. * Both read and write bandwidth settings are consolidated into CGroupIODeviceLimit which describes all limits applicable to the device. This makes it less painful to add new limits. * "max" can be used to specify the maximum limit which is equivalent to no config for max limits and treated as such. If a given CGroupIODeviceLimit doesn't contain any non-default configs, the config struct is discarded once the no limit config is applied to cgroup. * lookup_blkio_device() is renamed to lookup_block_device(). Signed-off-by: Tejun Heo <htejun@fb.com>
* cgtop: initialize `ours' to NULL properly (#3139)Naohiro Aota2016-04-281-1/+1
| | | | | | | | | | | Running cgtop on a system, which lacks expecting stat file, results in a segfault. For example, a system with blkio tree but without cfq io scheduler, lacks "blkio.io_service_bytes". When the targeting cgroup's file does not exist, process() returns 0 and also does not modify `*ret' value (which is `*ours'). As a result, callers of refresh_one() can have bogus pointer, which result in SEGV. This patch just properly initialize the variable to NULL.
* tree-wide: make more global variables staticLennart Poettering2016-02-131-2/+2
| | | | let's export as little as we can
* 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.
* tree-wide: use xsprintf() where applicableDaniel Mack2016-01-121-2/+3
| | | | Also add a coccinelle receipt to help with such transitions.
* tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easyLennart Poettering2015-11-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GLIB has recently started to officially support the gcc cleanup attribute in its public API, hence let's do the same for our APIs. With this patch we'll define an xyz_unrefp() call for each public xyz_unref() call, to make it easy to use inside a __attribute__((cleanup())) expression. Then, all code is ported over to make use of this. The new calls are also documented in the man pages, with examples how to use them (well, I only added docs where the _unref() call itself already had docs, and the examples, only cover sd_bus_unrefp() and sd_event_unrefp()). This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we tend to call our destructors these days. Note that this defines no public macro that wraps gcc's attribute and makes it easier to use. While I think it's our duty in the library to make our stuff easy to use, I figure it's not our duty to make gcc's own features easy to use on its own. Most likely, client code which wants to make use of this should define its own: #define _cleanup_(function) __attribute__((cleanup(function))) Or similar, to make the gcc feature easier to use. Making this logic public has the benefit that we can remove three header files whose only purpose was to define these functions internally. See #2008.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-0/+1
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* bus-util: rename bus_open_transport() to bus_connect_transport()Lennart Poettering2015-09-291-1/+1
| | | | | | | | | | | | | | In sd-bus, the sd_bus_open_xyz() family of calls allocates a new bus, while sd_bus_default_xyz() family tries to reuse the thread's default bus. bus_open_transport() sometimes internally uses the former, sometimes the latter family, but suggests it only calls the former via its name. Hence, let's avoid this confusion, and generically rename the call to bus_connect_transport(). Similar for all related calls. And while we are at it, also change cgls + cgtop to do direct systemd connections where possible, since all they do is talk to systemd itself.
* util: introduce common version() implementation and use it everywhereLennart Poettering2015-09-291-17/+15
| | | | | | This also allows us to drop build.h from a ton of files, hence do so. Since we touched the #includes of those files, let's order them properly according to CODING_STYLE.
* cgtop: make sure help text doesn't cause main contents to moveLennart Poettering2015-09-221-1/+1
| | | | | Let's always keep space for the full help text. (We used to do that, but recently another line of help was added which broke this.)
* cgtop: underline table headerLennart Poettering2015-09-221-19/+25
| | | | | | Let's underline the header line of the table shown by cgtop, how it is customary for tables. In order to do this, let's introduce new ANSI underline macros, and clean up the existing ones as side effect.
* cgtop: add -M/--machineEvgeny Vereshchagin2015-09-211-2/+55
|
* Merge pull request #1239 from poettering/cgroup-pidsDaniel Mack2015-09-101-18/+89
|\ | | | | core: add support for the "pids" cgroup controller
| * core: add support for the "pids" cgroup controllerLennart Poettering2015-09-101-18/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds support for the new "pids" cgroup controller of 4.3 kernels. It allows accounting the number of tasks in a cgroup and enforcing limits on it. This adds two new setting TasksAccounting= and TasksMax= to each unit, as well as a gloabl option DefaultTasksAccounting=. This also updated "cgtop" to optionally make use of the new kernel-provided accounting. systemctl has been updated to show the number of tasks for each service if it is available. This patch also adds correct support for undoing memory limits for units using a MemoryLimit=infinity syntax. We do the same for TasksMax= now and hence keep things in sync here.
* | tree-wide: never use the off_t unless glibc makes us use itLennart Poettering2015-09-101-1/+1
|/ | | | | | | | | | | off_t is a really weird type as it is usually 64bit these days (at least in sane programs), but could theoretically be 32bit. We don't support off_t as 32bit builds though, but still constantly deal with safely converting from off_t to other types and back for no point. Hence, never use the type anymore. Always use uint64_t instead. This has various benefits, including that we can expose these values directly as D-Bus properties, and also that the values parse the same in all cases.
* core: unified cgroup hierarchy supportLennart Poettering2015-09-011-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch set adds full support the new unified cgroup hierarchy logic of modern kernels. A new kernel command line option "systemd.unified_cgroup_hierarchy=1" is added. If specified the unified hierarchy is mounted to /sys/fs/cgroup instead of a tmpfs. No further hierarchies are mounted. The kernel command line option defaults to off. We can turn it on by default as soon as the kernel's APIs regarding this are stabilized (but even then downstream distros might want to turn this off, as this will break any tools that access cgroupfs directly). It is possibly to choose for each boot individually whether the unified or the legacy hierarchy is used. nspawn will by default provide the legacy hierarchy to containers if the host is using it, and the unified otherwise. However it is possible to run containers with the unified hierarchy on a legacy host and vice versa, by setting the $UNIFIED_CGROUP_HIERARCHY environment variable for nspawn to 1 or 0, respectively. The unified hierarchy provides reliable cgroup empty notifications for the first time, via inotify. To make use of this we maintain one manager-wide inotify fd, and each cgroup to it. This patch also removes cg_delete() which is unused now. On kernel 4.2 only the "memory" controller is compatible with the unified hierarchy, hence that's the only controller systemd exposes when booted in unified heirarchy mode. This introduces a new enum for enumerating supported controllers, plus a related enum for the mask bits mapping to it. The core is changed to make use of this everywhere. This moves PID 1 into a new "init.scope" implicit scope unit in the root slice. This is necessary since on the unified hierarchy cgroups may either contain subgroups or processes but not both. PID 1 hence has to move out of the root cgroup (strictly speaking the root cgroup is the only one where processes and subgroups are still allowed, but in order to support containers nicey, we move PID 1 into the new scope in all cases.) This new unit is also used on legacy hierarchy setups. It's actually pretty useful on all systems, as it can then be used to filter journal messages coming from PID 1, and so on. The root slice ("-.slice") is now implicitly created and started (and does not require a unit file on disk anymore), since that's where "init.scope" is located and the slice needs to be started before the scope can. To check whether we are in unified or legacy hierarchy mode we use statfs() on /sys/fs/cgroup. If the .f_type field reports tmpfs we are in legacy mode, if it reports cgroupfs we are in unified mode. This patch set carefuly makes sure that cgls and cgtop continue to work as desired. When invoking nspawn as a service it will implicitly create two subcgroups in the cgroup it is using, one to move the nspawn process into, the other to move the actual container processes into. This is done because of the requirement that cgroups may either contain processes or other subgroups.
* cgtop: properly show "/" instead of empty string in cgroup listLennart Poettering2015-09-011-3/+5
|
* cgtop: rework error handlingLennart Poettering2015-08-311-14/+7
| | | | Never report errors twice.
* cgtop: allow toggling of --recursive= and -k at runtimeLennart Poettering2015-08-311-2/+16
|
* cgtop: recursively count cgroup member tasksLennart Poettering2015-08-311-25/+71
| | | | | | | | | When showing the number of tasks in a cgroup, recursively count tasks in child cgroups and include them in the number. This ensures that the number of tasks is cummulative the same way as memory, cpu and IO resources are. Old behaviour can be restored by passing the new --recursive=no switch.
* cgtop: ignore kernel threads when counting tasksLennart Poettering2015-08-311-2/+14
| | | | However, allow them to be counted in by specifying -k
* cgtop: show resource usage relative to cgroup root onlyLennart Poettering2015-08-311-6/+13
| | | | | This way the output is restricted to cgroups from a container when run in one.