/* * Print general memory information. */ static void root_meminfo(void) { struct vm_stats_info vsi; if (vm_info_stats(&vsi) != OK) return; buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize, vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached); }
u32_t fs_bufs_heuristic(int minbufs, u32_t btotal, u32_t bfree, int blocksize, dev_t majordev) { struct vm_stats_info vsi; int bufs; u32_t kbytes_used_fs, kbytes_total_fs, kbcache, kb_fsmax; u32_t kbytes_remain_mem, bused; bused = btotal-bfree; /* but we simply need minbufs no matter what, and we don't * want more than that if we're a memory device */ if(majordev == MEMORY_MAJOR) { return minbufs; } /* set a reasonable cache size; cache at most a certain * portion of the used FS, and at most a certain %age of remaining * memory */ if((vm_info_stats(&vsi) != OK)) { bufs = 1024; printf("fslib: heuristic info fail: default to %d bufs\n", bufs); return bufs; } kbytes_remain_mem = div64u(mul64u(vsi.vsi_free, vsi.vsi_pagesize), 1024); /* check fs usage. */ kbytes_used_fs = div64u(mul64u(bused, blocksize), 1024); kbytes_total_fs = div64u(mul64u(btotal, blocksize), 1024); /* heuristic for a desired cache size based on FS usage; * but never bigger than half of the total filesystem */ kb_fsmax = sqrt_approx(kbytes_used_fs)*40; kb_fsmax = MIN(kb_fsmax, kbytes_total_fs/2); /* heuristic for a maximum usage - 10% of remaining memory */ kbcache = MIN(kbytes_remain_mem/10, kb_fsmax); bufs = kbcache * 1024 / blocksize; /* but we simply need MINBUFS no matter what */ if(bufs < minbufs) bufs = minbufs; return bufs; }
static u32_t fs_bufs_heuristic(int minbufs, u32_t btotal, u64_t bfree, int blocksize, dev_t majordev) { struct vm_stats_info vsi; int bufs; u32_t kbytes_used_fs, kbytes_total_fs, kbcache, kb_fsmax; u32_t kbytes_remain_mem; u64_t bused; bused = btotal-bfree; /* set a reasonable cache size; cache at most a certain * portion of the used FS, and at most a certain %age of remaining * memory */ if(vm_info_stats(&vsi) != OK) { bufs = 1024; if(!quiet) printf("fslib: heuristic info fail: default to %d bufs\n", bufs); return bufs; } /* remaining free memory is unused memory plus memory in used for cache, * as the cache can be evicted */ kbytes_remain_mem = (u64_t)(vsi.vsi_free + vsi.vsi_cached) * vsi.vsi_pagesize / 1024; /* check fs usage. */ kbytes_used_fs = (unsigned long)(((u64_t)bused * blocksize) / 1024); kbytes_total_fs = (unsigned long)(((u64_t)btotal * blocksize) / 1024); /* heuristic for a desired cache size based on FS usage; * but never bigger than half of the total filesystem */ kb_fsmax = sqrt_approx(kbytes_used_fs)*40; kb_fsmax = MIN(kb_fsmax, kbytes_total_fs/2); /* heuristic for a maximum usage - 10% of remaining memory */ kbcache = MIN(kbytes_remain_mem/10, kb_fsmax); bufs = kbcache * 1024 / blocksize; /* but we simply need MINBUFS no matter what */ if(bufs < minbufs) bufs = minbufs; return bufs; }
void vm_dmp() { static struct proc proc[NR_TASKS + NR_PROCS]; static struct vm_region_info vri[LINES]; struct vm_stats_info vsi; struct vm_usage_info vui; static int prev_i = -1; static vir_bytes prev_base = 0; int r, r2, i, j, first, n = 0; if (prev_i == -1) { if ((r = vm_info_stats(&vsi)) != OK) { printf("IS: warning: couldn't talk to VM: %d\n", r); return; } printf("Total %lu kB, free %lu kB, largest free %lu kB, cached %lu kB\n", vsi.vsi_total * (vsi.vsi_pagesize / 1024), vsi.vsi_free * (vsi.vsi_pagesize / 1024), vsi.vsi_largest * (vsi.vsi_pagesize / 1024), vsi.vsi_cached * (vsi.vsi_pagesize / 1024)); n++; printf("\n"); n++; prev_i++; } if ((r = sys_getproctab(proc)) != OK) { printf("IS: warning: couldn't get copy of process table: %d\n", r); return; } for (i = prev_i; i < NR_TASKS + NR_PROCS && n < LINES; i++, prev_base = 0) { if (i < NR_TASKS || isemptyp(&proc[i])) continue; /* The first batch dump for each process contains a header line. */ first = prev_base == 0; r = vm_info_region(proc[i].p_endpoint, vri, LINES - first, &prev_base); if (r < 0) { printf("Process %d (%s): error %d\n", proc[i].p_endpoint, proc[i].p_name, r); n++; continue; } if (first) { /* The entire batch should fit on the screen. */ if (n + 1 + r > LINES) { prev_base = 0; /* restart on next page */ break; } if ((r2 = vm_info_usage(proc[i].p_endpoint, &vui)) != OK) { printf("Process %d (%s): error %d\n", proc[i].p_endpoint, proc[i].p_name, r2); n++; continue; } printf("Process %d (%s): total %lu kB, common %lu kB, " "shared %lu kB\n", proc[i].p_endpoint, proc[i].p_name, vui.vui_total / 1024L, vui.vui_common / 1024L, vui.vui_shared / 1024L); n++; } while (r > 0) { for (j = 0; j < r; j++) { print_region(&vri[j], &n); } if (LINES - n - 1 <= 0) break; r = vm_info_region(proc[i].p_endpoint, vri, LINES - n - 1, &prev_base); if (r < 0) { printf("Process %d (%s): error %d\n", proc[i].p_endpoint, proc[i].p_name, r); n++; } } print_region(NULL, &n); if (n > LINES) printf("IS: internal error\n"); if (n == LINES) break; /* This may have to wipe out the "--more--" from below. */ printf(" \n"); n++; } if (i >= NR_TASKS + NR_PROCS) { i = -1; prev_base = 0; } else printf("--more--\r"); prev_i = i; }