From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22293 invoked by alias); 21 Oct 2011 09:53:05 -0000 Received: (qmail 22279 invoked by uid 22791); 21 Oct 2011 09:53:04 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 09:52:49 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9L9qkRR011422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Oct 2011 05:52:46 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9L9qj2Z023894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Oct 2011 05:52:46 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p9L9qjU0015784; Fri, 21 Oct 2011 11:52:45 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p9L9qier015783; Fri, 21 Oct 2011 11:52:44 +0200 Date: Fri, 21 Oct 2011 10:29:00 -0000 From: Jakub Jelinek To: Richard Guenther Cc: Andi Kleen , gcc-patches@gcc.gnu.org, Andi Kleen Subject: Re: [PATCH 1/3] Add missing page rounding of a page_entry Message-ID: <20111021095244.GR2210@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <1319176370-26071-1-git-send-email-andi@firstfloor.org> <1319176370-26071-2-git-send-email-andi@firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg01946.txt.bz2 On Fri, Oct 21, 2011 at 11:42:26AM +0200, Richard Guenther wrote: > On Fri, Oct 21, 2011 at 7:52 AM, Andi Kleen wrote: > > From: Andi Kleen > > > > This one place in ggc forgot to round page_entry->bytes to the > > next page boundary, which lead to all the heuristics in freeing to > > check for continuous memory failing. Round here too, like all other > > allocators already do. The memory consumed should be the same > > for MMAP because the kernel would round anyways. It may slightly > > increase memory usage when malloc groups are used. > > > > This will also increase the hitrate on the free page list > > slightly. > > > 2011-10-18  Andi Kleen   > > > >        * ggc-page.c (alloc_pages): Always round up entry_size. As I said in the PR, ROUND_UP should make the previous if (entry_size < G.pagesize) entry_size = G.pagesize; completely unnecessary. Additionally, seeing what ROUND_UP does, it seems horribly expensive when the second argument is not a constant. #define ROUND_UP(x, f) (CEIL (x, f) * (f)) #define CEIL(x,y) (((x) + (y) - 1) / (y)) as G.pagesize is variable, I'm afraid the compiler has to divide and multiply (or perhaps divide and modulo), there is nothing hinting that G.pagesize is a power of two and thus (entry_page_size + G.pagesize - 1) & (G.pagesize - 1); will work. ggc-page.c relies on G.pagesize to be a power of two though (and I hope no sane host uses something else), as otherwise G.lg_pagesize would be -1 and we shift by that amount, so that would be undefined behavior. > > diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c > > index 2da99db..ba88e3f 100644 > > --- a/gcc/ggc-page.c > > +++ b/gcc/ggc-page.c > > @@ -736,6 +736,7 @@ alloc_page (unsigned order) > >   entry_size = num_objects * OBJECT_SIZE (order); > >   if (entry_size < G.pagesize) > >     entry_size = G.pagesize; > > +  entry_size = ROUND_UP (entry_size, G.pagesize); > > > >   entry = NULL; > >   page = NULL; > > -- > > 1.7.5.4 > > > > Jakub