From owner-svn-src-head@freebsd.org Mon Sep 2 08:03:29 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B5806D5C34; Mon, 2 Sep 2019 08:03:29 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46MMz54NB5z4Pmg; Mon, 2 Sep 2019 08:03:29 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7AAE9F130; Mon, 2 Sep 2019 08:03:29 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8283Tuf067815; Mon, 2 Sep 2019 08:03:29 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8283T7t067814; Mon, 2 Sep 2019 08:03:29 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <201909020803.x8283T7t067814@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Mon, 2 Sep 2019 08:03:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351690 - head/libexec/rtld-elf X-SVN-Group: head X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: head/libexec/rtld-elf X-SVN-Commit-Revision: 351690 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Sep 2019 08:03:29 -0000 Author: brooks Date: Mon Sep 2 08:03:29 2019 New Revision: 351690 URL: https://svnweb.freebsd.org/changeset/base/351690 Log: Remove remnants of optimization for > pagesize allocations. In the past, this allocator seems to have allocated things larger than a page seperately. Much of this code was removed at some point (perhaps along with sbrk() used) so remove the rest. Instead, keep allocating in power-of-two bins up to FIRST_BUCKET_SIZE << (NBUCKETS - 1). If we want something more efficent, we should use a fancier allocator. While here, remove some vestages of sbrk() use. Most importantly, don't try to page align the pagepool since it's always page aligned by mmap(). Reviewed by: kib Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D21453 Modified: head/libexec/rtld-elf/rtld_malloc.c Modified: head/libexec/rtld-elf/rtld_malloc.c ============================================================================== --- head/libexec/rtld-elf/rtld_malloc.c Mon Sep 2 08:02:55 2019 (r351689) +++ head/libexec/rtld-elf/rtld_malloc.c Mon Sep 2 08:03:29 2019 (r351690) @@ -89,15 +89,15 @@ static int morepages(int n); #define MAGIC 0xef /* magic # on accounting info */ /* - * nextf[i] is the pointer to the next free block of size 2^(i+3). The - * smallest allocatable block is 8 bytes. The overhead information - * precedes the data area returned to the user. + * nextf[i] is the pointer to the next free block of size + * (FIRST_BUCKET_SIZE << i). The overhead information precedes the data + * area returned to the user. */ +#define FIRST_BUCKET_SIZE 8 #define NBUCKETS 30 static union overhead *nextf[NBUCKETS]; static int pagesz; /* page size */ -static int pagebucket; /* page size bucket */ /* * The array of supported page sizes is provided by the user, i.e., the @@ -112,50 +112,25 @@ __crt_malloc(size_t nbytes) { union overhead *op; int bucket; - ssize_t n; size_t amt; /* - * First time malloc is called, setup page size and - * align break pointer so all data will be page aligned. + * First time malloc is called, setup page size. */ - if (pagesz == 0) { - pagesz = n = pagesizes[0]; - if (morepages(NPOOLPAGES) == 0) - return NULL; - op = (union overhead *)(pagepool_start); - n = n - sizeof (*op) - ((long)op & (n - 1)); - if (n < 0) - n += pagesz; - if (n) { - pagepool_start += n; - } - bucket = 0; - amt = 8; - while ((unsigned)pagesz > amt) { - amt <<= 1; - bucket++; - } - pagebucket = bucket; - } + if (pagesz == 0) + pagesz = pagesizes[0]; /* * Convert amount of memory requested into closest block size * stored in hash buckets which satisfies request. * Account for space used per block for accounting. */ - if (nbytes <= (unsigned long)(n = pagesz - sizeof(*op))) { - amt = 8; /* size of first bucket */ - bucket = 0; - n = -sizeof(*op); - } else { - amt = pagesz; - bucket = pagebucket; - } - while (nbytes > amt + n) { + amt = FIRST_BUCKET_SIZE; + bucket = 0; + while (nbytes > amt - sizeof(*op)) { amt <<= 1; - if (amt == 0) - return (NULL); bucket++; + if (amt == 0 || bucket >= NBUCKETS) + return (NULL); } /* * If nothing in hash bucket right now, @@ -200,18 +175,12 @@ morecore(int bucket) int amt; /* amount to allocate */ int nblks; /* how many blocks we get */ - /* - * sbrk_size <= 0 only for big, FLUFFY, requests (about - * 2^30 bytes on a VAX, I think) or for a negative arg. - */ - if ((unsigned)bucket >= NBBY * sizeof(int) - 4) - return; - sz = 1 << (bucket + 3); + sz = FIRST_BUCKET_SIZE << bucket; if (sz < pagesz) { amt = pagesz; nblks = amt / sz; } else { - amt = sz + pagesz; + amt = sz; nblks = 1; } if (amt > pagepool_end - pagepool_start)