NetBSD Problem Report #45588

From www@NetBSD.org  Mon Nov  7 18:41:24 2011
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id CA8F563CD5F
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  7 Nov 2011 18:41:23 +0000 (UTC)
Message-Id: <20111107184123.38E5863CD56@www.NetBSD.org>
Date: Mon,  7 Nov 2011 18:41:23 +0000 (UTC)
From: naruse@airemix.jp
Reply-To: naruse@airemix.jp
To: gnats-bugs@NetBSD.org
Subject: Switching many pthreads causes segv
X-Send-Pr-Version: www-1.0

>Number:         45588
>Category:       kern
>Synopsis:       Switching many pthreads causes segv
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 07 18:45:00 +0000 2011
>Last-Modified:  Sun Nov 13 20:15:05 +0000 2011
>Originator:     Yui NARUSE
>Release:        NetBSD 5.99.56 x86_64
>Organization:
>Environment:
NetBSD kelvena.airemix.net 5.99.56 NetBSD 5.99.56 (GENERIC) #0: Sun Nov  6 06:47:01 JST 2011  naruse@kelvena.airemix.net:/usr/obj/sys/arch/amd64/compile/GENERIC amd64

>Description:
Making many (1000) pthreads and switching them, it causes segv.
>How-To-Repeat:
Run following program and it will segv.

% cat th.c
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#define THREAD_COUNT 10000
void *dummy(void *p) {
    sleep(3);
    return NULL;
}
int main(void) {
    int i;
    pthread_t *threads = malloc(sizeof(pthread_t) * THREAD_COUNT);
    for (i = 0; i < THREAD_COUNT; i++) {
        if (pthread_create(&threads[i], NULL, dummy, &i)) {
            perror("pthread_create");
            abort();
        }
        sched_yield();
    }
    return 0;
}
% gcc -pthread th.c&&./a.out
a.out: _lwp_ctl: zsh: segmentation fault (core dumped)  ./a.out

>Fix:

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/45588: Switching many pthreads causes segv
Date: Sun, 13 Nov 2011 17:43:47 +0000

 On Mon, Nov 07, 2011 at 06:45:00PM +0000, naruse@airemix.jp wrote:
  > Making many (1000) pthreads and switching them, it causes segv.

 The last time I did something like that (years ago) it killed the
 system entirely...

 Are you running out of virtual address space to put thread stacks in?

 -- 
 David A. Holland
 dholland@netbsd.org

From: "NARUSE, Yui" <naruse@airemix.jp>
To: gnats-bugs@NetBSD.org
Cc: David Holland <dholland-bugs@netbsd.org>, kern-bug-people@netbsd.org,
        gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/45588: Switching many pthreads causes segv
Date: Mon, 14 Nov 2011 03:15:06 +0900

 (2011/11/14 2:45), David Holland wrote:
 >   On Mon, Nov 07, 2011 at 06:45:00PM +0000, naruse@airemix.jp wrote:
 >    >  Making many (1000) pthreads and switching them, it causes segv.
 > 
 >   The last time I did something like that (years ago) it killed the
 >   system entirely...

 You can reproduce it with my attached code ;-)

 >   Are you running out of virtual address space to put thread stacks in?

 Yeah, it seems something like it.
 By ktrace/kdump, _lwp_ctl returns error "Can't allocate memory".
 sched_yield(2) should returns error instead of segv.

 -- 
 NARUSE, Yui  <naruse@airemix.jp>

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.