From nobody Thu Jun 13 20:15:12 2024 X-Original-To: dev-commits-src-all@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 4W0YYY0l22z5PHLn; Thu, 13 Jun 2024 20:15:13 +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 4W0YYY0HLbz40br; Thu, 13 Jun 2024 20:15:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718309713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=demhMVI7uRLdVdBgxafaLz12L2SGi1p3tlcAF0noQOY=; b=cJIWBFLAz5LC3CnyBZoE9FBZy0blvWiCKEpscB+4RXrwoBHF/w/IIuwhNowhyqc8M1t9qS xlNqDLwkhBREBYb4d6Eqo1IghyHvlYYSr30/80ArcxfD/jSkhySvCfsE1miHF5m6g1gDly N7+L6ToAMzKXcK40lNlJZrjbP+9tA+4jPm3uUP/xthvg2NvTK9txwVoxAYlj+sBuvKtNYU u2WBTCWm0SO1YZ9+1KHo8kkz9QffCj27HqrFwZzNB4F/vYiE6R4ZsDiZMuqByzkSXmbv0Z vbr3a/gIRMyhPSfCOG822gl2J2lgmP+8TmVXjbrWvw7Ms59iwgNh6lmq6AWZPw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718309713; a=rsa-sha256; cv=none; b=CKgjuG2HdhTTOweFruHOQdJ8e6BlkPlirL3TuJj0ORz6ieuUn4QKYbRP/+BPB+p449AuzA +18oqqsjLzKkguQBIrCsrcyXXX+d8rKvtKz6T6SnqwPbdfED0LYYo5ljK/ORYxCnLgTqlg mA38ATlWVGy3oqQzuH/EEYy7kP3iYN1C43P/4uLPmqIoy2h9v57Q7b5xbCE6N1/C7RQXhQ 5zoxBDDV0E1gM9IwRVIEQMUc4xXT4JJYN9FCYbI+jpp3rRcGA8cu5s/1dUEaEV0IOHPF/0 hYirBgvWEj3xyA7di/patoY8hsWaMa0eijNIP8j5DXpTX3/maqoN4MwU7J+xIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718309713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=demhMVI7uRLdVdBgxafaLz12L2SGi1p3tlcAF0noQOY=; b=QyFcWQENWLByJnT5sVoyAW92tgispXI11/RDx3zfgAX7ExlNb1KCBvuF6468iRNjebUGxJ L/d+uJhp/vvRs/3/teDYPWfm+SVZ+fDMi91YNyQ+VastQ2FM2hPY2u2dk10CD19/LlQbnh SA+ncgbHi4hO4YLQs2IrDTZOusBsxmPYc9xaT5oJZdSz5hDnOT24kYvPBmC5+EfK+xej49 teW5ZZHQ0JJmNIWFAvxWxCHUHOJiziUT4I2rBftdFJFXkWPuoLgnoNHFs9ilRGK5sxjoO6 A1tYVDnVDpe3SJ1c9Q3H3+I3EcdJPXKIvQofcD2Q/SMmwfGtb2/i3/e6PV7JqQ== 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 4W0YYX70ZkzrGG; Thu, 13 Jun 2024 20:15:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45DKFCww041099; Thu, 13 Jun 2024 20:15:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45DKFCaX041096; Thu, 13 Jun 2024 20:15:12 GMT (envelope-from git) Date: Thu, 13 Jun 2024 20:15:12 GMT Message-Id: <202406132015.45DKFCaX041096@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Cox Subject: git: 268f19aacc6a - main - vm: Reduce address space fragmentation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: alc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 268f19aacc6af8f64c438e8515213023a2e66ed7 Auto-Submitted: auto-generated The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=268f19aacc6af8f64c438e8515213023a2e66ed7 commit 268f19aacc6af8f64c438e8515213023a2e66ed7 Author: Alan Cox AuthorDate: 2024-06-09 16:58:27 +0000 Commit: Alan Cox CommitDate: 2024-06-13 20:13:45 +0000 vm: Reduce address space fragmentation jemalloc performs two types of virtual memory allocations: (1) large chunks of virtual memory, where the chunk size is a multiple of a superpage and explicitly aligned, and (2) small allocations, mostly 128KB, where no alignment is requested. Typically, it starts with a small allocation, and over time it makes both types of allocation. With anon_loc being updated on every allocation, we wind up with a repeating pattern of a small allocation, a large gap, and a large, aligned allocation. (As an aside, we wind up allocating a reservation for these small allocations, but it will never fill because the next large, aligned allocation updates anon_loc, leaving a gap that will never be filled with other small allocations.) With this change, anon_loc isn't updated on every allocation. So, the small allocations will be clustered together, the large allocations will be clustered together, and there will be fewer gaps between the anonymous memory allocations. In addition, I see a small reduction in reservations allocated (e.g., 1.6% during buildworld), fewer partially populated reservations, and a small increase in 64KB page promotions on arm64. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39845 --- sys/vm/vm_map.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 3c7afcb6642f..fa71bb8a01d6 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2247,8 +2247,15 @@ again: rv = vm_map_insert(map, object, offset, *addr, *addr + length, prot, max, cow); } - if (rv == KERN_SUCCESS && update_anon) - map->anon_loc = *addr + length; + + /* + * Update the starting address for clustered anonymous memory mappings + * if a starting address was not previously defined or an ASLR restart + * placed an anonymous memory mapping at a lower address. + */ + if (update_anon && rv == KERN_SUCCESS && (map->anon_loc == 0 || + *addr < map->anon_loc)) + map->anon_loc = *addr; done: vm_map_unlock(map); return (rv); @@ -4041,9 +4048,6 @@ vm_map_delete(vm_map_t map, vm_offset_t start, vm_offset_t end) entry->object.vm_object != NULL) pmap_map_delete(map->pmap, entry->start, entry->end); - if (entry->end == map->anon_loc) - map->anon_loc = entry->start; - /* * Delete the entry only after removing all pmap * entries pointing to its pages. (Otherwise, its