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 b779855cf15d68f9038ff1809db18c0788e9ae70 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
6c148b4f8b
commit
e4f0b4ebf3
@ -44,6 +44,7 @@ global:
|
|||||||
open_psdb;
|
open_psdb;
|
||||||
open_psdb_message;
|
open_psdb_message;
|
||||||
openproc;
|
openproc;
|
||||||
|
page_bytes;
|
||||||
pretty_print_signals;
|
pretty_print_signals;
|
||||||
print_uptime;
|
print_uptime;
|
||||||
procps_version;
|
procps_version;
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
long smp_num_cpus; /* number of CPUs */
|
long smp_num_cpus; /* number of CPUs */
|
||||||
|
long page_bytes; /* this architecture's page size */
|
||||||
|
|
||||||
#define BAD_OPEN_MESSAGE \
|
#define BAD_OPEN_MESSAGE \
|
||||||
"Error: /proc must be mounted\n" \
|
"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 */
|
init_Linux_version(); /* Must be called before we check code */
|
||||||
|
|
||||||
cpuinfo();
|
cpuinfo();
|
||||||
|
page_bytes = sysconf(_SC_PAGESIZE);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
|
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
|
||||||
@ -661,6 +663,7 @@ void meminfo(void){
|
|||||||
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
|
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
|
||||||
|
|
||||||
kb_inactive = ~0UL;
|
kb_inactive = ~0UL;
|
||||||
|
kb_low_total = kb_main_available = 0;
|
||||||
|
|
||||||
head = buf;
|
head = buf;
|
||||||
for(;;){
|
for(;;){
|
||||||
@ -704,7 +707,7 @@ nextline:
|
|||||||
- watermark_low;
|
- watermark_low;
|
||||||
|
|
||||||
if (mem_available < 0) mem_available = 0;
|
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;
|
vm_pgsteal = vm_pgsteal_dma + vm_pgsteal_high + vm_pgsteal_normal;
|
||||||
|
|
||||||
FILE_TO_BUF(VM_MIN_FREE_FILE, vm_min_free_fd);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -9,6 +9,7 @@ EXTERN_C_BEGIN
|
|||||||
extern unsigned long long Hertz; /* clock tick frequency */
|
extern unsigned long long Hertz; /* clock tick frequency */
|
||||||
extern long smp_num_cpus; /* number of CPUs */
|
extern long smp_num_cpus; /* number of CPUs */
|
||||||
extern int have_privs; /* boolean, true if setuid or similar */
|
extern int have_privs; /* boolean, true if setuid or similar */
|
||||||
|
extern long page_bytes; /* this architecture's bytes per page */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define JT double
|
#define JT double
|
||||||
|
Loading…
x
Reference in New Issue
Block a user