From nobody Sat Aug 12 06:29:05 2023 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 4RN9jZ1bKmz4TvPv; Sat, 12 Aug 2023 06:29:06 +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 4RN9jY3rJYz3Xnl; Sat, 12 Aug 2023 06:29:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821745; 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=IqYxQOtvji+BJ8UJtMJ6bNUncIwGWBmbUbLCkeOgKg4=; b=rYWVxf736clXOjKALQ5aRsCKOMhiD0Uz/fm7sTU9NtD2//JwNFwSyoRzBAAk8hcrScKBi7 K+/ZNAPo7xeKklgxG6Gmv9NrCpBRJdQYOOqed0DNSc6jUjuHaXLxUtbKp0Lr2/H9r5uNjR rciChSv6TeLh0oahu+3G22AoOKbzOT9/j055arSnjQOoMzUYgp2teO9BO8M0aLikXQ3vpC eaNSK5qwd+IjQb212BtLW/Ml1L2tuY4+bM6auUk1KArjuv68ugO3jnG6/qKxH3ZK/7SHsU cIBAw0vM6jjfNRdgLpx5a1sIEnPwPTFdjgAMQxnkXrPVohGcDo4dyIKk4QUNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821745; 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=IqYxQOtvji+BJ8UJtMJ6bNUncIwGWBmbUbLCkeOgKg4=; b=SZ0ru+UVAlmqEgpPOBGtbSY3b5n0MFnozE+KkaG0kzCDSAA4Ed4Y6arzAkJE1TzicUxxkP RhawpTc50RCQ3OnjIs2YzUG1+M7ZjkU/FCZuNqUWDSGNIrhXdEdGTYE1cNQ3s9eQFmcAzx 2BIU3C8xKcBHS+SA48mfzqEXVE7Q6Q0E+yZ9QEiwaP/Etl4RYVbuLyvASJ99996Dp2lq5r 4shbhIhK0q57G3OUDWMKAa5N7BnJOKid5BtqGyuqrPkuHH7qefxmjl+ucYqwIwDtXnF2Jf tfY1XD+S+jwOHV0Vin7yZ7pe0Q2yb2JWpH+IW7vQrEQHZnkqCbQsQIzR/Hpkfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691821745; a=rsa-sha256; cv=none; b=qIfZUnvKR/DXdLldeTngOn1Ikr8CXVJLUg3VAvRaRvlwWUUtNbF3GbaYz8vzcGpGyQUbI5 VqRPfaFiuHtc9hll7YJNUDOB0YyLDFd4sNCkfIlOvO2MmVaEt8Mzbb43f5i7zIRfteVciC 09usbXlZz64Wdaoy12XYjX1y4QCAv9hsrm2hBL5GCgySplY01F0QFTggN2xz2fLNKiaDFD dGL6UvWUQIM7lRhRrHPS9xn3cE4uSQmhbGloiD4+xjw0rAw83iSv8c4JoQv4ipMx3/cL3G CEDwqFeqjVM81cNg5FT5fBJy5iWi88WvpWo3CMxbFAMrCB9yGLkwI3BAjvBbSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RN9jY1Zvjz18nQ; Sat, 12 Aug 2023 06:29:05 +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 37C6T5ph024687; Sat, 12 Aug 2023 06:29:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37C6T5nk024684; Sat, 12 Aug 2023 06:29:05 GMT (envelope-from git) Date: Sat, 12 Aug 2023 06:29:05 GMT Message-Id: <202308120629.37C6T5nk024684@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: ba41b0de3ef2 - main - Add vm_map_insert1(9) 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: ba41b0de3ef2b29c5c1155c7550785ed4b491bd8 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=ba41b0de3ef2b29c5c1155c7550785ed4b491bd8 commit ba41b0de3ef2b29c5c1155c7550785ed4b491bd8 Author: Konstantin Belousov AuthorDate: 2023-07-19 16:44:18 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-12 06:28:13 +0000 Add vm_map_insert1(9) The function returns the newly created entry. Use vm_map_insert1() in stack grow code to avoid gap entry re-lookup. The comment update for vm_map_try_merge_entries() was suggested by dougm. Suggested by: alc Reviewed by: alc, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41099 --- sys/vm/vm_map.c | 75 +++++++++++++++++++++++++++++++++++++++------------------ sys/vm/vm_map.h | 2 +- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 2829c015359a..f8a2903567a6 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -1601,19 +1601,16 @@ vm_map_lookup_entry( } /* - * vm_map_insert: - * - * Inserts the given VM object into the target map at the - * specified address range. - * - * Requires that the map be locked, and leaves it so. - * - * If object is non-NULL, ref count must be bumped by caller - * prior to making call to account for the new entry. + * vm_map_insert1() is identical to vm_map_insert() except that it + * returns the newly inserted map entry in '*res'. In case the new + * entry is coalesced with a neighbor or an existing entry was + * resized, that entry is returned. In any case, the returned entry + * covers the specified address range. */ -int -vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, - vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow) +static int +vm_map_insert1(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow, + vm_map_entry_t *res) { vm_map_entry_t new_entry, next_entry, prev_entry; struct ucred *cred; @@ -1760,7 +1757,8 @@ charged: map->size += end - prev_entry->end; vm_map_entry_resize(map, prev_entry, end - prev_entry->end); - vm_map_try_merge_entries(map, prev_entry, next_entry); + *res = vm_map_try_merge_entries(map, prev_entry, + next_entry); return (KERN_SUCCESS); } @@ -1821,7 +1819,7 @@ charged: * other cases, which are less common. */ vm_map_try_merge_entries(map, prev_entry, new_entry); - vm_map_try_merge_entries(map, new_entry, next_entry); + *res = vm_map_try_merge_entries(map, new_entry, next_entry); if ((cow & (MAP_PREFAULT | MAP_PREFAULT_PARTIAL)) != 0) { vm_map_pmap_enter(map, start, prot, object, OFF_TO_IDX(offset), @@ -1831,6 +1829,27 @@ charged: return (KERN_SUCCESS); } +/* + * vm_map_insert: + * + * Inserts the given VM object into the target map at the + * specified address range. + * + * Requires that the map be locked, and leaves it so. + * + * If object is non-NULL, ref count must be bumped by caller + * prior to making call to account for the new entry. + */ +int +vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow) +{ + vm_map_entry_t res; + + return (vm_map_insert1(map, object, offset, start, end, prot, max, + cow, &res)); +} + /* * vm_map_findspace: * @@ -2318,13 +2337,14 @@ vm_map_merged_neighbor_dispose(vm_map_t map, vm_map_entry_t entry) /* * vm_map_try_merge_entries: * - * Compare the given map entry to its predecessor, and merge its precessor - * into it if possible. The entry remains valid, and may be extended. - * The predecessor may be deleted. + * Compare two map entries that represent consecutive ranges. If + * the entries can be merged, expand the range of the second to + * cover the range of the first and delete the first. Then return + * the map entry that includes the first range. * * The map must be locked. */ -void +vm_map_entry_t vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev_entry, vm_map_entry_t entry) { @@ -2334,7 +2354,9 @@ vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev_entry, vm_map_mergeable_neighbors(prev_entry, entry)) { vm_map_entry_unlink(map, prev_entry, UNLINK_MERGE_NEXT); vm_map_merged_neighbor_dispose(map, prev_entry); + return (entry); } + return (prev_entry); } /* @@ -4547,10 +4569,10 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, gap_bot = top; gap_top = addrbos + max_ssize; } - rv = vm_map_insert(map, NULL, 0, bot, top, prot, max, cow); + rv = vm_map_insert1(map, NULL, 0, bot, top, prot, max, cow, + &new_entry); if (rv != KERN_SUCCESS) return (rv); - new_entry = vm_map_entry_succ(prev_entry); KASSERT(new_entry->end == top || new_entry->start == bot, ("Bad entry start/end for new stack entry")); KASSERT((orient & MAP_STACK_GROWS_DOWN) == 0 || @@ -4561,10 +4583,17 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, ("new entry lacks MAP_ENTRY_GROWS_UP")); if (gap_bot == gap_top) return (KERN_SUCCESS); - rv = vm_map_insert(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE, + rv = vm_map_insert1(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE, VM_PROT_NONE, MAP_CREATE_GUARD | (orient == MAP_STACK_GROWS_DOWN ? - MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP)); + MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP), &gap_entry); if (rv == KERN_SUCCESS) { + KASSERT((gap_entry->eflags & MAP_ENTRY_GUARD) != 0, + ("entry %p not gap %#x", gap_entry, gap_entry->eflags)); + KASSERT((gap_entry->eflags & (MAP_ENTRY_STACK_GAP_DN | + MAP_ENTRY_STACK_GAP_UP)) != 0, + ("entry %p not stack gap %#x", gap_entry, + gap_entry->eflags)); + /* * Gap can never successfully handle a fault, so * read-ahead logic is never used for it. Re-use @@ -4574,8 +4603,6 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, * store the original stack protections in the * object offset. */ - gap_entry = orient == MAP_STACK_GROWS_DOWN ? - vm_map_entry_pred(new_entry) : vm_map_entry_succ(new_entry); gap_entry->next_read = sgp; gap_entry->offset = prot; } else { diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 82320196b98b..08bc6532b8b8 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -526,7 +526,7 @@ vm_map_entry_succ(vm_map_entry_t entry) int vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_prot_t new_prot, vm_prot_t new_maxprot, int flags); int vm_map_remove (vm_map_t, vm_offset_t, vm_offset_t); -void vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev, +vm_map_entry_t vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev, vm_map_entry_t entry); void vm_map_startup (void); int vm_map_submap (vm_map_t, vm_offset_t, vm_offset_t, vm_map_t);