From patchwork Fri Apr 20 04:58:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 153929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6586CB7017 for ; Fri, 20 Apr 2012 14:59:05 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1335502746; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=eeCSRfSVJ5A5vC0YGs8qQfbcANU=; b=d0thUu4GKI10A2S U9mVYZ1JWo4sTYyT5KR3gLzFdDjL1cYQb02WI4dp3WZqITJP16Ll1qsjxtHc04Kr 0DRZ/xLPE6e3w80B29yrHZ90m0jHwm9ayyHoA00ctddL9hnmeBSJAuivZAvckwO0 p6wbbD1FQRfuEcYCNfgJHmWAl6fQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=s0VTbl6s2AdLh4LtCYuCUZrk647gV4NQcQQhRLyNFUYBpn8GBGh+FD2+h5u3uc /h1KBQeXxeHrznvArRaFV7wi2fCS02db4N0Cpl+Xf07w/Mqu5TBf2LPKMtITZc2H 5TXvT00ool71qoi21dc6QA+jnbH3qxTQW55xgUy16B4yk=; Received: (qmail 476 invoked by alias); 20 Apr 2012 04:59:01 -0000 Received: (qmail 464 invoked by uid 22791); 20 Apr 2012 04:59:00 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f51.google.com (HELO mail-pz0-f51.google.com) (209.85.210.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Apr 2012 04:58:45 +0000 Received: by dadz8 with SMTP id z8so12103363dad.10 for ; Thu, 19 Apr 2012 21:58:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=+q7La7m1LDVVwynBmutidAivAWz05W+2yXGypXTxEnw=; b=jHZnohWknVZiqCa7aCt0e8h2yVQtyOyp9vxxdn9V+anHAXZVPizHXX4AXrfJeYKmcd pEqzNxsgOIxrbKU3K/9A4ww6yck7SloZz7M4qlAaZ4WRyLcfrLAaOWUFhVJXRpMlJoyT t3dlOeyHp7+yMqqg232o+2HxRtt+WHbuGQw7yZppU+wuswdcA6esiujb3A67LRxXLOa7 jXUCJ2q5v78HRJG96/D1p5MMpJl+/W+etOM9sipxBLxEHdXko5cSl3P6+KbKlU+sSpfr 2DguQsUfVXAuJondhd7EmQLHCGvlfqDMDmj0bwTC7ZM56EQa70ACBzEuGOIlIMZAxuWF MOVw== Received: by 10.68.191.4 with SMTP id gu4mr4756943pbc.125.1334897924950; Thu, 19 Apr 2012 21:58:44 -0700 (PDT) Received: by 10.68.191.4 with SMTP id gu4mr4756924pbc.125.1334897924841; Thu, 19 Apr 2012 21:58:44 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id qb8sm4239017pbb.12.2012.04.19.21.58.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Apr 2012 21:58:44 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Ignore stacks when deciding when to GC Date: Thu, 19 Apr 2012 21:58:43 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmNiWrJShP3EFAnTeOhNh3AUzKPxDbHE0i0YIKGEdoUHoEZaEHl+2pKPagwMJKLw+gUPMbTmD3IcUjzkkEWeNMwIdJhfH51GJxvVZF8ez+d2U643HXGNZf0rFRfsafL+MsnKvdjWXppGyz02+no0cmdS7mRIxBJIcLSr8IQC62lJtC84lo= X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch to libgo ignores space allocated for goroutine stacks when deciding when to next run the garbage collector. On systems that support split stacks this does nothing, as on those systems the stacks are allocated by the split stack code. On systems that do not support split stacks this doesn't let the large amount of memory allocated for stacks cause the system to delay GC unreasonably. This patch also does a couple of other minor things. The heap bitmap bits are allocated in page size units. This fixes a problem on PPC GNU/Linux which uses a larger page size than x86. Also this clears the ucontext_t field in the G structure when it is put on the free list. This prevents the GC from thinking that old register values, now meaningless, are valid pointers requiring data to be kept in memory. Bootstrapped on x86_64-unknown-linux-gnu and powerpc64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian diff -r c8d973732b42 libgo/runtime/malloc.goc --- a/libgo/runtime/malloc.goc Thu Apr 19 21:46:43 2012 -0700 +++ b/libgo/runtime/malloc.goc Thu Apr 19 21:50:27 2012 -0700 @@ -72,7 +72,7 @@ npages = size >> PageShift; if((size & PageMask) != 0) npages++; - s = runtime_MHeap_Alloc(&runtime_mheap, npages, 0, !(flag & FlagNoGC)); + s = runtime_MHeap_Alloc(&runtime_mheap, npages, 0, 1); if(s == nil) runtime_throw("out of memory"); size = npages< + #include "runtime.h" #include "arch.h" #include "malloc.h" @@ -918,7 +920,7 @@ uint64 stacks_sys; stacks_inuse = 0; - stacks_sys = 0; + stacks_sys = runtime_stacks_sys; for(m=runtime_allm; m; m=m->alllink) { runtime_purgecachedstats(m); // stacks_inuse += m->stackalloc->inuse; @@ -1020,7 +1022,7 @@ stealcache(); cachestats(); - mstats.next_gc = mstats.heap_alloc+mstats.heap_alloc*gcpercent/100; + mstats.next_gc = mstats.heap_alloc+(mstats.heap_alloc-runtime_stacks_sys)*gcpercent/100; m->gcing = 0; m->locks++; // disable gc during the mallocs in newproc @@ -1329,6 +1331,8 @@ void runtime_MHeap_MapBits(MHeap *h) { + size_t page_size; + // Caller has added extra mappings to the arena. // Add extra mappings of bitmap words as needed. // We allocate extra bitmap pieces in chunks of bitmapChunk. @@ -1342,6 +1346,9 @@ if(h->bitmap_mapped >= n) return; + page_size = getpagesize(); + n = (n+page_size-1) & ~(page_size-1); + runtime_SysMap(h->arena_start - n, n - h->bitmap_mapped); h->bitmap_mapped = n; } diff -r c8d973732b42 libgo/runtime/proc.c --- a/libgo/runtime/proc.c Thu Apr 19 21:46:43 2012 -0700 +++ b/libgo/runtime/proc.c Thu Apr 19 21:50:27 2012 -0700 @@ -46,6 +46,8 @@ # define StackMin 2 * 1024 * 1024 #endif +uintptr runtime_stacks_sys; + static void schedule(G*); typedef struct Sched Sched; @@ -1091,6 +1093,7 @@ m->lockedg = nil; } gp->idlem = nil; + runtime_memclr(&gp->context, sizeof gp->context); gfput(gp); if(--runtime_sched.gcount == 0) runtime_exit(0); @@ -1288,6 +1291,7 @@ *ret_stacksize = stacksize; newg->gcinitial_sp = *ret_stack; newg->gcstack_size = stacksize; + runtime_xadd(&runtime_stacks_sys, stacksize); #endif } return newg; diff -r c8d973732b42 libgo/runtime/runtime.h --- a/libgo/runtime/runtime.h Thu Apr 19 21:46:43 2012 -0700 +++ b/libgo/runtime/runtime.h Thu Apr 19 21:50:27 2012 -0700 @@ -463,3 +463,8 @@ }; void __go_register_gc_roots(struct root_list*); + +// Size of stack space allocated using Go's allocator. +// This will be 0 when using split stacks, as in that case +// the stacks are allocated by the splitstack library. +extern uintptr runtime_stacks_sys;