2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdio.h>
2N/A#include "mtmalloc.h"
2N/A#include <unistd.h>
2N/A#include <thread.h>
2N/A#include <sys/types.h>
2N/A#include <sys/mman.h>
2N/A#include <fcntl.h>
2N/A#include <errno.h>
2N/A
2N/A/*
2N/A * This file tests for swap space exhaustion
2N/A *
2N/A * cc -O -o exhaust exhaust.c -lmtmalloc
2N/A */
2N/A
2N/Avoid * be_thread(void *);
2N/Aint iwin = 0;
2N/A
2N/Amain(int argc, char ** argv)
2N/A{
2N/A int ncpus;
2N/A thread_t tid[512];
2N/A int fd;
2N/A caddr_t stacks[512];
2N/A
2N/A srand(getpid());
2N/A ncpus = sysconf(_SC_NPROCESSORS_CONF);
2N/A
2N/A fd = open("/dev/zero", O_RDONLY);
2N/A
2N/A if (fd < 0) {
2N/A perror("open");
2N/A exit(-1);
2N/A }
2N/A
2N/A while (ncpus--)
2N/A stacks[ncpus] = mmap(0, 1<<23, PROT_READ|PROT_WRITE,
2N/A MAP_PRIVATE, fd, 0);
2N/A
2N/A close(fd);
2N/A
2N/A mallocctl(MTCHUNKSIZE, 150);
2N/A
2N/A ncpus = sysconf(_SC_NPROCESSORS_CONF);
2N/A while (ncpus--)
2N/A thr_create(stacks[ncpus], 1<<23, be_thread, NULL, THR_BOUND,
2N/A &tid[ncpus]);
2N/A
2N/A while (thr_join(NULL, NULL, NULL) == 0);
2N/A
2N/A exit(0);
2N/A}
2N/A
2N/A/* ARGSUSED */
2N/Avoid *
2N/Abe_thread(void *foo)
2N/A{
2N/A char *p;
2N/A
2N/A if (iwin) {
2N/A printf("why am I here\n");
2N/A return;
2N/A }
2N/A
2N/A if ((p = malloc(rand())) == NULL) {
2N/A iwin = 1;
2N/A fprintf(stderr, "Errno is %d\n", errno);
2N/A perror("malloc");
2N/A } else {
2N/A be_thread(NULL);
2N/A printf("free %p\n", p);
2N/A free(p);
2N/A }
2N/A
2N/A}