Problem with sbrk(3) under 4.1c BSD

NEP.FOUTS at Ames-Vmsb.ARPA NEP.FOUTS at Ames-Vmsb.ARPA
Sun Mar 25 21:58:00 AEST 1984


The following small piece of code attempts to size memory by using sbrk to
set the highest acceptable address.  To do this quickly, it uses a "binary
search" approach.  It selects a large (8mb) memory increment, and attempts
to increase memory by this increment size until sbrk returns an error code.
It then cuts the increment size in half and tries again.  This continues until
it has failed with a 1kb increment size.  As it is going along, it keeps
track of the amount added and at the end reports the final result.

-----  code start

#include <stdio.h>
#include <sys/file.h>
#include <errno.h>

#define kb 1024				/* 1 kb */
#define end_inc 1024			/* smallest buffer to allocate  1kb */
#define start_inc 8192 * 1024		/* largest buffer to allocate  8kb */
#define maximum_size 8192 * 1024	/* maximum memory to allocate  8mb */

int ptrs;

main( )
{
	int i, j;
	i = 0;
	j = start_inc;
	printf("Expanded from %dkb to ",sbrk(0)/kb);
	for (j = start_inc; j > end_inc; j /= 2)
		while ((i < maximum_size)
			&& (sbrk((int) j) > 0))
			i += j;
	printf("%dkb by allocating %dkb of memory.\n",sbrk(0)/kb,i/kb);
}

----- code end

The problem is that according to the sbrk(3) manual page, I should be able
to allocate 6112kb of virtual memory (as indicated by executing the limit
command from csh.  One one of my 780s this works fine.  On another one, I
get a variable result, depending on the system load, from under .5mb to
around 4mb.

The machine on which the code works has two 8mb (16mb total) swap partitions
and 4mb of real memory.  The machine on which the code fails has four 8mb swap
partitions (32mb total) and 8mb of real memory.

I have observed the system using DSD while the problem program (and several
variations) is running, and do not seem to be even close to filling the swap
space when the code executes, although I usualy am near to filling physical
memory.

I have tried tracking down the sbrk code, but I can't find where in the kernal
the "chmk $SYS_brk" instruction in /usr/src/lib/libc/sys/Osbrk.c leads to.

Help!
------



More information about the Comp.unix.wizards mailing list