Пример #1
0
void system_memory(void)
{
#define pagetob(size) ((size) << (uvmexp.pageshift))
	struct uvmexp uvmexp;
	int nswap, rnswap, i;
	int mib[] = { CTL_VM, VM_UVMEXP };
	size_t size = sizeof (uvmexp);

	if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
		return 0;

	bm.mem_used = pagetob(uvmexp.active);
	bm.mem_max = pagetob(uvmexp.npages);
	bm.swap_used = 0;
	bm.swap_max = 0;
	if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) != 0) {
		struct swapent *swdev = malloc(nswap * sizeof(*swdev));
		if((rnswap = swapctl(SWAP_STATS, swdev, nswap)) != nswap) {
			for (i = 0; i < nswap; i++) {
				if (swdev[i].se_flags & SWF_ENABLE) {
					bm.swap_used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
					bm.swap_max += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
				}
			}
		}
		free(swdev);
	}
}
Пример #2
0
void KMemoryWidget::update()
{
    int pageshift; /* log base 2 of the pagesize */
    register int pagesize;
    vm_statistics_data_t vmstats;
    int swap_pages = 0, swap_free = 0, i;
    struct tbl_swapinfo swbuf;

    /* get the page size with "getpagesize" and calculate pageshift from it */

    pagesize = getpagesize();
    pageshift = 0;
    while(pagesize > 1)
    {
        pageshift++;
        pagesize >>= 1;
    }

    /* we only need the amount of log(2)1024 for our conversion */

    pageshift -= LOG1024;

    /* memory information */
    /* this is possibly bogus - we work out total # pages by */
    /* adding up the free, active, inactive, wired down, and */
    /* zero filled. Anyone who knows a better way, TELL ME!  */
    /* Change: dont use zero filled. */

    (void)::vm_statistics(::task_self(), &vmstats);

    /* thanks DEC for the table() command. No thanks at all for   */
    /* omitting the man page for it from OSF/1 1.2, and failing   */
    /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
    /* include files. */

    i = 0;
    while(table(TBL_SWAPINFO, i, &swbuf, 1, sizeof(struct tbl_swapinfo)) > 0)
    {
        swap_pages += swbuf.size;
        swap_free += swbuf.free;
        i++;
    }
    Memory_Info[TOTAL_MEM] = pagetob((vmstats.free_count + vmstats.active_count + vmstats.inactive_count + vmstats.wire_count));
    Memory_Info[FREE_MEM] = pagetob(vmstats.free_count);
    Memory_Info[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
    Memory_Info[BUFFER_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
#ifdef __GNUC__
#warning "FIXME: Memory_Info[CACHED_MEM]"
#endif
    Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; /* cached memory in ram */
    Memory_Info[SWAP_MEM] = pagetob(swap_pages);
    Memory_Info[FREESWAP_MEM] = pagetob(swap_free);
}