All pastes #29870 Raw Edit

Untitled

public c v1 · immutable
#29870 ·published 2005-11-21 04:07 UTC
rendered paste body
#include <linux/pagefault.h>#include <linux/unistd.h>#include <stdlib.h>#include <sys/types.h>#include <stdio.h>int main(int argc, char** argv){    int flag;    pid_t pid;    pf_info_struct_t info;    int count;    char *mem_hogs[10000];    long i,j,k, randomi;    float randomf;        _syscall3(int, sys_pgfltstats, pid_t, pid, int, flag, pf_info_struct_t*, info);        // tell the system call to only return values for the pid we give it    flag = PGFLTSTAT_PROC;        // get the pid of this process    pid = getpid();        // allocate max memory    i=0;    while(1)    {        if ((mem_hogs[i]=malloc(512000)) == NULL)            break;        i++;    }        printf("Allocated %d 512k blocks before heap size limit\n",i);    //sleep(10);    for(j=0;j<i;j++)    {        *mem_hogs[j]=1;    }    sys_pgfltstats(pid, flag, &info);    printf("Sequential Run Complete\nPage Faults: %d\n", info . maj_pagefaults);        for(j=0;j<100000;j++)    {        randomf=(float)rand()/RAND_MAX;        randomi=randomf * i;        *mem_hogs[randomi]=1;        //printf("Access %d\n", randomi);        //printf("%d=%d\n",randomi,mem_hogs[randomi]);    }    sys_pgfltstats(pid, flag, &info);    printf("Random Run Complete\nPage Faults: %d\n", info . maj_pagefaults);            return;}