From owner-freebsd-current@FreeBSD.ORG Thu Aug 14 10:08:00 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 343E1AC0; Thu, 14 Aug 2014 10:08:00 +0000 (UTC) Received: from ivan-labs.com (ivan-labs.com [162.243.251.239]) by mx1.freebsd.org (Postfix) with ESMTP id 0A2732009; Thu, 14 Aug 2014 10:07:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ivan-labs.com (Postfix) with ESMTP id 03CFA120856; Thu, 14 Aug 2014 14:07:53 +0400 (MSK) X-Virus-Scanned: Debian amavisd-new at Received: from ivan-labs.com ([127.0.0.1]) by localhost (ivan-labs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6a8z3qNU+CXE; Thu, 14 Aug 2014 14:07:52 +0400 (MSK) Received: from [192.168.43.253] (host-31-152-66-217.spbmts.ru [217.66.152.31]) by ivan-labs.com (Postfix) with ESMTPSA id 99843120256; Thu, 14 Aug 2014 14:07:51 +0400 (MSK) Message-ID: <53EC8A6F.1020807@ivan-labs.com> Date: Thu, 14 Aug 2014 14:07:43 +0400 From: "Ivan A. Kosarev" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Dimitry Andric , Konstantin Belousov Subject: Re: libthr and main thread stack size References: <53E36E84.4060806@ivan-labs.com> <20140808052807.GB93733@kib.kiev.ua> <53E48B38.9010607@ivan-labs.com> <20140808112201.GC93733@kib.kiev.ua> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 10:08:00 -0000 On 08/13/2014 01:40 AM, Dimitry Andric wrote: > On 08 Aug 2014, at 13:22, Konstantin Belousov wrote: >> On Fri, Aug 08, 2014 at 12:32:56PM +0400, Ivan A. Kosarev wrote: >>> On 08/08/2014 09:28 AM, Konstantin Belousov wrote: >>>> On Thu, Aug 07, 2014 at 04:18:12PM +0400, Ivan A. Kosarev wrote: >>>>> Hello, >>>>> >>>>> According to libthr's thr_init.c (the 9.2 version) init_main_thread() >>>>> allocates s.c. "red zone" below the main stack in order to protect other >>>>> stacks. The size of the main stack is determined by the >>>>> _thr_stack_initial variable that is declared extern though it doesn't >>>>> seem it can be changed. The value of the variable is set to 4M on 64-bit >>>>> platforms which is obviously not sufficient for the most of real programs. >>>>> >>>>> Can anyone please confirm that there is no way to increase the stack >>>>> size for the main thread and thus any program linked against libthr has >>>>> only a few megabytes of stack memory for its main thread--whatever the >>>>> system stack size (ulimit -s) is set to? >>>> Yes, there is no way to change the main thread stack clamping. >>>> Could you provide a reasonable use case for the 4MB stack ? >>> Traversing trees with recursive functions or on-stack grammar parsers? > I just ran into a similar issue while running one of clang 3.5's test > cases (see http://llvm.org/PR20635 ). On i386, it used up approximately > 2MB of stack, then ran into the guard page, and segfaulted. > > I was quite amazed to find out that ulimit -s didn't help at all, until > I remembered this thread. :-) Yes, that was the point: at least some of real programs consume more stack space than what we have with the hardcoded libthr's limits. Also, it looks a bit weird to me that adding thread support/linking against libthr affects how much stack space we can consume and whether it can be controlled with ulimit. The original issue I've run into is one of the Asan's tests: http://reviews.llvm.org/D4562 --