Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <pthread.h>
- #include </usr/src/linux/include/linux/memstats.h>
- #define PAGESIZE 4096
- int main()
- {
- int status, i;
- int nr_pages = 100000;
- char **page_array;
- struct memstats stats;
- printf("\n'test.c'\n\n");
- status = syscall (328, &stats);
- printf( "stats:\n" );
- printf(
- " Number of free pages = %lu\n"
- " Number of pages used by slab allocator = %lu\n"
- " Number of pages in active list = %lu\n"
- " Number of pages in inactive list = %lu\n"
- " Number of pages in active list with set bit = %lu\n"
- " Number of pages in inactive list with set bit = %lu\n"
- " Number of pages moved from active to inactive list = %lu\n"
- " Number of pages evicted from inactive list = %lu\n",
- stats.u1, stats.u2, stats.u3, stats.u4, stats.u5, stats.u6, stats.u7,
- stats.u8);
- page_array = (char **)malloc(nr_pages * sizeof(char *));
- if ( page_array == NULL )
- {
- printf("ERROR ALLOCATING MEMORY TO FILL PAGES!\n");
- return -1;
- }
- for( i = 0; i < nr_pages; i++)
- {
- page_array[i] = (char *)malloc( sizeof(char) * PAGESIZE );
- if ( page_array[i] == NULL )
- {
- printf("ERROR ALLOCATING MEMORY TO PAGE %d!\n", i);
- return -1;
- }
- }
- printf("\nMemory has been allocated for %d pages\n\n", nr_pages);
- sleep(2);
- status = syscall (328, &stats);
- printf( "stats:\n" );
- printf(
- " Number of free pages = %lu\n"
- " Number of pages used by slab allocator = %lu\n"
- " Number of pages in active list = %lu\n"
- " Number of pages in inactive list = %lu\n"
- " Number of pages in active list with set bit = %lu\n"
- " Number of pages in inactive list with set bit = %lu\n"
- " Number of pages moved from active to inactive list = %lu\n"
- " Number of pages evicted from inactive list = %lu\n",
- stats.u1, stats.u2, stats.u3, stats.u4, stats.u5, stats.u6, stats.u7,
- stats.u8);
- printf("\nFreeing allocated memory...\n\n", nr_pages);
- for( i = 0; i < nr_pages; i++)
- {
- free( page_array[i] );
- }
- free( page_array );
- sleep(2);
- printf("Stats after freeing %d pages:\n\n", nr_pages);
- status = syscall (328, &stats);
- printf( "stats:\n" );
- printf(
- " Number of free pages = %lu\n"
- " Number of pages used by slab allocator = %lu\n"
- " Number of pages in active list = %lu\n"
- " Number of pages in inactive list = %lu\n"
- " Number of pages in active list with set bit = %lu\n"
- " Number of pages in inactive list with set bit = %lu\n"
- " Number of pages moved from active to inactive list = %lu\n"
- " Number of pages evicted from inactive list = %lu\n",
- stats.u1, stats.u2, stats.u3, stats.u4, stats.u5, stats.u6, stats.u7,
- stats.u8);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement