library: tweak newly added MemAvailable fall-back code

This commit just ensures recalculation of some amounts
for iterative processes, like top. It also trades some
repeated runtime calls to sysconf for a one time cost.

Reference(s):
http://www.freelists.org/post/procps/systemd-support-to-library,7
. fall-back calculations
commit b779855cf1

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2014-07-17 11:11:11 -05:00 committed by Jaromir Capik
parent 6c148b4f8b
commit e4f0b4ebf3
3 changed files with 7 additions and 2 deletions

View File

@ -44,6 +44,7 @@ global:
open_psdb;
open_psdb_message;
openproc;
page_bytes;
pretty_print_signals;
print_uptime;
procps_version;

View File

@ -37,6 +37,7 @@
#endif
long smp_num_cpus; /* number of CPUs */
long page_bytes; /* this architecture's page size */
#define BAD_OPEN_MESSAGE \
"Error: /proc must be mounted\n" \
@ -277,6 +278,7 @@ static void init_libproc(void){
init_Linux_version(); /* Must be called before we check code */
cpuinfo();
page_bytes = sysconf(_SC_PAGESIZE);
#ifdef __linux__
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
@ -661,6 +663,7 @@ void meminfo(void){
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
kb_inactive = ~0UL;
kb_low_total = kb_main_available = 0;
head = buf;
for(;;){
@ -704,7 +707,7 @@ nextline:
- watermark_low;
if (mem_available < 0) mem_available = 0;
kb_main_available = (unsigned long)((unsigned long long)mem_available * sysconf(_SC_PAGESIZE) / 1024ull);
kb_main_available = (unsigned long)((unsigned long long)mem_available * page_bytes / 1024ull);
}
}
@ -888,7 +891,7 @@ nextline:
vm_pgsteal = vm_pgsteal_dma + vm_pgsteal_high + vm_pgsteal_normal;
FILE_TO_BUF(VM_MIN_FREE_FILE, vm_min_free_fd);
vm_min_free = (unsigned long) (strtoull(buf,&tail,10) * 1024ull / sysconf(_SC_PAGESIZE));
vm_min_free = (unsigned long) (strtoull(buf,&tail,10) * 1024ull / page_bytes);
}
///////////////////////////////////////////////////////////////////////

View File

@ -9,6 +9,7 @@ EXTERN_C_BEGIN
extern unsigned long long Hertz; /* clock tick frequency */
extern long smp_num_cpus; /* number of CPUs */
extern int have_privs; /* boolean, true if setuid or similar */
extern long page_bytes; /* this architecture's bytes per page */
#if 0
#define JT double