void testRandomFree(void){ long x,y,a; int i; printf(" => testRandomFree\n"); srand(time(NULL)); a=REAL_TASK_COUNT; x=rand(); x=((x)%a+a)%a;x=(x==0)?x+1:x; /*random x s.t. 0<x<a*/ y=rand(); y=((y)%a+a)%a;y=(y==0)?y+1:y; /*random y s.t. 0<y<a*/ if(x>y){long z=x; x=y;y=z;} /*change x and y s.t. 0<=x<=y<a*/ if(x+1==y) /*make sure that x<y-1 to avoid double free*/ { if(x<=1) y++; else x--; } /* we will free x, then y, then 0 to x, then x+1 to y, then y+1 to end */ doFree(x); doFree(y); /* Free 0 up to x */ for(i = 0; i < x; i++){ doFree(i); } /* Free x+1 up to y */ for(i = x+1; i < y; i++){ doFree(i); } /* Free y up to REAL_TASK_COUNT */ for(i = y+1; i < REAL_TASK_COUNT; i++){ doFree(i); } }
void testRandomFree(void){ long x,y,a; int i; printf(" => testRandomFree\n"); srand(-1); a=FAIR_TASK_COUNT; x=rand(); x=((x)%a+a)%a;x=(x==0)?x+1:x; /*random x s.t. 0<x<a*/ y=rand(); y=((y)%a+a)%a;y=(y==0)?y+1:y; /*random y s.t. 0<y<a*/ if(x>y){long z=x; x=y;y=z;} /*change x and y s.t. 0<=x<=y<a*/ if(x+1==y) /*make sure that x<y-1 to avoid double free*/ { if(x<=1) y++; else x--; } /* We will free x, then y, then 0 to x, then x+1 to y, then y+1 to end. If you need to see which x and y are chosen for debugging reasons, just uncomment the prints */ /*printf("Freeing: %d,",x);*/ doFree(x); /*printf(" then %d",y);*/ doFree(y); /*printf(" and then 0 up to %d, and then %d up to %d, and then %d up to the end in sequence.\n", x, x+1,y,y+1);*/ /* Free 0 up to x */ for(i = 0; i < x; i++){ doFree(i); } /* Free x+1 up to y */ for(i = x+1; i < y; i++){ doFree(i); } /* Free y up to FAIR_TASK_COUNT */ for(i = y+1; i < a; i++){ doFree(i); } }
asmlinkage int sys_netmalloc(net_malloc_arg_t *arg) { switch(arg->action) { case A_ALLOC: doAlloc(arg); break; case A_FREE: doFree(arg); break; } return 0; }