vm, kernel, top: report memory usage of vm, kernel

This commit is contained in:
Ben Gras
2012-09-18 22:19:22 +02:00
parent aa82e375c6
commit fe6e291f59
9 changed files with 69 additions and 15 deletions

View File

@@ -107,15 +107,15 @@ static void pid_psinfo(int i)
ex64lo(proc[i].p_cycles)
);
memset(&vui, 0, sizeof(vui));
if (!is_zombie(i)) {
/* We don't care if this fails. */
(void) vm_info_usage(proc[i].p_endpoint, &vui);
}
/* If the process is not a kernel task, we add some extra info. */
if (!task) {
memset(&vui, 0, sizeof(vui));
if (!is_zombie(i)) {
/* We don't care if this fails. */
(void) vm_info_usage(proc[i].p_endpoint, &vui);
}
if (mproc[pi].mp_flags & PAUSED)
p_state = PSTATE_PAUSED;
else if (mproc[pi].mp_flags & WAITING)
@@ -165,6 +165,9 @@ static void pid_psinfo(int i)
ex64hi(proc[i].p_kcall_cycles),
ex64lo(proc[i].p_kcall_cycles));
/* add total memory for tasks at the end */
if(task) buf_printf(" %lu", vui.vui_total);
/* Newline at the end of the file. */
buf_printf("\n");
}

View File

@@ -36,6 +36,8 @@
#include "memory.h"
static int vm_self_pages;
/* PDE used to map in kernel, kernel physical address. */
static int pagedir_pde = -1;
static u32_t global_bit = 0, pagedir_pde_val;
@@ -67,6 +69,9 @@ static struct {
phys_bytes phys;
} sparepages[SPAREPAGES];
extern char _end;
#define is_staticaddr(v) ((vir_bytes) (v) < (vir_bytes) &_end)
#define MAX_KERNMAPPINGS 10
static struct {
phys_bytes phys_addr; /* Physical addr. */
@@ -130,7 +135,6 @@ static u32_t findhole(void)
int pde = 0, try_restart;
static u32_t lastv = 0;
pt_t *pt = &vmprocess->vm_pt;
extern char _end;
vir_bytes vmin, vmax;
vmin = (vir_bytes) (&_end) & I386_VM_ADDR_MASK; /* marks end of VM BSS */
@@ -188,9 +192,8 @@ static u32_t findhole(void)
void vm_freepages(vir_bytes vir, int pages)
{
assert(!(vir % I386_PAGE_SIZE));
extern char _end;
if(vir < (vir_bytes) &_end) {
if(is_staticaddr(vir)) {
printf("VM: not freeing static page\n");
return;
}
@@ -200,6 +203,8 @@ void vm_freepages(vir_bytes vir, int pages)
WMF_OVERWRITE | WMF_FREE) != OK)
panic("vm_freepages: pt_writemap failed");
vm_self_pages--;
#if SANITYCHECKS
/* If SANITYCHECKS are on, flush tlb so accessing freed pages is
* always trapped, also if not in tlb.
@@ -288,6 +293,7 @@ void *vm_allocpage(phys_bytes *phys, int reason)
util_stacktrace();
printf("VM: warning: out of spare pages\n");
}
if(!is_staticaddr(s)) vm_self_pages++;
return s;
}
@@ -330,6 +336,7 @@ void *vm_allocpage(phys_bytes *phys, int reason)
/* Return user-space-ready pointer to it. */
ret = (void *) loc;
vm_self_pages++;
return ret;
}
@@ -1135,3 +1142,4 @@ void pt_cycle(void)
vm_checkspares();
}
int get_vm_self_pages(void) { return vm_self_pages; }

View File

@@ -100,6 +100,7 @@ void pt_cycle(void);
int pt_mapkernel(pt_t *pt);
void vm_pagelock(void *vir, int lockflag);
int vm_addrok(void *vir, int write);
int get_vm_self_pages(void);
#if SANITYCHECKS
void pt_sanitycheck(pt_t *pt, char *file, int line);
@@ -159,6 +160,7 @@ int map_get_ref(struct vmproc *vmp, vir_bytes addr, u8_t *cnt);
void get_stats_info(struct vm_stats_info *vsi);
void get_usage_info(struct vmproc *vmp, struct vm_usage_info *vui);
void get_usage_info_kernel(struct vm_usage_info *vui);
int get_region_info(struct vmproc *vmp, struct vm_region_info *vri, int
count, vir_bytes *nextp);
int copy_abs2region(phys_bytes abs, struct vir_region *destregion,

View File

@@ -11,6 +11,7 @@
#include <minix/debug.h>
#include <minix/bitmap.h>
#include <minix/hash.h>
#include <machine/multiboot.h>
#include <sys/mman.h>
@@ -1879,6 +1880,19 @@ void get_stats_info(struct vm_stats_info *vsi)
vsi->vsi_cached++;
}
void get_usage_info_kernel(struct vm_usage_info *vui)
{
memset(vui, 0, sizeof(*vui));
vui->vui_total = kernel_boot_info.kernel_allocated_bytes;
}
static void get_usage_info_vm(struct vm_usage_info *vui)
{
memset(vui, 0, sizeof(*vui));
vui->vui_total = kernel_boot_info.vm_allocated_bytes +
get_vm_self_pages() * VM_PAGE_SIZE;
}
/*========================================================================*
* get_usage_info *
*========================================================================*/
@@ -1892,6 +1906,16 @@ void get_usage_info(struct vmproc *vmp, struct vm_usage_info *vui)
memset(vui, 0, sizeof(*vui));
if(vmp->vm_endpoint == VM_PROC_NR) {
get_usage_info_vm(vui);
return;
}
if(vmp->vm_endpoint < 0) {
get_usage_info_kernel(vui);
return;
}
while((vr = region_get_iter(&v_iter))) {
physr_start_iter_least(vr->phys, &iter);
while((ph = physr_get_iter(&iter))) {

View File

@@ -122,10 +122,11 @@ int do_info(message *m)
break;
case VMIW_USAGE:
if (vm_isokendpt(m->VMI_EP, &pr) != OK)
if(m->VMI_EP < 0)
get_usage_info_kernel(&vui);
else if (vm_isokendpt(m->VMI_EP, &pr) != OK)
return EINVAL;
get_usage_info(&vmproc[pr], &vui);
else get_usage_info(&vmproc[pr], &vui);
addr = (vir_bytes) &vui;
size = sizeof(vui);