From patchwork Sat Apr 2 15:34:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 605424 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qcj3X4tkZz9s9W for ; Sun, 3 Apr 2016 02:34:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=DalpRgbc; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=O/cfNSHN9X727OF4 ocWQlnYyh3gqa75N++l5O6lJt6Q0dXEl2vRYWtXxY/gs127v6BHkddFDFgsa+g2x 4/Ra5+Rkhy6wLdkmyB+uWUhjMddPFBbIzfGodGgixlFJtp96u+Gh28FVp10L15HX Ch/y4TUAqy3JjFUJKg8gOz9hAOs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=XouRwit8aaVhpTRPptUNEv vHq1M=; b=DalpRgbcHmUqg+CSRi6EVKCoO3Afu+2Gvy4tnLjKFsfWGprMrGlOLD fXDmHwadOcxbCKqSuM9HeXtELOC1yR9p5odqoTK4OjFpLbSeNvsLdwQNn/V/fdyJ 4yhm8cDdad9Eutd8co4664Z8WZh1ZBM6niaJ+rhKCvOGLDFiU62DI= Received: (qmail 26052 invoked by alias); 2 Apr 2016 15:34:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 26034 invoked by uid 89); 2 Apr 2016 15:34:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=backing, Hx-languages-length:1241, operate, Worst X-HELO: mga02.intel.com X-ExtLoop1: 1 Date: Sat, 2 Apr 2016 08:34:21 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] Reduce number of mmap calls from __libc_memalign in ld.so Message-ID: <20160402153421.GA28788@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) __libc_memalign in ld.so allocates one page at a time and tries to optimize consecutive __libc_memalign calls by hoping that the next mmap is after the current memory allocation. However, the kernel hands out mmap addresses in top-down order, so this optimization in practice never happens, with the result that we have more mmap calls and waste a bunch of space for each __libc_memalign. This change makes __libc_memalign to mmap one page extra. Worst case, the kernel never puts a backing page behind it, but best case it allows __libc_memalign to operate much much better. For elf/tst-align --direct, it reduces number of mmap calls from 12 to 9. Tested on x86-64. OK for master? H.J. --- * elf/dl-minimal.c (__libc_memalign): Mmap one extra page. --- elf/dl-minimal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 762e65b..d6f87f1 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -75,6 +75,7 @@ __libc_memalign (size_t align, size_t n) return NULL; nup = GLRO(dl_pagesize); } + nup += GLRO(dl_pagesize); page = __mmap (0, nup, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); if (page == MAP_FAILED)