From patchwork Fri Jun 30 13:21:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697946 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp451557wrs; Fri, 30 Jun 2023 06:25:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sMvvhG3F6LqaiofNklPknkwkM5Pd1IgIuhOgt/hLE+bVEDiLlB5Wkdme7w3/UTy0nzGnA X-Received: by 2002:a05:622a:11c5:b0:400:8613:5378 with SMTP id n5-20020a05622a11c500b0040086135378mr3575274qtk.20.1688131558291; Fri, 30 Jun 2023 06:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131558; cv=none; d=google.com; s=arc-20160816; b=RANzKiNBt7kBb0YeisYB3vVpkzORwVeRKfwFF8fJpzgIUrI3XpJNzntr6cyoVU6SyB GKqXMc1i7EV+wpvqaZ7Nq8iDNzkllqyjIy53i+bmHcO0st9OC0rGyj+plOWhenE0gxQB U81n1Vk0ciOFQxnwSn3w5g370+drYMIgtw/5Cx7ihvaIlZdRn1wOhCMfCgDreO/R+1Xc fU4UVMxv2Jn3C8nW2gixpzxbGpjZFrkBKV859GSDGvG9BPjKYAY4Ls37x6cwN4uk+Ed6 /VVAdToFEde7yyot8fhcQIzDOPmOyiEJBvPWWKSTFUQV5pmrtHH4GjYN+/fCIUU0Xlsq EcbQ== 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; fh=l4eJLtUn0SmHiKt99PWqHuWj2v8zKyPa4Rk+HEUnuU8=; b=J3rzP11gUvA8RAGOztcW1H4twUmBEGA+UpNZxQlhGtuIB0FPuZD1sqdCJ0zfnZM56Y +xHN1xV1CsB7DsqnOrgJYoDlXZMeWHZuMwJvnCBIsc3l8Ngad1QSpZ6clDnAj+BpeuW6 js6h7RYcU8oGWrTPVBPCcM2cmTiRc+bWYqS2XxqS8BN4kUZrUdlwli8tFqr6lOUplU3F 3m3gpNFtMX+ISjOyDjh04WuumVrBmw3abvloRTWVLi2YdOTgacwn0j7S2J2905YzLBKq 8AG1yyZ9x5pxjrcvPEztPSfCTg/ZhqA8waqgjV+ZUJPF7U/4aZlbR5bfWsu8CYVFb5lt wBfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itKu4EMV; 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 b22-20020ac87fd6000000b003f72e877e5esi443670qtk.104.2023.06.30.06.25.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:25:58 -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=itKu4EMV; 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 1qFE4n-0007iy-Cc; Fri, 30 Jun 2023 09:22:17 -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 1qFE4l-0007hP-Qm for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:15 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4k-0003RO-4F for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:15 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso105346f8f.0 for ; Fri, 30 Jun 2023 06:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131332; x=1690723332; 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; b=itKu4EMVKahoT+E93KzdauxK55wwu4oLz0zFvoMNn5+ep63LvPey39LtQIxBikZf13 xs4VooEnBkqKSW00hceAEbyiHlonw6HRZ+cD2BSoUm5iAl2tlYTuRul9dDSReGd65irD 7fgbLiE+HQzA4dSJnPe1KYJgeQ2ymVbOXbVmPw30j4UtD78CdctsmYiVH0bbo1C9tHYk ggjq5PQrnTJuAi7S0ypeyMb1hltDSrju0LtAkLbnF8brljgONK5fo9rZvJQ8E+NBfntV 4miijhkM7vPqHZkw5jY9I0upLe6Rewr6bV4cNvY//KDfaDVyDLj4igOfOK7tWuHmGlyP cq9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131332; x=1690723332; 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; b=Cwj2D0ajAvpuvTaL14Ms4JA5PKVzhyBft+w3CtTiEC3RUk5euCzkERnp0WxgLNsuwd VvYiN4xXsIyF365FKNslr97pHhUuAf4qkJ+iRhUSRwfC0rfE9hZyJysPUSJsg+aA1enW J54fEJ7m9c2cBFoA259Eg6TTPrpMzvOwgoZaecPwB+4Afbs6O9FQvdjd8MdlRsJLFtEJ 39gECUH0AmHcXRFd0sPbdoVh3ORr0ysKJB+g1m05u0ZJNzppSgSYD9pwCyt26v0eDpky uzDz4Gx7tS/856/+f+ZICcwiUMbzw2qudlxZ6aBIYyWxqbfGqRAA8Jl7wId/ZoXaz/MX Dmow== X-Gm-Message-State: ABy/qLZOsJWMKKB6zknmgcj2fTBdlXtjwAzFZxqoxvNprJXvW3kCMdXV O3pi1lMsm2zxJxjoh1RNJkrS9JPhwJcOR+Avg6qvpA== X-Received: by 2002:adf:f20d:0:b0:313:e80b:2273 with SMTP id p13-20020adff20d000000b00313e80b2273mr2005791wro.46.1688131332583; Fri, 30 Jun 2023 06:22:12 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu, Warner Losh , Kyle Evans Subject: [PATCH 15/24] bsd-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 30 Jun 2023 15:21:50 +0200 Message-Id: <20230630132159.376995-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 | 47 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 07b5b8055e..0d06bd457d 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -222,50 +222,15 @@ 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, align); + 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, align); } - 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; } /*