From patchwork Fri Mar 19 21:21:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 48193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C1410B7D48 for ; Sat, 20 Mar 2010 08:24:54 +1100 (EST) Received: from localhost ([127.0.0.1]:60051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nsjg4-0006vK-2f for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2010 17:24:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nsjem-0006u1-T4 for qemu-devel@nongnu.org; Fri, 19 Mar 2010 17:23:00 -0400 Received: from [199.232.76.173] (port=39441 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nsjem-0006tl-Hb for qemu-devel@nongnu.org; Fri, 19 Mar 2010 17:23:00 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nsjek-0005X9-S0 for qemu-devel@nongnu.org; Fri, 19 Mar 2010 17:23:00 -0400 Received: from are.twiddle.net ([75.149.56.221]:35309) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nsjek-0005Wh-A1 for qemu-devel@nongnu.org; Fri, 19 Mar 2010 17:22:58 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id E3B04A48; Fri, 19 Mar 2010 14:22:55 -0700 (PDT) From: Richard Henderson Date: Fri, 19 Mar 2010 14:21:13 -0700 To: qemu-devel@nongnu.org Message-Id: <20100319212255.E3B04A48@are.twiddle.net> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] linux-user: Use RLIMIT_STACK for default stack size. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The current default stack limit of 512kB is far too small; a fair number of gcc testsuite failures (for all guests) are directly attributable to this. Using the -s option in every invocation of the emulator is annoying to say the least. A reasonable compromise seems to be to honor the system rlimit. At least on two Linux distributions, this is set to 8MB and 10MB respectively. If the system does not limit the stack, then we're no worse off than before. At the same time, rename the variable from x86_stack_size and change the ultimate fallback size from 512kB to 8MB. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 +- linux-user/main.c | 23 +++++++++++++++++------ linux-user/qemu.h | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 91eea62..b721b10 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1004,7 +1004,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm, /* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ - size = x86_stack_size; + size = guest_stack_size; if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) size = MAX_ARG_PAGES*TARGET_PAGE_SIZE; error = target_mmap(0, diff --git a/linux-user/main.c b/linux-user/main.c index 4614e3c..e5ff8a9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "qemu.h" #include "qemu-common.h" @@ -51,7 +52,7 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE; /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size = 512 * 1024; +unsigned long guest_stack_size = 8 * 1024 * 1024UL; void gemu_log(const char *fmt, ...) { @@ -2560,7 +2561,7 @@ static void usage(void) , TARGET_ARCH, interp_prefix, - x86_stack_size, + guest_stack_size, DEBUG_LOGFILE); exit(1); } @@ -2639,6 +2640,16 @@ int main(int argc, char **argv, char **envp) (void) envlist_setenv(envlist, *wrk); } + /* Read the stack limit from the kernel. If it's "unlimited", + then we can do little else besides use the default. */ + { + struct rlimit lim; + if (getrlimit(RLIMIT_STACK, &lim) == 0 + && lim.rlim_cur != RLIM_INFINITY) { + guest_stack_size = lim.rlim_cur; + } + } + cpu_model = NULL; #if defined(cpudef_setup) cpudef_setup(); /* parse cpu definitions in target config file (TBD) */ @@ -2687,13 +2698,13 @@ int main(int argc, char **argv, char **envp) if (optind >= argc) break; r = argv[optind++]; - x86_stack_size = strtol(r, (char **)&r, 0); - if (x86_stack_size <= 0) + guest_stack_size = strtoul(r, (char **)&r, 0); + if (guest_stack_size == 0) usage(); if (*r == 'M') - x86_stack_size *= 1024 * 1024; + guest_stack_size *= 1024 * 1024; else if (*r == 'k' || *r == 'K') - x86_stack_size *= 1024; + guest_stack_size *= 1024; } else if (!strcmp(r, "L")) { interp_prefix = argv[optind++]; } else if (!strcmp(r, "p")) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 6ab9517..47fc686 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -246,7 +246,7 @@ void mmap_fork_end(int child); #endif /* main.c */ -extern unsigned long x86_stack_size; +extern unsigned long guest_stack_size; /* user access */