Skip to contentSkip to conversation

mm deadlock

BUG TeJun Huh 1 participant 1 message May 9, 2002

lore
Share & tools
lore

TeJun Huh

author
#0 lore raw

Running the following program on linux 2.4.18 SMP results in lockup
of the thread and some part of the system (any attempt to access the thread list results in the lockup of the attempting thread).

The program basically mmaps memory until the mmapped region is very
close to the bottom of the stack with some unmapped region inbetween. Then it tries to access region beyond the end of the highest mmaped region. I think it has something to do with stack growth.

---- program follows ----

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>

#define BASE_SIZE (32 << 20)
#define MIN_SIZE (512 << 10)

int main(void)

{
	size_t size;
	unsigned long *p, *lastp;
	size_t last_size;
	int i;

	lastp = NULL;
	size = BASE_SIZE;
	while (size >= MIN_SIZE) {
		p = mmap(0, size, PROT_READ|PROT_WRITE,
			 MAP_SHARED|MAP_ANONYMOUS, 0, 0);
		if (p == (unsigned long *)-1)
			size >>= 1;
		else {
			lastp = p;
			last_size = size;
		}
	}

	p = lastp + last_size / sizeof(unsigned long);
	for (i = 0; i < last_size / sizeof(unsigned long); i++)
		p[i] = i;

	printf("ok\n");
	return 0;
}