Skip to content

Commit a073d4c

Browse files
authored
Merge branch 'htop-dev:main' into main
2 parents bc39b17 + ab455a2 commit a073d4c

20 files changed

+278
-67
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ jobs:
230230
- name: Compile
231231
uses: vmactions/freebsd-vm@v1
232232
with:
233-
release: '14.1'
233+
release: '14.2'
234234
usesh: true
235235
prepare: |
236236
pkg install -y gmake autoconf automake pkgconf git
@@ -251,11 +251,11 @@ jobs:
251251
- name: Compile
252252
uses: vmactions/netbsd-vm@v1
253253
with:
254-
release: '10.0'
254+
release: '10.1'
255255
usesh: true
256256
prepare: |
257257
PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
258-
PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.0/All/"
258+
PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.1/All/"
259259
export PATH PKG_PATH
260260
/usr/sbin/pkg_add pkgin
261261
pkgin -y install autoconf automake libtool ncurses pkg-config gmake git
@@ -276,7 +276,7 @@ jobs:
276276
- name: Compile
277277
uses: vmactions/openbsd-vm@v1
278278
with:
279-
release: '7.4'
279+
release: '7.6'
280280
usesh: true
281281
prepare: |
282282
pkg_add gmake git

DisplayOptionsPanel.c

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
149149
&(settings->showCPUTemperature)));
150150
Panel_add(super, (Object*) CheckItem_newByRef("- Show temperature in degree Fahrenheit instead of Celsius", &(settings->degreeFahrenheit)));
151151
#endif
152+
Panel_add(super, (Object*) CheckItem_newByRef("Show cached memory in graph and bar modes", &(settings->showCachedMemory)));
152153
#ifdef HAVE_GETMOUSE
153154
Panel_add(super, (Object*) CheckItem_newByRef("Enable the mouse", &(settings->enableMouse)));
154155
#endif

MemoryMeter.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ static void MemoryMeter_updateValues(Meter* this) {
3333
size_t size = sizeof(this->txtBuffer);
3434
int written;
3535

36+
Settings *settings = this->host->settings;
37+
3638
/* shared, compressed and available memory are not supported on all platforms */
3739
this->values[MEMORY_METER_SHARED] = NAN;
3840
this->values[MEMORY_METER_COMPRESSED] = NAN;
3941
this->values[MEMORY_METER_AVAILABLE] = NAN;
4042
Platform_setMemoryValues(this);
41-
43+
if ((this->mode == GRAPH_METERMODE || this->mode == BAR_METERMODE) && !settings->showCachedMemory) {
44+
this->values[MEMORY_METER_BUFFERS] = 0;
45+
this->values[MEMORY_METER_CACHE] = 0;
46+
}
4247
/* Do not print available memory in bar mode */
4348
static_assert(MEMORY_METER_AVAILABLE + 1 == MEMORY_METER_ITEMCOUNT,
4449
"MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues");

Settings.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ static bool Settings_read(Settings* this, const char* fileName, const Machine* h
466466
this->showCPUUsage = atoi(option[1]);
467467
} else if (String_eq(option[0], "show_cpu_frequency")) {
468468
this->showCPUFrequency = atoi(option[1]);
469+
} else if (String_eq(option[0], "show_cached_memory")) {
470+
this->showCachedMemory = atoi(option[1]);
469471
#ifdef BUILD_WITH_CPU_TEMP
470472
} else if (String_eq(option[0], "show_cpu_temperature")) {
471473
this->showCPUTemperature = atoi(option[1]);
@@ -650,11 +652,15 @@ int Settings_write(const Settings* this, bool onCrash) {
650652
xAsprintf(&tmpFilename, "%s.tmp.XXXXXX", this->filename);
651653
int fdtmp = mkstemp(tmpFilename);
652654
umask(cur_umask);
653-
if (fdtmp == -1)
655+
if (fdtmp == -1) {
656+
free(tmpFilename);
654657
return -errno;
658+
}
655659
fp = fdopen(fdtmp, "w");
656-
if (!fp)
660+
if (!fp) {
661+
free(tmpFilename);
657662
return -errno;
663+
}
658664
separator = '\n';
659665
of = fprintf;
660666
}
@@ -697,6 +703,7 @@ int Settings_write(const Settings* this, bool onCrash) {
697703
printSettingInteger("show_cpu_temperature", this->showCPUTemperature);
698704
printSettingInteger("degree_fahrenheit", this->degreeFahrenheit);
699705
#endif
706+
printSettingInteger("show_cached_memory", this->showCachedMemory);
700707
printSettingInteger("update_process_names", this->updateProcessNames);
701708
printSettingInteger("account_guest_in_cpu_meter", this->accountGuestInCPUMeter);
702709
printSettingInteger("color_scheme", this->colorScheme);
@@ -801,6 +808,7 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
801808
this->showCPUTemperature = false;
802809
this->degreeFahrenheit = false;
803810
#endif
811+
this->showCachedMemory = true;
804812
this->updateProcessNames = false;
805813
this->showProgramPath = true;
806814
this->highlightThreads = true;

Settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef struct Settings_ {
101101
bool accountGuestInCPUMeter;
102102
bool headerMargin;
103103
bool screenTabs;
104+
bool showCachedMemory;
104105
#ifdef HAVE_GETMOUSE
105106
bool enableMouse;
106107
#endif

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ AC_SUBST([AM_CPPFLAGS])
11091109
# We're done, let's go!
11101110
# ----------------------------------------------------------------------
11111111

1112-
AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2024 htop dev team."], [Copyright message.])
1112+
AC_DEFINE_UNQUOTED([COPYRIGHT], ["(C) 2004-2019 Hisham Muhammad. (C) 2020-2025 htop dev team."], [Copyright message.])
11131113

11141114
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
11151115
AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])

darwin/PlatformHelpers.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,12 @@ double Platform_calculateNanosecondsPerMachTick(void) {
103103
* the "Apple M1" chip specifically when running under Rosetta 2.
104104
*/
105105

106-
char cpuBrandString[1024] = "";
107-
Platform_getCPUBrandString(cpuBrandString, sizeof(cpuBrandString));
108-
109106
bool isRunningUnderRosetta2 = Platform_isRunningTranslated();
110107

111108
// Kernel version 20.0.0 is macOS 11.0 (Big Sur)
112109
bool isBuggedVersion = Platform_KernelVersionIsBetween((KernelVersion) {20, 0, 0}, (KernelVersion) {999, 999, 999});
113110

114-
if (isRunningUnderRosetta2 && String_eq(cpuBrandString, "Apple M1") && isBuggedVersion) {
111+
if (isRunningUnderRosetta2 && isBuggedVersion) {
115112
// In this case `mach_timebase_info` provides the wrong value, so we hard-code the correct factor,
116113
// as determined from `mach_timebase_info` when the process running natively.
117114
info = (mach_timebase_info_data_t) { .numer = 125, .denom = 3 };

dragonflybsd/DragonFlyBSDMachine.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,20 @@ static void DragonFlyBSDMachine_scanMemoryInfo(Machine* super) {
240240
sysctl(MIB_hw_physmem, 2, &(super->totalMem), &len, NULL, 0);
241241
super->totalMem /= 1024;
242242

243-
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(this->memActive), &len, NULL, 0);
244-
this->memActive *= this->pageSizeKb;
243+
unsigned long long int memActive = 0;
244+
sysctl(MIB_vm_stats_vm_v_active_count, 4, &memActive, &len, NULL, 0);
245+
memActive *= this->pageSizeKb;
245246

246-
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(this->memWire), &len, NULL, 0);
247-
this->memWire *= this->pageSizeKb;
247+
unsigned long long int memWire = 0;
248+
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &memWire, &len, NULL, 0);
249+
memWire *= this->pageSizeKb;
248250

249251
sysctl(MIB_vfs_bufspace, 2, &(super->buffersMem), &len, NULL, 0);
250252
super->buffersMem /= 1024;
251253

252254
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(super->cachedMem), &len, NULL, 0);
253255
super->cachedMem *= this->pageSizeKb;
254-
super->usedMem = this->memActive + this->memWire;
256+
super->usedMem = memActive + memWire;
255257

256258
struct kvm_swap swap[16];
257259
int nswap = kvm_getswapinfo(this->kd, swap, ARRAYSIZE(swap), 0);

dragonflybsd/DragonFlyBSDMachine.h

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ typedef struct DragonFlyBSDMachine_ {
4242
int pageSizeKb;
4343
int kernelFScale;
4444

45-
unsigned long long int memWire;
46-
unsigned long long int memActive;
47-
unsigned long long int memInactive;
48-
unsigned long long int memFree;
49-
5045
CPUData* cpus;
5146

5247
unsigned long* cp_time_o;

freebsd/FreeBSDMachine.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,21 @@ static void FreeBSDMachine_scanMemoryInfo(Machine* super) {
313313
// @etosan:
314314
// memory counter relationships seem to be these:
315315
// total = active + wired + inactive + cache + free
316-
// htop_used (unavail to anybody) = active + wired
317-
// htop_cache (for cache meter) = buffers + cache
318-
// user_free (avail to procs) = buffers + inactive + cache + free
316+
// htop_used (unavail to anybody) = active + wired + inactive - buffer
317+
// htop_cache (for cache meter) = buffer + cache
318+
// htop_user_free (avail to procs) = buffer + cache + free
319+
// htop_buffers (disk write buffer) = 0 (not applicable to FreeBSD)
320+
//
321+
// 'buffer' contain cache used by most file systems other than ZFS, and is
322+
// included in 'wired'
319323
//
320324
// with ZFS ARC situation becomes bit muddled, as ARC behaves like "user_free"
321325
// and belongs into cache, but is reported as wired by kernel
322326
//
323327
// htop_used = active + (wired - arc)
324328
// htop_cache = buffers + cache + arc
325329
u_long totalMem;
326-
u_int memActive, memWire, cachedMem;
330+
u_int memActive, memWire, memInactive, cachedMem;
327331
long buffersMem;
328332
size_t len;
329333
struct vmtotal vmtotal;
@@ -340,28 +344,30 @@ static void FreeBSDMachine_scanMemoryInfo(Machine* super) {
340344
len = sizeof(memActive);
341345
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(memActive), &len, NULL, 0);
342346
memActive *= this->pageSizeKb;
343-
this->memActive = memActive;
344347

345348
len = sizeof(memWire);
346349
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(memWire), &len, NULL, 0);
347350
memWire *= this->pageSizeKb;
348-
this->memWire = memWire;
351+
352+
len = sizeof(memInactive);
353+
sysctl(MIB_vm_stats_vm_v_inactive_count, 4, &(memInactive), &len, NULL, 0);
354+
memInactive *= this->pageSizeKb;
349355

350356
len = sizeof(buffersMem);
351357
sysctl(MIB_vfs_bufspace, 2, &(buffersMem), &len, NULL, 0);
352358
buffersMem /= 1024;
353-
super->buffersMem = buffersMem;
359+
super->cachedMem = buffersMem;
354360

355361
len = sizeof(cachedMem);
356362
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(cachedMem), &len, NULL, 0);
357363
cachedMem *= this->pageSizeKb;
358-
super->cachedMem = cachedMem;
364+
super->cachedMem += cachedMem;
359365

360366
len = sizeof(vmtotal);
361367
sysctl(MIB_vm_vmtotal, 2, &(vmtotal), &len, NULL, 0);
362368
super->sharedMem = vmtotal.t_rmshr * this->pageSizeKb;
363369

364-
super->usedMem = this->memActive + this->memWire;
370+
super->usedMem = memActive + memWire + memInactive - buffersMem;
365371

366372
struct kvm_swap swap[16];
367373
int nswap = kvm_getswapinfo(this->kd, swap, ARRAYSIZE(swap), 0);

freebsd/FreeBSDMachine.h

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ typedef struct FreeBSDMachine_ {
3636
int pageSizeKb;
3737
int kernelFScale;
3838

39-
unsigned long long int memWire;
40-
unsigned long long int memActive;
41-
4239
ZfsArcStats zfs;
4340

4441
CPUData* cpus;

htop.1.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "HTOP" "1" "2024" "@PACKAGE_STRING@" "User Commands"
1+
.TH "HTOP" "1" "2025" "@PACKAGE_STRING@" "User Commands"
22
.SH "NAME"
33
htop, pcp-htop \- interactive process viewer
44
.SH "SYNOPSIS"
@@ -702,7 +702,7 @@ communities, and forms part of the Performance Co-Pilot suite of tools.
702702
.SH "COPYRIGHT"
703703
Copyright \(co 2004-2019 Hisham Muhammad.
704704
.br
705-
Copyright \(co 2020-2024 htop dev team.
705+
Copyright \(co 2020-2025 htop dev team.
706706
.LP
707707
License GPLv2+: GNU General Public License version 2 or, at your option, any later version.
708708
.LP

0 commit comments

Comments
 (0)