From patchwork Fri Jul 7 20:40:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700060 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066526wrs; Fri, 7 Jul 2023 13:45:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKXHEpVZEtlUgJ9euZkI6HpFvXFgHMJgSDJYAnUsIr0Q1H+WkU3FJOJqMyZ7PPx9YZfZMh X-Received: by 2002:ac8:5bd3:0:b0:402:d5b0:6324 with SMTP id b19-20020ac85bd3000000b00402d5b06324mr9051208qtb.45.1688762735928; Fri, 07 Jul 2023 13:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762735; cv=none; d=google.com; s=arc-20160816; b=0Sn02J1KY6ohxDawS6e8uPlFPsnOQPUoZYpahCzDuVm09wrx2EDY8NrAYe+xeXJH4C NFdYXRyoQXvQW1AncW3YBRyRLCUm0DkyuO5GEOITZc4sXg8ih71Syu/Nl1MRNiamVHOh U5jF+Ej6oK2m5Z0lTQ1XcoXXZS2VytZeqS7yf/IOaPgTTWuUEkn/RAuBzs0nSvGwOhZ5 ZLoQ+RSvFn8hOC+JwOjjx+0qI86Li+O7xIY57IvX96DAYsfEKIxAJfzstWNkaue5LGGy LrF6MnTfk1bp1c9BYuImdN/TGImY/Fhuy3+/CndegY0dNFpztxEMd3Y3fpDRJu+T+/5L AF3A== 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=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; fh=c5yfIwOUC8JO1RlChQuc3YChZ5JSRT1D/lDsc4eQOLI=; b=Y6ilGYfKKVzyUhtJJl6conDo4RfLfHHpbmKoecEVhmT7l4FO0CJiuWLPjS48LIjHbP qu6qUKi0cZzvkV8keA3Ty8FYefSGOE+Z4hIBNCQQcN6aqjXrVrNHKYzAWnHCaklkp5xf 8qCUfLsRCktkIX05mmiEVr06QTatWH2ohvsnwh8jseXgGCwxSBWW5BTPQ86m+8wy5zLM 2mslcd+KKcZzTY0cRSVkvwaQWi3KURWnQ6YvHPJp6UbRmRs4Z3RL/mbBjhzMyjswzH1D rUkJ+sO3qOrGKFxvRVqYM0hiqQehUwkO9pL+6+HvqCqaq54boxx8nEbYBPlR1Osw3pDE YvEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqkcjVrj; 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 pi1-20020a05620a378100b00767471599e3si3249556qkn.253.2023.07.07.13.45.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:45:35 -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=hqkcjVrj; 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 1qHsGa-0004zS-IG; Fri, 07 Jul 2023 16:41:24 -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 1qHsGM-0004oG-DQ for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGK-0004m8-Ro for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbea147034so24480915e9.0 for ; Fri, 07 Jul 2023 13:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762467; x=1691354467; 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=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; b=hqkcjVrjecW9ZGOCxywyxtkSkvDxsHfzboWDqkQozjmmZlpNf4L6Lci466McRPMknX UZwT4OFF5rE4nlPv5DabmD0C3J6HdZ25OPT7fDFsu4p2tV/eeYOjd+YBXN4jFmwoPKeZ zxboOLhK3s5VLVj1dBrTtY4u2hbA4YPtn7q3Xuv79kyc+b8PywoalbHupzCSS0dE1/T4 eP6v70sfJ2JrPQSBd8uAfCdO/hB+bEAnLNz2+OCM3opQNTdHIoYz1NuoDMtvIJ4lpFp4 Lg/aJiYXq+x3Oek1TDjwvYUyBjgzoTgdUeuC6bFzGpua2YXpB+fNMKvst1XAvDPuvNGI jL2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762467; x=1691354467; 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=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; b=jirhNnmA1HZdmoxV5EihpO7I+Ldpq8wty3xajhv+QkLfbVyny/Bj49KHKdGvrqc1zx mtk0qRv4nkw3ircz8BU1jA5T/gAY9l2OW6Av9FdRB19E267buYiL1KKZYxSfMg0x7QvH PgtjR0BSow0XYQGmG5dA5jTNe/efoq0x4xVOBm8vC2jUTCcSrneLvQjrt0hUQiZ7sc2i BD8O1rCzrfPtl4nA4UYH/7wAr1+eua1xG8/uOTzHTlv5XDCKZ/jx4ob3u9/WsxMr0rQk MQ1/PlbmaLpr3sMdh6hRHBboMJh/ASqZO3IVSCWYEYhs9KwXQPv5gd1NPZ8744eQv06Q Z3Sg== X-Gm-Message-State: ABy/qLYOP626dwRKRTPh+ec8IaKJPaeVw9SULIfkE2CHEfwoFJVPgpgs UrZxiSWVfW+YFZEGAgw+kp6jnf3yiFWItFpFd/3C+w== X-Received: by 2002:a7b:cd8c:0:b0:3fa:991c:2af9 with SMTP id y12-20020a7bcd8c000000b003fa991c2af9mr4826847wmj.16.1688762467409; Fri, 07 Jul 2023 13:41:07 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, Warner Losh , Kyle Evans Subject: [PATCH v2 15/24] bsd-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 7 Jul 2023 21:40:45 +0100 Message-Id: <20230707204054.8792-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.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 --- 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; } /*