Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Feb 2001 12:38:38 -0800 (PST)
From:      Archie Cobbs <archie@dellroad.org>
To:        freebsd-hackers@freebsd.org, phk@freebsd.org
Subject:   new /etc/malloc.conf option
Message-ID:  <200102082038.MAA56927@curve.dellroad.org>

next in thread | raw e-mail | index | archive | help
Here's an idea for a new /etc/malloc.conf option to help with
debugging... I'm interested in what other people think.

The option would have the effect of setting a "failure probability"
P between 0.0 and 1.0 such that any malloc()/realloc() operation would
fail with probability P.

Sometimes I've implemented this kind of thing manually to test code
robustness and it's been very helpful in catching obscure bugs.

You can't do this with a single letter, but maybe we could do something
like this using a number between 0..100:

	$ ln -s F5AJ /etc/malloc.conf

Then in the malloc code read out the 'F5' at startup and set
failure_prob to 5%...

	static u_int failure_prob;	/* a number between 0 and 100 */

	void *
	malloc(size_t len)
	{
		u_int failure_index;

		if (failure_prob != 0 && (random() % 100) < failure_prob) {
			errno = ENOMEM;
			return (NULL)
		}
	}

This would then give you a 1% failure probability.

By using random(), the exact failure can be reproduced by the application
by setting the same seed with srandom(). We might want to use a more
precise range, e.g., 0..1000000 instead of 0..100.

-Archie

__________________________________________________________________________
Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102082038.MAA56927>