From patchwork Sun Jul 9 18:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700909 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4830043wrs; Sun, 9 Jul 2023 11:42:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnZrbeMQfsqvdZzZAmyni3Ktw3RyXs4rN8YDbjHhFM+9cnYKwUa3LngOSzJF3wGhYJHzhN X-Received: by 2002:a0c:8d45:0:b0:630:1531:acf2 with SMTP id s5-20020a0c8d45000000b006301531acf2mr8089579qvb.46.1688928156077; Sun, 09 Jul 2023 11:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688928156; cv=none; d=google.com; s=arc-20160816; b=ieyEXYne74JuXG2YH9fcWcny9qu3Q70Q2CBGfq7NlhMhJrYv6EBAW1oBJnCGvaKio7 vVmVmfVRTpROhzh7BGVxmJ2ehCg37Y9lO+qu6eOhOUc61t8T4dvk65tXbqdPMVhw6TLV 5GOEc4APfIdKQ0BdUfIe6I4m+bng6g6k3oBd1A/buYrQBLoTskv4oHRY9dfNyaZw7Mxj aP++0e6sRZhxm3WTKVvsDuMRrSlTiaooBKIw2w2utkdWl6ucvTzk8zTJFl1wdXmD4c71 dX1RdhabUnz0NcNX7QjWd9ttqGggxnPJKdK55eDFjSVDAdGTXFJ2C7Ww2dWpvjBcpeTo Yitw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QRxmyw2NI294w3E1OCW/a4A3Z0jUfk7Gsk9X8Q/8iho=; fh=TaZCENeteU7KJWs7MRbYIL1hiC/3Q7pMtkyczfsO15k=; b=Gx/GnkOKrFQaU0tWbLgG+n4VfqO/w6JKws10JzjI+/ZT4MpwUIcQ+F7ZuR6h0c2cr3 +4Te5IDgjDAob7F8fS28hRhv9fEcSnDE3t2VBRpxozlpb3cLXXPZOdadSEJHeGPK4wG6 QyYRdj+pOAj0W8+F7wxj9FYcHugJAbgEwy7btQ5c/A8PqPLj21Nc6NUeKKZtVzVaGUEV qNKSVMgR3j1co6euhWQx3do88rfN5pudag1z3CP9MJ8gVHrNBbmvDKl5vkj21DB9GNK7 P4OFbH/o+uc41+kmSY+gZAPGPS1NlFLEnIWXhhmB2iovcKkyh0E9xtryHskHXU1YhYRR 3ljg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Owl5H1sH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g4-20020a0cdf04000000b00635dd2f5284si4750681qvl.376.2023.07.09.11.42.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 11:42:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Owl5H1sH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIZED-00052V-Fj; Sun, 09 Jul 2023 14:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIZE0-0003cP-7Y for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:38 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIZDy-0004HP-NF for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:35 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbfa811667so19655015e9.1 for ; Sun, 09 Jul 2023 11:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688927613; x=1691519613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QRxmyw2NI294w3E1OCW/a4A3Z0jUfk7Gsk9X8Q/8iho=; b=Owl5H1sHBMbZEz/AJsmVnI8Pxc5Sm9o908wqmw5nqZScNiDYcJxe9LnazFZqnye1HZ Ri1jRZqald3TGzUARdgTKa2JFhFQ99phScy/YkT9aEzWro11pth83nhsGgy5fyQGVOAt Azq1X5Yo/ZBCGYiTr5BB/mzcozPxz263OS1lS/0BBmA3SfoygfyDWtjFVZKRgwzQNOlF hR0SIaCbLlH58CiCQhxI//QuIiOYSNsz49bHmV3dRqE46rs4SaaAgywJd8UV83V8sfy4 aon6FBX8G6Y20RCWC2JDUIDiHbTZzv9gICKjzO0cF+MJ371hOJPazmFnfU0D2bwg5rnZ 0JUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688927613; x=1691519613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QRxmyw2NI294w3E1OCW/a4A3Z0jUfk7Gsk9X8Q/8iho=; b=Ga7kKIPWMmLksG7lx86Ufj6KuzWrLTQUu6FzZEqCnC6GXNhJ9bYso96RysKxlZKYvn Khr0PeKcdDs0mAaAKTrL2Hcft+zVsoE82iai8qyb8j5BnZGGAuv6z7c6IYrBJ8aGvbtz pXFg3jATXEu2kNSP9G2Qw5uC7CaunyWWR9cdgSvfL/v3OH0AnzXcfkSzQ+uEKxS+/yDN o6msye9dcjhk6Y5grYPJ9YaxuTFgWiC4hn1Kk0XGy1yx/fLiZbXcpGyHfADjplI07UcE 7KSc17e91lPGl0Leq7dnNmXETas0z0zp8vGI1Y44D4kZ7de6m4uq505EkOLw2M/pbnIb K+CA== X-Gm-Message-State: ABy/qLbZq3KuBu5CpHky1AwKoaT3+A0ERmP+74LrvAEwrWlnM3q8yJc9 ifEOsdLMEwKbFS3V2uyMlvU/otu4vlzY/OhMNAHZ+w== X-Received: by 2002:adf:e4cb:0:b0:313:e88d:e6d3 with SMTP id v11-20020adfe4cb000000b00313e88de6d3mr13286461wrm.14.1688927613516; Sun, 09 Jul 2023 11:33:33 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id e17-20020a5d4e91000000b0031433760a92sm9635256wru.115.2023.07.09.11.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 11:33:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, Warner Losh , Kyle Evans Subject: [PATCH 34/45] bsd-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Sun, 9 Jul 2023 19:29:19 +0100 Message-Id: <20230709182934.309468-68-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709182934.309468-1-richard.henderson@linaro.org> References: <20230709182934.309468-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use the interval tree to find empty space, rather than probing each page in turn. Cc: Warner Losh Cc: Kyle Evans Signed-off-by: Richard Henderson Reviewed-bt: Warner Losh Message-Id: <20230707204054.8792-18-richard.henderson@linaro.org> --- bsd-user/mmap.c | 48 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 07b5b8055e..aca8764356 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -222,50 +222,16 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong alignment) { - abi_ulong addr; - abi_ulong end_addr; - int prot; - int looped = 0; + abi_ulong ret; - if (size > reserved_va) { - return (abi_ulong)-1; + ret = page_find_range_empty(start, reserved_va, size, alignment); + if (ret == -1 && start > TARGET_PAGE_SIZE) { + /* Restart at the beginning of the address space. */ + ret = page_find_range_empty(TARGET_PAGE_SIZE, start - 1, + size, alignment); } - size = HOST_PAGE_ALIGN(size) + alignment; - end_addr = start + size; - if (end_addr > reserved_va) { - end_addr = reserved_va + 1; - } - addr = end_addr - qemu_host_page_size; - - while (1) { - if (addr > end_addr) { - if (looped) { - return (abi_ulong)-1; - } - end_addr = reserved_va + 1; - addr = end_addr - qemu_host_page_size; - looped = 1; - continue; - } - prot = page_get_flags(addr); - if (prot) { - end_addr = addr; - } - if (end_addr - addr >= size) { - break; - } - addr -= qemu_host_page_size; - } - - if (start == mmap_next_start) { - mmap_next_start = addr; - } - /* addr is sufficiently low to align it up */ - if (alignment != 0) { - addr = (addr + alignment) & ~(alignment - 1); - } - return addr; + return ret; } /*