slow Hello world benchmark

Henry Cejtin henry@sourcelight.com
Tue, 26 Jun 2001 00:34:07 -0500


I  don't know if you noticed, but on the programming language shootout we did
quite poorly in the `hello  world'  test.   The  reason  is  our  reading  of
/proc/meminfo.   This  is all because it has to go around looking at the uses
of memory for various things that we don't care about.

The solution is to use the sysinfo system call.   It  is  still  rather  slow
because  it  also  returns lots of extra information which it needs to gather
up, but nothing in ASCII.  On both a 2.2 and 2.4 kernel it is  a  bit  faster
than  twice  as  fast as reading /proc/meminfo.  Also it will get rid of more
stdio stuff.

I thought at first we could just stat /proc/kcore, but this doesn't work.  On
really  big machines it is much smaller than physical memory because of games
played in what is mapped into kernel space.

At any rate, here is the new version of getRAMsize().  Note, you  now  should
add
    #include <sys/sysinfo.h>
    #include <errno.h>
    #include <string.h>
into the list of includes in gc.c.

=======================================================================
/*
 * Get RAM size.  Very Linux specific.
 * Note the total amount of RAM is multiplied by RAMSLOP so that we don't
 * use all of memory or start swapping.  It used to be .95, but Linux
 * 2.2 is more aggressive about swapping.
 */
#define	RAMSLOP	.85

static uint
getRAMsize(void)
{
	struct sysinfo	sbuf;

	unless (sysinfo(&sbuf) == 0)
		die("sysinfo failed, errno %s", strerror(errno));
	return (roundPage(sbuf.totalram * RAMSLOP));
}
=======================================================================

Note, no extra casts.  They are all taken care of.

Note the (void) in the function definition.

Note, RAMSLOP is a #define, not a static variable.  RAMslop is gone.