From nobody Tue Oct 12 23:45:41 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 6DCB81803099; Tue, 12 Oct 2021 23:45:42 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HTXNQ1NfJz4s0D; Tue, 12 Oct 2021 23:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3E7821D7A3; Tue, 12 Oct 2021 23:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19CNjfX5093121; Tue, 12 Oct 2021 23:45:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19CNjfYo093120; Tue, 12 Oct 2021 23:45:41 GMT (envelope-from git) Date: Tue, 12 Oct 2021 23:45:41 GMT Message-Id: <202110122345.19CNjfYo093120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 19e008e7f79c - main - crt_malloc: Be more persistent when handling mmap() failure List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 19e008e7f79ce55182d227be8513b3fa520471d8 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=19e008e7f79ce55182d227be8513b3fa520471d8 commit 19e008e7f79ce55182d227be8513b3fa520471d8 Author: Konstantin Belousov AuthorDate: 2021-10-11 16:13:31 +0000 Commit: Konstantin Belousov CommitDate: 2021-10-12 23:37:09 +0000 crt_malloc: Be more persistent when handling mmap() failure In the situation with limited address space, together with fragmentation, it is possible for mmap() request in morecore() to fail when asking for required size + NPOOLPAGES, but succeed without the addend. Retry allocation there. PR: 259076 Reported by: Denis Koreshkov Reviewed by: arichardson Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32474 --- libexec/rtld-elf/rtld_malloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld_malloc.c b/libexec/rtld-elf/rtld_malloc.c index f22c3c727c73..64218b5bb786 100644 --- a/libexec/rtld-elf/rtld_malloc.c +++ b/libexec/rtld-elf/rtld_malloc.c @@ -184,7 +184,9 @@ morecore(int bucket) nblks = 1; } if (amt > pagepool_end - pagepool_start) - if (morepages(amt/pagesz + NPOOLPAGES) == 0) + if (morepages(amt / pagesz + NPOOLPAGES) == 0 && + /* Retry with min required size */ + morepages(amt / pagesz) == 0) return; op = (union overhead *)pagepool_start; pagepool_start += amt; @@ -269,6 +271,8 @@ morepages(int n) } } + if (pagepool_start == MAP_FAILED) + pagepool_start = 0; offset = (uintptr_t)pagepool_start - rounddown2( (uintptr_t)pagepool_start, pagesz);