For now, the semantics are mostly fit for Linux zswap subsystem. For
instance, we add the third swap usage metric that indicates the amount
of memory that is accounted to swap but in fact stored elsewhere. This
exactly matches the definition of frontswap/zswap, and is probably of
little use to all other platforms.
This removes the duplication of dynamic meter/column hashtable
pointers that has come in between the Settings and ProcessList
structures - only one copy of these is needed. With the future
planned dynamic screens feature adding another pointer, let us
first clean this up before any further duplication happens.
Below is a small example of two threads program, whose main thread
statistics is incorrect in htop. Despite main thread is permanently
sleeping, its CPU load is 100% (must be 0%). CPU load of secondary
thread is correct (100%).
void *thread_func(void *data)
{
while(1) {
}
return NULL;
}
int main()
{
pthread_t thread;
pthread_create(&thread, NULL, thread_func, NULL);
pthread_join(thread, NULL);
}
The reason is in there is a difference in behavior of some files
in /proc/pid and /proc/pid/task/pid directories. For example,
/proc/pid/stat shows agregated user and sys times for all threads
of a process. For the details please see do_task_stat() implementation
and this function behavior difference in dependence of last argument:
https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/array.c#L652
So, the problem occurs because of user and sys times of main thread are
polluted by secondary thread statistics. This patch fixes the problem
by reading correct stat from /proc/pid/task/pid/stat for main thread.
Looking at other files from /proc/pid directory I found /proc/pid/io
file with the same problem:
https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/base.c#L3029
This problem is also fixed in this patch by reading correct data
from /proc/pid/task/pid/io file for main thread.
/proc/pid directory files are declared in tgid_base_stuff, while
/proc/pid/task/tid directory files are declared in tid_base_stuff
in kernel's fs/proc/base.c file:
https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/base.c#L3238
I checked the difference between rest of declarations and it looks like
there is no more problems of such type affecting htop.
LXC shows the real host CPU ids but can be limited in configuration
as to which cores are used. Still the sysfs files are visible and the
CPUs (stay) marked online. We will need to parse
/sys/devices/system/cpu/online to follow LXC's logic.
Revert for now until we can come up with a better handling of the LXC hacks.
Cf. issue #1195
Essentially reverting 33973f7e and 0d53245c (#993, #995)
The linux kernel recently gained a new PSI meter, namely
a new /proc/pressure/irq meter has been added [1]:
full avg10=0.00 avg60=0.00 avg300=0.00 total=100648410
This commit adds support for this PSI meter by adding a
PressureStallIRQFullMeter_class.
[1] 52b1364ba0
Highlight processes started from binaries with file capabilities set,
like kwin_wayland, or retaining Linux capabilities, via the ambient set,
after switching from the root user, e.g. rtkit.
Merge parsing /proc/<pid>/status for context switches, vserver ID and
container detection into one function.
(OpenVZ still does a separate cycle but is left as an exercise for
someone actually using it.)
Add a process column for scheduling policy to show the current
scheduling policy of the process.
Add a the ability to change the scheduling policy of a process via the
key 'Y'.
Currently implemented on Linux and FreeBSD only but should be portable,
since sched_getscheduler(2) is part of POSIX.1-2001.
Closes: #1161
It's an artefact of the previous implementation of
Platform_getProcessLocks for Linux, and is never used;
there's no reason for it to have ever been exported
Instead of filtering the global /proc/locks by PID-that-locked
(which is different than the process that holds it for inherited
flock(2)s and always literal -1 for fcntl(F_OFD_SETLK)s),
just look at the locks on open files
For a process with:
$ head /proc/$$/fdinfo/{9,10,11}
==> /proc/797393/fdinfo/9 <==
pos: 0
flags: 0100000
mnt_id: 2775
lock: 1: FLOCK ADVISORY WRITE 818754 00:69:7 0 EOF
==> /proc/797393/fdinfo/10 <==
pos: 0
flags: 0100000
mnt_id: 127
lock: 1: FLOCK ADVISORY WRITE 828244 00:30:509028 0 EOF
lock: 2: OFDLCK ADVISORY READ -1 00:30:509028 0 199
==> /proc/797393/fdinfo/11 <==
pos: 0
flags: 0100000
mnt_id: 2775
lock: 1: FLOCK ADVISORY WRITE 935925 00:69:1187 0 EOF
Instead of:
No locks have been found for the selected process.
I now observe:
1 FLOCK ADVISORY WRITE 00:30:00000000000000509028 0 <END OF FILE> /home/nabijaczleweli/.feeds
1 FLOCK ADVISORY WRITE 00:69:00000000000000000007 0 <END OF FILE> /home/nabijaczleweli/uwu/mart.html
1 FLOCK ADVISORY WRITE 00:69:00000000000000001187 0 <END OF FILE> /home/nabijaczleweli/uwu/removedfile (deleted)
2 OFDLCK ADVISORY READ 00:30:00000000000000509028 0 199 /home/nabijaczleweli/.feeds
This also fixes an obvious issue where the filename for fd 0 would
never be resolved
This includes:
- Wrap function implementations
- Pointer alignment for function signatures
- Pointer alignment for variable declarations
- Whitespace after keywords
- Whitespace after comma
- Whitespace around initializers
- Whitespace around operators
- Code indentation
- Line break for single line statements
- Misleading alignment
Add actionToggle and fix LinuxProcessList_checkPidNamespace
Read cgroup file irrespective of flags
Improve logic to check if running in container
Add isContainerOrVMSlice()
Also change "(Process *)lp" to "proc"
Remove check for root slice
Remove Process_isRunningInContainer
Co-authored-by: BenBE <BenBE@geshi.org>
linux/LinuxProcessList.c:1094:52: error: format specifies type 'char *' but the argument has type 'openat_arg_t' (aka 'int') [-Werror,-Wformat]
xSnprintf(filename, sizeof(filename), "%s/cwd", procFd);
~~ ^~~~~~
%d
linux/LinuxProcessList.c:1333:44: error: format specifies type 'char *' but the argument has type 'openat_arg_t' (aka 'int') [-Werror,-Wformat]
xSnprintf(path, sizeof(path), "%s/exe", procFd);
~~ ^~~~~~
%d
Supersedes: #1025
Searching man systemd(1) for "is-system-running" we see these states:
initializing
starting
running
degraded
maintenance
stopping
offline
unknown
Let's differentiate some more: green (ok) if state is "running", red (error)
if the state is unknown to htop or "degraded", yellow (warning) for
everything else (incl. "initializing", "starting", "maintenance" &
"stopping").
CRT.c:1015:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void CRT_done() {
^
void
Title width of "CPUD%" and "SWAPD%" is 5 and there value cannot go
beyond "100.0%", so increase their field width to 5.
"IOD%" is similar to "MEM%" column, title width is 4 and maximum value
cannot go beyond "100.0%". So in case of "IOD%" column, there is no need
to increase title width to "5". "Process_printPercentage()" function
will handle the maximum value case, it will display value beyond "99.9%"
as "100" instead of "100.0".
Since commit edf319e[1], we're dynamically adjusting column width of
"CPU%", showing single digit precision also for values greater than
"99.9%" makes "CPU%" column consistent with all other values.
[1]: edf319e53d
Change "Process_printPercentage()" function's logic to always display
value (i.e. "val") with single precision. Except when value is greater
than "99.9%" for columns like "MEM%", whose width is fixed to "4" and
value cannot go beyond "100%".
Credits: @Explorer09, thanks for the patch[2] to fix title alignment
issue.
[2]: https://github.com/htop-dev/htop/pull/959#issuecomment-1092480951Closes: #957
If a process goes away while reading its fields, but we already have
that process in the list, we should keep it in case the "highlight dying
processes" mode is active. Not only is that expected in this mode, but
this should also ensure parents are in the list when their children are
(wanted for tree mode consistency).
A process can die between reading the directory listing and opening the
directory FD (if HAVE_OPENAT) or /proc files (otherwise) for reading the
process data. This race would cause LinuxProcessList_recurseProcTree to
remove it from the list immediately, which is unexpected in the
"highlight dying processes" mode and can break the tree structure.
This patch closes this race in the HAVE_OPENAT case by only accessing
the process entry after the directory FD has been opened.
man sscanf(3):
A sequence of white-space characters (space, tab, newline, etc.; see isspace(3)).
This directive matches any amount of white space, including none, in the input.
At the moment this is used to make the memory meter report sane values even
if the host has ZFS and that leaks through into a containerized environment
Fixes#863
Includes a clever check for magic PROC_PID_INIT_INO in /proc/self/ns/pid thanks to Pavel Snajdr (snajpa)