Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Add ZFS cache awareness to memory meters. #976

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ else
[AC_CHECK_HEADERS([ncurses.h],[:],[missing_headers="$missing_headers $ac_header"])])])])
fi

AC_ARG_ENABLE(zfs_cache_awareness, [AC_HELP_STRING([--enable-zfs-cache-awareness],[enable ZFS cache awareness for memory usage])], enable_zfs_cache_awareness="yes",enable_zfs_cache_awareness="no")
if test "x$enable_zfs_cache_awareness" = xyes; then
AC_DEFINE(HAVE_ZFS, 1, [Define if we want the memory meter to be aware of the ZFS cache])
fi

if test "$my_htop_platform" = "freebsd"; then
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
fi
Expand Down
30 changes: 29 additions & 1 deletion linux/LinuxProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ typedef struct LinuxProcessList_ {
#define PROCMEMINFOFILE PROCDIR "/meminfo"
#endif

#ifndef ZFSINFOFILE
#define ZFSINFOFILE "/proc/spl/kstat/zfs/arcstats"
#endif

#ifndef PROCTTYDRIVERSFILE
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
#endif

#ifndef PROC_LINE_LENGTH
#define PROC_LINE_LENGTH 4096
#endif

}*/

#ifndef CLAMP
Expand Down Expand Up @@ -958,6 +961,31 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
#undef tryRead
}

#ifdef HAVE_ZFS
FILE* zfsFile = fopen(ZFSINFOFILE,"r");
if( zfsFile != NULL)
{
unsigned long long int zfsMem = 0;
while(fgets(buffer,128,zfsFile) && zfsMem == 0)
{
switch(buffer[0])
{
case 's':
if(String_startsWith(buffer, "size"))
sscanf(buffer,"size %*i %32llu",&zfsMem);
zfsMem /= 1024;
break;
default:
break;
}
}
this->cachedMem += zfsMem;
fclose(zfsFile);
}
#endif



this->usedMem = this->totalMem - this->freeMem;
this->cachedMem = this->cachedMem + sreclaimable - shmem;
this->usedSwap = this->totalSwap - swapFree;
Expand Down
4 changes: 4 additions & 0 deletions linux/LinuxProcessList.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ typedef struct LinuxProcessList_ {
#define PROCMEMINFOFILE PROCDIR "/meminfo"
#endif

#ifndef ZFSINFOFILE
#define ZFSINFOFILE "/proc/spl/kstat/zfs/arcstats"
#endif

#ifndef PROCTTYDRIVERSFILE
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
#endif
Expand Down