« Small Progress on the Mullocator | Main | Tried to install the Mac OS X Developer Documentation somewhere else »

Your help is needed. Give!

In the ongoing battle to enlighten the world about the evils of zerofilling memory pages, you can make your contribution right now! If you have a machine at your disposal, that is not a G4-400 Mhz G3-350 Mhz, iBook 500 Mhz or iMac 800 Mhz you immediately qualify.

How's that ? Pretty easy requirements! Please compile and run the following code on a system that is close to doing nothing, turn of Mail, turn off iTunes and what ever else might be sucking up CPU time. Compile this with cc -o page-clean-test page-clean-test.m -framework Foundation.

Please send the output result to nat@mulle-kybernetik.com (Harvest be damn SPAM bot!) Please write me the kind of system you ran the test on. If you didn't use Mac OS X 10.2, please tell me also.

Here comes the source...

#import <Foundation/Foundation.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <mach/mach_init.h>
#include <mach/vm_map.h>
#include <mach/vm_statistics.h>

/* Try this to see cost of zero page faulting 
 * in relationship to allocate and deallocate
 * PAGES=1 LOOPS=200000
 */
#define PAGES	1
#define LOOPS   (1000*1000)

/* Try this to see cost of zero page faulting
 * in relationship to "other activtity" during
 * faulting. Some believe zerofill is cheap.
 * Check it out with Shark. Use a little fuzz,
 * set samples to 50 us and let run for 300000
 * samples or so
 * PAGES=2048 LOOPS=1000
 */


void   alloc_loop()
{
   unsigned int   i;
   char           *block;

   for( i = 0; i < LOOPS; i++)
   {
      if( vm_allocate( mach_task_self(), (vm_address_t *) &block, PAGES * vm_page_size, 1))
         abort();

      if( vm_deallocate( mach_task_self(), (vm_address_t) block, PAGES * vm_page_size))
         abort();
   }
}


void   touch_loop()
{
   unsigned int   i, j;
   char           *block;

   for( i = 0; i < LOOPS; i++)
   {
      if( vm_allocate( mach_task_self(), (vm_address_t *) &block, PAGES * vm_page_size, 1))
         abort();

      for( j = 0; j < PAGES * vm_page_size; j += vm_page_size)
         block[ j] = 1;

      if( vm_deallocate( mach_task_self(), (vm_address_t) block, PAGES * vm_page_size))
         abort();
   }
}


void   alloc_loop2()
{
   unsigned int   i;
   char           *block;

   for( i = 0; i < LOOPS; i++)
   {
      if( vm_allocate( mach_task_self(), (vm_address_t *) &block, PAGES * 2 * vm_page_size, 1))
         abort();

      if( vm_deallocate( mach_task_self(), (vm_address_t) block, PAGES * 2 * vm_page_size))
         abort();
   }
}


void   touch_loop2()
{
   unsigned int   i, j;
   char           *block;

   for( i = 0; i < LOOPS; i++)
   {
      if( vm_allocate( mach_task_self(), (vm_address_t *) &block, PAGES * 2 * vm_page_size, 1))
         abort();

      for( j = 0; j < PAGES * 2 * vm_page_size; j += vm_page_size)
         block[ j] = 1;

      if( vm_deallocate( mach_task_self(), (vm_address_t) block, PAGES * 2 * vm_page_size))
         abort();
   }
}




int  main()
{
   alloc_loop();	/* warm up */

   NSLog( @"Just alloc start\n");
   alloc_loop();
   NSLog( @"Just alloc stop\n");

   NSLog( @"Zero fill start\n");
   touch_loop();
   NSLog( @"Zero fill stop\n");

   NSLog( @"Just alloc start two pages\n");
   alloc_loop2();
   NSLog( @"Just alloc stop two pages\n");
   
   NSLog( @"Zero fill start two pages\n");
   touch_loop2();
   NSLog( @"Zero fill stop two pages\n");

   return( 0);
}

About

This page contains a single entry from the blog posted on July 30, 2003 12:31 AM.

The previous post in this blog was Small Progress on the Mullocator.

The next post in this blog is Tried to install the Mac OS X Developer Documentation somewhere else.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 4.25