malloc error

This commit is contained in:
albert 2003-01-23 05:48:27 +00:00
parent e092b7a18d
commit 0a03eac352
6 changed files with 155 additions and 149 deletions

View File

@ -22,6 +22,7 @@
#include "procps.h"
#include "version.h"
#include "sysinfo.h" /* smp_num_cpus */
#include "wchan.h" // to verify prototypes
#define KSYMS_FILENAME "/proc/ksyms"

View File

@ -1,5 +1,5 @@
// Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
// Copyright 1998-2002 Albert Cahalan
// Copyright 1998-2003 Albert Cahalan
//
// This file is placed under the conditions of the GNU Library
// General Public License, version 2, or any later version.
@ -283,7 +283,7 @@ void loadavg(double *restrict av1, double *restrict av5, double *restrict av15)
typedef struct mem_table_struct {
const char *name; /* memory type name */
unsigned *slot; /* slot in return struct */
unsigned long *slot; /* slot in return struct */
} mem_table_struct;
static int compare_mem_table_structs(const void *a, const void *b){
@ -316,41 +316,45 @@ static int compare_mem_table_structs(const void *a, const void *b){
* Committed_AS: 8440 kB 2.5.41+
* PageTables: 304 kB 2.5.41+
* ReverseMaps: 5738 2.5.41+
* SwapCached: 0 kB 2.5.??+
* HugePages_Total: 220 2.5.??+
* HugePages_Free: 138 2.5.??+
* Hugepagesize: 4096 kB 2.5.??+
*/
/* obsolete */
unsigned kb_main_shared;
unsigned long kb_main_shared;
/* old but still kicking -- the important stuff */
unsigned kb_main_buffers;
unsigned kb_main_cached;
unsigned kb_main_free;
unsigned kb_main_total;
unsigned kb_swap_free;
unsigned kb_swap_total;
unsigned long kb_main_buffers;
unsigned long kb_main_cached;
unsigned long kb_main_free;
unsigned long kb_main_total;
unsigned long kb_swap_free;
unsigned long kb_swap_total;
/* recently introduced */
unsigned kb_high_free;
unsigned kb_high_total;
unsigned kb_low_free;
unsigned kb_low_total;
unsigned long kb_high_free;
unsigned long kb_high_total;
unsigned long kb_low_free;
unsigned long kb_low_total;
/* 2.4.xx era */
unsigned kb_active;
unsigned kb_inact_laundry;
unsigned kb_inact_dirty;
unsigned kb_inact_clean;
unsigned kb_inact_target;
unsigned kb_swap_cached; /* late 2.4 only */
unsigned long kb_active;
unsigned long kb_inact_laundry;
unsigned long kb_inact_dirty;
unsigned long kb_inact_clean;
unsigned long kb_inact_target;
unsigned long kb_swap_cached; /* late 2.4 only */
/* derived values */
unsigned kb_swap_used;
unsigned kb_main_used;
unsigned long kb_swap_used;
unsigned long kb_main_used;
/* 2.5.41+ */
unsigned kb_writeback;
unsigned kb_slab;
unsigned nr_reversemaps;
unsigned kb_committed_as;
unsigned kb_dirty;
unsigned kb_inactive;
unsigned kb_mapped;
unsigned kb_pagetables;
unsigned long kb_writeback;
unsigned long kb_slab;
unsigned long nr_reversemaps;
unsigned long kb_committed_as;
unsigned long kb_dirty;
unsigned long kb_inactive;
unsigned long kb_mapped;
unsigned long kb_pagetables;
void meminfo(void){
char namebuf[16]; /* big enough to hold any row name */
@ -359,37 +363,37 @@ void meminfo(void){
char *head;
char *tail;
static const mem_table_struct mem_table[] = {
{"Active", &kb_active},
{"Buffers", &kb_main_buffers},
{"Cached", &kb_main_cached},
{"Active", &kb_active}, // important
{"Buffers", &kb_main_buffers}, // important
{"Cached", &kb_main_cached}, // important
{"Committed_AS", &kb_committed_as},
{"Dirty", &kb_dirty},
{"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty
{"HighFree", &kb_high_free},
{"HighTotal", &kb_high_total},
{"Inact_clean", &kb_inact_clean},
{"Inact_dirty", &kb_inact_dirty},
{"Inact_laundry",&kb_inact_laundry},
{"Inact_target", &kb_inact_target},
{"Inactive", &kb_inactive},
{"Inactive", &kb_inactive}, // important
{"LowFree", &kb_low_free},
{"LowTotal", &kb_low_total},
{"Mapped", &kb_mapped},
{"MemFree", &kb_main_free},
{"MemShared", &kb_main_shared},
{"MemTotal", &kb_main_total},
{"PageTables", &kb_pagetables},
{"ReverseMaps", &nr_reversemaps},
{"Slab", &kb_slab},
{"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped
{"MemFree", &kb_main_free}, // important
{"MemShared", &kb_main_shared}, // important
{"MemTotal", &kb_main_total}, // important
{"PageTables", &kb_pagetables}, // kB version of vmstat nr_page_table_pages
{"ReverseMaps", &nr_reversemaps}, // same as vmstat nr_page_table_pages
{"Slab", &kb_slab}, // kB version of vmstat nr_slab
{"SwapCached", &kb_swap_cached},
{"SwapFree", &kb_swap_free},
{"SwapTotal", &kb_swap_total},
{"Writeback", &kb_writeback}
{"SwapFree", &kb_swap_free}, // important
{"SwapTotal", &kb_swap_total}, // important
{"Writeback", &kb_writeback}, // kB version of vmstat nr_writeback
};
const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct);
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
kb_inactive = ~0U;
kb_inactive = ~0UL;
head = buf;
for(;;){
@ -416,7 +420,7 @@ nextline:
kb_low_total = kb_main_total;
kb_low_free = kb_main_free;
}
if(kb_inactive==~0U){
if(kb_inactive==~0UL){
kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry;
}
kb_swap_used = kb_swap_total - kb_swap_free;
@ -429,38 +433,39 @@ nextline:
typedef struct vm_table_struct {
const char *name; /* VM statistic name */
unsigned *slot; /* slot in return struct */
unsigned long *slot; /* slot in return struct */
} vm_table_struct;
static int compare_vm_table_structs(const void *a, const void *b){
return strcmp(((const vm_table_struct*)a)->name,((const vm_table_struct*)b)->name);
}
unsigned vm_nr_dirty; // dirty writable pages
unsigned vm_nr_writeback; // pages under writeback
unsigned vm_nr_pagecache; // pages in pagecache
unsigned vm_nr_page_table_pages;// pages used for pagetables
unsigned vm_nr_reverse_maps; // includes PageDirect
unsigned vm_nr_mapped; // mapped into pagetables
unsigned vm_nr_slab; // in slab
unsigned vm_pgpgin; // disk reads (same as 1st num on /proc/stat page line)
unsigned vm_pgpgout; // disk writes (same as 2nd num on /proc/stat page line)
unsigned vm_pswpin; // swap reads (same as 1st num on /proc/stat swap line)
unsigned vm_pswpout; // swap writes (same as 2nd num on /proc/stat swap line)
unsigned vm_pgalloc; // page allocations
unsigned vm_pgfree; // page freeings
unsigned vm_pgactivate; // pages moved inactive -> active
unsigned vm_pgdeactivate; // pages moved active -> inactive
unsigned vm_pgfault; // total faults (major+minor)
unsigned vm_pgmajfault; // major faults
unsigned vm_pgscan; // pages scanned by page reclaim
unsigned vm_pgrefill; // inspected by refill_inactive_zone
unsigned vm_pgsteal; // total pages reclaimed
unsigned vm_kswapd_steal; // pages reclaimed by kswapd
// see include/linux/page-flags.h and mm/page_alloc.c
unsigned long vm_nr_dirty; // dirty writable pages
unsigned long vm_nr_writeback; // pages under writeback
unsigned long vm_nr_pagecache; // pages in pagecache
unsigned long vm_nr_page_table_pages;// pages used for pagetables
unsigned long vm_nr_reverse_maps; // includes PageDirect
unsigned long vm_nr_mapped; // mapped into pagetables
unsigned long vm_nr_slab; // in slab
unsigned long vm_pgpgin; // kB disk reads (same as 1st num on /proc/stat page line)
unsigned long vm_pgpgout; // kB disk writes (same as 2nd num on /proc/stat page line)
unsigned long vm_pswpin; // swap reads (same as 1st num on /proc/stat swap line)
unsigned long vm_pswpout; // swap writes (same as 2nd num on /proc/stat swap line)
unsigned long vm_pgalloc; // page allocations
unsigned long vm_pgfree; // page freeings
unsigned long vm_pgactivate; // pages moved inactive -> active
unsigned long vm_pgdeactivate; // pages moved active -> inactive
unsigned long vm_pgfault; // total faults (major+minor)
unsigned long vm_pgmajfault; // major faults
unsigned long vm_pgscan; // pages scanned by page reclaim
unsigned long vm_pgrefill; // inspected by refill_inactive_zone
unsigned long vm_pgsteal; // total pages reclaimed
unsigned long vm_kswapd_steal; // pages reclaimed by kswapd
// next 3 as defined by the 2.5.52 kernel
unsigned vm_pageoutrun; // times kswapd ran page reclaim
unsigned vm_allocstall; // times a page allocator ran direct reclaim
unsigned vm_pgrotated; // pages rotated to the tail of the LRU for immediate reclaim
unsigned long vm_pageoutrun; // times kswapd ran page reclaim
unsigned long vm_allocstall; // times a page allocator ran direct reclaim
unsigned long vm_pgrotated; // pages rotated to the tail of the LRU for immediate reclaim
void vminfo(void){
char namebuf[16]; /* big enough to hold any row name */
@ -485,14 +490,14 @@ void vminfo(void){
{"pgfault", &vm_pgfault},
{"pgfree", &vm_pgfree},
{"pgmajfault", &vm_pgmajfault},
{"pgpgin", &vm_pgpgin},
{"pgpgout", &vm_pgpgout},
{"pgpgin", &vm_pgpgin}, // important
{"pgpgout", &vm_pgpgout}, // important
{"pgrefill", &vm_pgrefill},
{"pgrotated", &vm_pgrotated},
{"pgscan", &vm_pgscan},
{"pgsteal", &vm_pgsteal},
{"pswpin", &vm_pswpin},
{"pswpout", &vm_pswpout}
{"pswpin", &vm_pswpin}, // important
{"pswpout", &vm_pswpout} // important
};
const int vm_table_count = sizeof(vm_table)/sizeof(vm_table_struct);

View File

@ -17,65 +17,65 @@ extern void loadavg(double *av1, double *av5, double *av15);
/* obsolete */
extern unsigned kb_main_shared;
extern unsigned long kb_main_shared;
/* old but still kicking -- the important stuff */
extern unsigned kb_main_buffers;
extern unsigned kb_main_cached;
extern unsigned kb_main_free;
extern unsigned kb_main_total;
extern unsigned kb_swap_free;
extern unsigned kb_swap_total;
extern unsigned long kb_main_buffers;
extern unsigned long kb_main_cached;
extern unsigned long kb_main_free;
extern unsigned long kb_main_total;
extern unsigned long kb_swap_free;
extern unsigned long kb_swap_total;
/* recently introduced */
extern unsigned kb_high_free;
extern unsigned kb_high_total;
extern unsigned kb_low_free;
extern unsigned kb_low_total;
extern unsigned long kb_high_free;
extern unsigned long kb_high_total;
extern unsigned long kb_low_free;
extern unsigned long kb_low_total;
/* 2.4.xx era */
extern unsigned kb_active;
extern unsigned kb_inact_laundry; // grrr...
extern unsigned kb_inact_dirty;
extern unsigned kb_inact_clean;
extern unsigned kb_inact_target;
extern unsigned kb_swap_cached; /* late 2.4+ */
extern unsigned long kb_active;
extern unsigned long kb_inact_laundry; // grrr...
extern unsigned long kb_inact_dirty;
extern unsigned long kb_inact_clean;
extern unsigned long kb_inact_target;
extern unsigned long kb_swap_cached; /* late 2.4+ */
/* derived values */
extern unsigned kb_swap_used;
extern unsigned kb_main_used;
extern unsigned long kb_swap_used;
extern unsigned long kb_main_used;
/* 2.5.41+ */
extern unsigned kb_writeback;
extern unsigned kb_slab;
extern unsigned nr_reversemaps;
extern unsigned kb_committed_as;
extern unsigned kb_dirty;
extern unsigned kb_inactive;
extern unsigned kb_mapped;
extern unsigned kb_pagetables;
extern unsigned long kb_writeback;
extern unsigned long kb_slab;
extern unsigned long nr_reversemaps;
extern unsigned long kb_committed_as;
extern unsigned long kb_dirty;
extern unsigned long kb_inactive;
extern unsigned long kb_mapped;
extern unsigned long kb_pagetables;
extern void meminfo(void);
extern unsigned vm_nr_dirty;
extern unsigned vm_nr_writeback;
extern unsigned vm_nr_pagecache;
extern unsigned vm_nr_page_table_pages;
extern unsigned vm_nr_reverse_maps;
extern unsigned vm_nr_mapped;
extern unsigned vm_nr_slab;
extern unsigned vm_pgpgin;
extern unsigned vm_pgpgout;
extern unsigned vm_pswpin;
extern unsigned vm_pswpout;
extern unsigned vm_pgalloc;
extern unsigned vm_pgfree;
extern unsigned vm_pgactivate;
extern unsigned vm_pgdeactivate;
extern unsigned vm_pgfault;
extern unsigned vm_pgmajfault;
extern unsigned vm_pgscan;
extern unsigned vm_pgrefill;
extern unsigned vm_pgsteal;
extern unsigned vm_kswapd_steal;
extern unsigned vm_pageoutrun;
extern unsigned vm_allocstall;
extern unsigned long vm_nr_dirty;
extern unsigned long vm_nr_writeback;
extern unsigned long vm_nr_pagecache;
extern unsigned long vm_nr_page_table_pages;
extern unsigned long vm_nr_reverse_maps;
extern unsigned long vm_nr_mapped;
extern unsigned long vm_nr_slab;
extern unsigned long vm_pgpgin;
extern unsigned long vm_pgpgout;
extern unsigned long vm_pswpin;
extern unsigned long vm_pswpout;
extern unsigned long vm_pgalloc;
extern unsigned long vm_pgfree;
extern unsigned long vm_pgactivate;
extern unsigned long vm_pgdeactivate;
extern unsigned long vm_pgfault;
extern unsigned long vm_pgmajfault;
extern unsigned long vm_pgscan;
extern unsigned long vm_pgrefill;
extern unsigned long vm_pgsteal;
extern unsigned long vm_kswapd_steal;
extern unsigned long vm_pageoutrun;
extern unsigned long vm_allocstall;
extern void vminfo(void);

View File

@ -5,7 +5,7 @@
EXTERN_C_BEGIN
extern const char * wchan(unsigned long address, unsigned pid);
extern const char * wchan(unsigned KLONG address, unsigned pid);
extern int open_psdb(const char *restrict override);
extern int open_psdb_message(const char *restrict override, void (*message)(const char *, ...));

View File

@ -309,7 +309,7 @@ static sort_node *do_one_sort_spec(const char *spec){
fs = search_format_array(spec);
if(fs){
sort_node *thisnode;
thisnode = malloc(sizeof(format_node));
thisnode = malloc(sizeof(sort_node));
thisnode->sr = fs->sr;
thisnode->need = fs->need;
thisnode->reverse = reverse;

View File

@ -99,7 +99,7 @@ static void getrunners(unsigned int *restrict running, unsigned int *restrict bl
}
static void getstat(jiff *restrict cuse, jiff *restrict cice, jiff *restrict csys, jiff *restrict cide, jiff *restrict ciow,
unsigned *restrict pin, unsigned *restrict pout, unsigned *restrict s_in, unsigned *restrict sout,
unsigned long *restrict pin, unsigned long *restrict pout, unsigned long *restrict s_in, unsigned long *restrict sout,
unsigned *restrict intr, unsigned *restrict ctxt,
unsigned int *restrict running, unsigned int *restrict blocked,
unsigned int *restrict btime, unsigned int *restrict processes) {
@ -123,11 +123,11 @@ static void getstat(jiff *restrict cuse, jiff *restrict cice, jiff *restrict csy
if(b) sscanf(b, "cpu %Lu %Lu %Lu %Lu %Lu", cuse, cice, csys, cide, ciow);
b = strstr(buff, "page ");
if(b) sscanf(b, "page %u %u", pin, pout);
if(b) sscanf(b, "page %lu %lu", pin, pout);
else need_vmstat_file = 1;
b = strstr(buff, "swap ");
if(b) sscanf(b, "swap %u %u", s_in, sout);
if(b) sscanf(b, "swap %lu %lu", s_in, sout);
else need_vmstat_file = 1;
b = strstr(buff, "intr ");
@ -249,17 +249,17 @@ static void new_header(void){
}
static void new_format(void) {
const char format[]="%2u %2u %6u %6u %6u %6u %4u %4u %5u %5u %4u %5u %2u %2u %2u %2u\n";
const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %5u %2u %2u %2u %2u\n";
unsigned int tog=0; /* toggle switch for cleaner code */
unsigned int i;
unsigned int hz = Hertz;
unsigned int running,blocked,dummy_1,dummy_2;
jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2];
jiff duse, dsys, didl, diow, Div, divo2;
unsigned int pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
unsigned int intr[2], ctxt[2];
unsigned int sleep_half;
unsigned int kb_per_page = sysconf(_SC_PAGESIZE) / 1024;
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
int debt = 0; // handle idle ticks running backwards
sleep_half=(sleep_time/2);
@ -347,7 +347,7 @@ static void new_format(void) {
static void sum_format(void) {
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow;
unsigned int pgpgin, pgpgout, pswpin, pswpout;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
unsigned int intr, ctxt;
meminfo();
@ -356,25 +356,25 @@ static void sum_format(void) {
&intr, &ctxt,
&running, &blocked,
&btime, &processes);
printf("%13u kB total memory\n", kb_main_total);
printf("%13u kB used memory\n", kb_main_used);
printf("%13u kB active memory\n", kb_active);
printf("%13u kB inactive memory\n", kb_inactive);
printf("%13u kB free memory\n", kb_main_free);
printf("%13u kB buffer memory\n", kb_main_buffers);
printf("%13u kB swap cache\n", kb_main_cached);
printf("%13u kB total swap\n", kb_swap_total);
printf("%13u kB used swap\n", kb_swap_used);
printf("%13u kB free swap\n", kb_swap_free);
printf("%13lu kB total memory\n", kb_main_total);
printf("%13lu kB used memory\n", kb_main_used);
printf("%13lu kB active memory\n", kb_active);
printf("%13lu kB inactive memory\n", kb_inactive);
printf("%13lu kB free memory\n", kb_main_free);
printf("%13lu kB buffer memory\n", kb_main_buffers);
printf("%13lu kB swap cache\n", kb_main_cached);
printf("%13lu kB total swap\n", kb_swap_total);
printf("%13lu kB used swap\n", kb_swap_used);
printf("%13lu kB free swap\n", kb_swap_free);
printf("%13Lu non-nice user cpu ticks\n", cpu_use);
printf("%13Lu nice user cpu ticks\n", cpu_nic);
printf("%13Lu system cpu ticks\n", cpu_sys);
printf("%13Lu idle cpu ticks\n", cpu_idl);
printf("%13Lu IO-wait cpu ticks\n", cpu_iow);
printf("%13u pages paged in\n", pgpgin);
printf("%13u pages paged out\n", pgpgout);
printf("%13u pages swapped in\n", pswpin);
printf("%13u pages swapped out\n", pswpout);
printf("%13lu pages paged in\n", pgpgin);
printf("%13lu pages paged out\n", pgpgout);
printf("%13lu pages swapped in\n", pswpin);
printf("%13lu pages swapped out\n", pswpout);
printf("%13u interrupts\n", intr);
printf("%13u CPU context switches\n", ctxt);
printf("%13u boot time\n", btime);
@ -384,7 +384,7 @@ static void sum_format(void) {
static void fork_format(void) {
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow;
unsigned int pgpgin, pgpgout, pswpin, pswpout;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
unsigned int intr, ctxt;
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl, &cpu_iow,