From owner-svn-src-user@FreeBSD.ORG Mon Oct 29 16:42:38 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9D0649CD; Mon, 29 Oct 2012 16:42:38 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 863358FC0A; Mon, 29 Oct 2012 16:42:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9TGgcaD000412; Mon, 29 Oct 2012 16:42:38 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9TGgc6N000411; Mon, 29 Oct 2012 16:42:38 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201210291642.q9TGgc6N000411@svn.freebsd.org> From: Peter Holm Date: Mon, 29 Oct 2012 16:42:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r242317 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Oct 2012 16:42:38 -0000 Author: pho Date: Mon Oct 29 16:42:37 2012 New Revision: 242317 URL: http://svn.freebsd.org/changeset/base/242317 Log: Regression test added. Added: user/pho/stress2/misc/mlockall2.sh (contents, props changed) Added: user/pho/stress2/misc/mlockall2.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mlockall2.sh Mon Oct 29 16:42:37 2012 (r242317) @@ -0,0 +1,148 @@ +#!/bin/sh + +# +# Copyright (c) 2012 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# core dumps seen in watchdogd after mlockall() was added. +# This scenario demonstrates the problem. Fixed in r242012. + +mem=`sysctl hw.usermem | awk '{print $NF}'` + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mlockall2.c +cc -o mlockall2 -Wall -Wextra -O2 -g mlockall2.c +rm -f mlockall2.c +cd $here + +rm -f mlockall2.core +/tmp/mlockall2 $mem & +while kill -0 $! 2>/dev/null; do + [ -r mlockall2.core ] && kill $! && break + sleep 10 +done +[ -r mlockall2.core ] && echo "FAIL" +killall mlockall2 +rm -f /tmp/mlockall2 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include + +#define LOAD 40 +#define N 90000 +#define PARALLEL 5 + +long size; + +void +swap(void) +{ + char *c; + int page; + long i; + + setproctitle("swap"); + c = malloc(size); + while (c == NULL) { + size -= 1024 * 1024; + c = malloc(size); + } + page = getpagesize(); + for (;;) { + i = 0; + while (i < size) { + c[i] = 0; + i += page; + } + } +} + +void +test(void) +{ + pid_t p; + int i, status; + + setproctitle("test"); + for (i = 0; i < N; i++) { + if ((p = fork()) == 0) { + _exit(0); + } + if (p > 0) + wait(&status); + if (status != 0) + break; + } + _exit(0); +} + +int +main(int argc __unused, char **argv) +{ + struct rtprio rtp; + int i, j; + + size = atol(argv[1]) / LOAD * 1.5; + for (i = 0; i < LOAD; i++) + if (fork() == 0) + swap(); + sleep(10); + + rtp.type = RTP_PRIO_REALTIME; + rtp.prio = 0; + if (rtprio(RTP_SET, 0, &rtp) == -1) + err(1, "rtprio"); + + if (madvise(0, 0, MADV_PROTECT) != 0) + err(1, "madvise failed"); + if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) + err(1, "mlockall failed"); + + for (j = 0; j < 10; j++) { + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + if (access("mlockall2.core", R_OK) == 0) + break; + } + + return (0); +}