From patchwork Fri Jul 7 20:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700062 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066651wrs; Fri, 7 Jul 2023 13:45:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2bzAJsG4Hp/MXqJdXef323WJEcLFGPZHy7IPA8SSkEK9fNTB0N5VNU79Me1w7cC90qNh5 X-Received: by 2002:ac8:5e51:0:b0:403:2e12:69ad with SMTP id i17-20020ac85e51000000b004032e1269admr8631629qtx.11.1688762755218; Fri, 07 Jul 2023 13:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762755; cv=none; d=google.com; s=arc-20160816; b=LT/rNWVtyNOtmg5S85PlFCjhxYWGao7Ny4Y2YkWNoeB9ucUcYCU+tcmq14NQx/gZ3k KWvQFvI5zS4U1Ze5OmKp98V4x2N2dByx7V8hRD/4Ed1SC0qiSq/PYcXptpcRHwWOQh09 Czlo2e+FkhNz08HnaSC5uMK/Bo4n0TMCz/cZfUdAngcU5Er6ETKH1/Mo+qlZ4xeIUD8h ryVWEDZgEs6cS0SRc/X6+7y9cyaSrPobLJul5HtSA1c7jdO+woR70H65F0wj2HoM6QGV YnCyWjVRFaPhIYpni79heWnjG07avOHuh4hClLcVA0XoPndYebnywoMWMfngVxym14YH oyqg== 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=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=tTb19nOvePXFsWkuOxllCqz8txsMctGsB2ZgW2iQMpBW/SneILxDZnQ8VFx6uVCplJ ZzUrIo0qX2ympR/6sLmfLgB5Cyaw+bsqVEslDsIGfbkZZZKdG1dFwNFkUNdDpoM5BMyM qSPTnT9ZpzNt5widHrXmxxeU4id6y8zUWnb2lWV9ixL+eA4sthUOgEYmHEFXcWGIYpf8 XtbfYlvs/ryhYAyXS1fSvJec5lRrE8+P/+9ATUM+rfTARjA5k8kgkfrvFY0fNNwvS82t 7jXkzNnOuHQsUu3NQZCyIvIeLrf+hizo+R5FPbxeI233imP0IwuHhqsGlnZ+y0o5LsmB T5LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sVuOsFi4; 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 c21-20020ac87dd5000000b004035964d820si3234142qte.311.2023.07.07.13.45.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:45:55 -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=sVuOsFi4; 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 1qHsGP-0004qB-MB; Fri, 07 Jul 2023 16:41:13 -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-0004oj-Sc for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGL-0004mi-5a for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso25265845e9.2 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=1688762468; x=1691354468; 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=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; b=sVuOsFi4B0MTOTW82lsGjgcUiO0FfrFjm9YLeoJ2bqc5UFqIBl8bOZyTdByuZjnAaT j4AlrXkMkkji2OyW+MLNiLyTYjA5O+amD3OvQw3pIlomFBj0rALDdhYUufQidE9LYMKv ri+pcb7JVHCFOaB33j7uoq05rnXjwDqdCvZbhdxqvYdCWxrfql5fuSma1iSxM2enoQIe IfR3Wrz/f2SsGJ5TDNlNvgic94Ekz8TKu3Q2Nlfm1bu3S/3QWtbgR+Hfuh22qaZkNrKZ QtdZdOvHruC2C3edPq5qNXX8fcgJmfRSVS7TABILOGNOOAwxZs590agkYZ7NSx7Lvxb5 fI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762468; x=1691354468; 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=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; b=CvrvBQ5QG49EnITLkCa715WDFEuC0glJTXSd6pyMtHtRjkWVT7iTHnBlMBNLfdYzjD XsnOeNmpqx4w6lYsRIoe1lhXWnyqXcjr0YCJ2XfTjXpZyrPVRKiLLi6pqNPQNcTYaLNc CXCDCQTR9wjRVXTWJ6qbR3BYUbGD3Bvm17IAOYptldsuwjYpmMiRCdYW1nj8TDHD6XDZ aA9yZftC38F5zbGK3+L103NlR0w4V1EQjqZDIfcmYyQMMADFmMMxXw/dv+m1BeGkkLmY 4kiQvyV3ndUtHIiUnC2wDf4FrlGfnx3j2mpdH/kCsSmfnZepjsa/PEVQO6HqPiN15X9b rDNg== X-Gm-Message-State: ABy/qLbSFmbahPeBjDnLFLNVznhw5g1zmeE329Xd6KQihe8ilD05ERq9 gyM+9LnQYyArQ1sX9bznAS4V6Oks3oU6u1lV6rYgvQ== X-Received: by 2002:a7b:cc86:0:b0:3f9:c8b2:dfbd with SMTP id p6-20020a7bcc86000000b003f9c8b2dfbdmr3576182wma.19.1688762467883; 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.07 (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 Subject: [PATCH v2 16/24] linux-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 7 Jul 2023 21:40:46 +0100 Message-Id: <20230707204054.8792-19-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::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 52 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index db4705e049..6ecdf9e56d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -317,55 +317,15 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong align) { - abi_ulong addr, end_addr, incr = qemu_host_page_size; - int prot; - bool looped = false; + target_ulong ret; - if (size > reserved_va) { - return (abi_ulong)-1; + ret = page_find_range_empty(start, reserved_va, size, align); + if (ret == -1 && start > mmap_min_addr) { + /* Restart at the beginning of the address space. */ + ret = page_find_range_empty(mmap_min_addr, start - 1, size, align); } - /* Note that start and size have already been aligned by mmap_find_vma. */ - - end_addr = start + size; - /* - * Start at the top of the address space, ignoring the last page. - * If reserved_va == UINT32_MAX, then end_addr wraps to 0, - * throwing the rest of the calculations off. - * TODO: rewrite using last_addr instead. - * TODO: use the interval tree instead of probing every page. - */ - if (start > reserved_va - size) { - end_addr = ((reserved_va - size) & -align) + size; - looped = true; - } - - /* Search downward from END_ADDR, checking to see if a page is in use. */ - addr = end_addr; - while (1) { - addr -= incr; - if (addr > end_addr) { - if (looped) { - /* Failure. The entire address space has been searched. */ - return (abi_ulong)-1; - } - /* Re-start at the top of the address space (see above). */ - addr = end_addr = ((reserved_va - size) & -align) + size; - looped = true; - } else { - prot = page_get_flags(addr); - if (prot) { - /* Page in use. Restart below this page. */ - addr = end_addr = ((addr - size) & -align) + size; - } else if (addr && addr + size == end_addr) { - /* Success! All pages between ADDR and END_ADDR are free. */ - if (start == mmap_next_start) { - mmap_next_start = addr; - } - return addr; - } - } - } + return ret; } /*