From patchwork Sun Apr 14 00:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7665FC4345F for ; Sun, 14 Apr 2024 00:46:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA91A6B007B; Sat, 13 Apr 2024 20:46:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A32696B0082; Sat, 13 Apr 2024 20:46:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FA2A6B0083; Sat, 13 Apr 2024 20:46:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6938F6B007B for ; Sat, 13 Apr 2024 20:46:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C12BD801CB for ; Sun, 14 Apr 2024 00:46:02 +0000 (UTC) X-FDA: 82006295364.20.65551E8 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf22.hostedemail.com (Postfix) with ESMTP id 2DBE0C0006 for ; Sun, 14 Apr 2024 00:46:00 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="BPcxq4/6"; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055561; a=rsa-sha256; cv=none; b=5oWBiwzadK6/gO+pLSc8ZzuBfUheXGJtCowYYxqw8yB5zx+9UttY9zkJVGVBDzHTHwVv4T hrgPhYOP1SrCQAy/tojE54etLJPLrMG6m0w3bUGPRcIWle8iCkpGYvcZHuSTQ8gSWWdf8W IovdIrfPQhctoSPX6WpZe9GlOStpC6A= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="BPcxq4/6"; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055561; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=z/lzrBdBq7d/KGMB51apJ9EvGc0eMJ+chjRrOdSDWt4=; b=CUHZrxUVlVTlAJwU4jhsNPZuAq/tMMxHj2mfM3v/NuJikZhZQ9DYp7jSC64t2L2a9nqtUB Q6x5s6XKssWGB5SEKK3d7IV8EvZ9MLmxqZbAzk0QwYHrwiXPFNxt3ME18VFMNF+QiWheZF UIMty69hcOu0+7cJw+ia0Csu9ikHGug= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a51b008b3aeso245275566b.3 for ; Sat, 13 Apr 2024 17:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055559; x=1713660359; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/lzrBdBq7d/KGMB51apJ9EvGc0eMJ+chjRrOdSDWt4=; b=BPcxq4/6anMoFlQMvKm+TaQzNIPnzOwBiTsaIqfvTddxaKzl9MU8xwZBef96LIw4rk 25goNMj6NTbFVkhqyFf3rREpErLhoTTQfxCye/1al5NMRpq8OboXTKi6kfgbdHQG4Q4y DNkOrXy6CDJSH8MaZOxwmPNHmXB3+UxElV0dTlUQwjXSk6J+7ELzuB1g2xYGUCJj1/3o 42NVtwTp2YItudat8zNMsgGuGGQXPHYN6Qkp8g1lQttVOLt3CZbdRGPkvYZbXPLK8pmf wOo7fJuJc1e9P0E7x7CQ9XqJ+TH9Dl+WVSJ4PWzyrkUatFecuhTTEhsiZdO8LGTDXX4m NydQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055559; x=1713660359; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z/lzrBdBq7d/KGMB51apJ9EvGc0eMJ+chjRrOdSDWt4=; b=YTg5I6lNkXmB9inUozzWh2pvOTjxdB8hOGESMv3c1oMsNIvTnA47PkaQOjxGtT7fqK dZi1cp5wLhWVJ/B8Jba1eXCsd0D18sspV9D7uPpmZoiinosK26SoFNSNWAy0hNc50rhp KVlKiCjfCuuCj5C+U6I9/xThBvbF31R+jxwkb/WV/IT4kyzEyW7ZWHenpxOU9yBVCuJb BOUoAOvGuuX9wbIBV42vd5tc8WrSy58w9ffAWZkHs+HIYoDALS0x1QO9J+0VedCu27Qv hWWbbBupZcsGTdLeLfD6JNWev9xKJJ/HyTy1bmxp4lNB1MbGq10x0g15KpGF1rnFa08C oEIw== X-Gm-Message-State: AOJu0Ywxaic/+ZgrUR2hufLC8p70NDvlctkklD2TKx/UpLWdoXWE7tBF yiwK6RWBT6UknC7lRhr2+Iw9H+C6aO4GcxqtzSYccTcQC1JySiSE X-Google-Smtp-Source: AGHT+IF+05A4jUJAv+Nc2l2jEKu9CswGqCbxMaxeeF88lVc/hyKc2NgpE1T1kGYYAhg9MRfs/D3IlQ== X-Received: by 2002:a17:906:dc8f:b0:a51:af7d:4652 with SMTP id cs15-20020a170906dc8f00b00a51af7d4652mr6073214ejc.32.1713055559238; Sat, 13 Apr 2024 17:45:59 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id k11-20020a1709067acb00b00a524b33fd9asm1354337ejo.68.2024.04.13.17.45.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:45:58 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , Jinyu Tang , Peng Zhang Subject: [PATCH 1/6] mm/memblock: reduce the two round insertion of memblock_add_range() Date: Sun, 14 Apr 2024 00:45:26 +0000 Message-Id: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2DBE0C0006 X-Stat-Signature: 561zfso9ttieoqihcxsanwcntoekpetd X-Rspam-User: X-HE-Tag: 1713055560-959414 X-HE-Meta: U2FsdGVkX1/7W0wLuTjK8CMqT47YpuYQKsU7G8aK52w3U+FJTDdCliC3P+NET2HJ0MY58uvxiUw7vXtLdFuGSPEInfWWnDb/lft3Y992RMUqogZjL6G0dSyushhhLHSbQjf0cMiLIMeVzsDm9QaRQlSVgdPogQcsFzKIWcL2o3I5Av97E8eo8D3zHOOqQuS+xzcK8Zz0KS+Ex1x7axfUWyTv0Csh6AqpWzYsbreYUVPvqvodl1lUrJMdwFVRpx46R8/M/JT9sUHUykGkNycSG6vqtu8EPlANbANWK6BT1SRZeU8UAnaXokp/f3eYsp/UX+h1l8S4Ww4MsSAHIDDOnL7yrvBuRbZ/hypYer2mwXrVM9eOdfXqp0L6uWS+YUa6UqSnKYOcgQZbeR25uCPXTQVwFW76RNigrgg7X3NOWSMRhHmm1ynTV3U7GpKyEtWpvdbuTjaOwdbIJr5L96Rlv+zFpKhu8L8JHl7pjVsvfPZOB6lcvVTwOCc5/Pbm14oH6ahUU4MxkjcssEezQdklJ3IZIU+iEwoQmqtxULMhE0nSt9wp/JdHhBKsdyOY9JVbmMi4PaO5Gy4KdurDi3G+AcPmNTW3wWZ6DFgNaQRrODdXUQcq249yufHByEArPH7qwnFuoawKxlP+pVsN4r3M9++nW7FYtx0qhh8S8cNt/1BuJEr9AMPmOjirNovkY4hLXarPaTW5Exm0wf1y3YxZ6ZQvV1hT12Z7LiZK+V7njEOTsAM8keP05uDAo9nivS1qsIIChnytCy7/SRbxnwcb1uW1/pL3Sabikwy8lf2nDVcR/ccx2j3IQbs+fduHfxIAlhwHyVsjr7jJmAtUkRL/IR+eP64tEN1kX+rnBAf7+aSvSebQfihSHToi04Fjl5JzNZ9T0v2C2TIQ4G1sj96gtM+gO6e3H/jaHQP9yw7tcbRUx8cdDQ5GSfFdD+v8ZnAnFIPwnjR7fay49JbzRuI AHK57tCA mGTysesE0eO0iiEyt3gqChJmLUMKXDVVoGalneUeQOzab32URRynmaUn5W6N65ej7/2jJhoSFYoFg/9rgDNk4o51evI4TP8xEDPIZF01AFDbqk7DtzhljR7jRyZxKMzK0Y8Q57KAuTX27vDEbXYUpxOYi7fFHUyab4tQuci7i8HPntRmWFPFF6Woo73rfNKbJkPc+LGcxyJ14Z/m68ZcfduLUVs1YDryL2NT0U7CnWBoUBlhXG6O4fUmUvqFWxszLVLNf1VbyAvUD9bWU5Yeeh0pGnSkK6Cte2YjWfrlgfdkdUtjzTU2hC6u5c3D+zKGXBf129xcRWosKiVIHsgXelmKCVeYbivjPjqA5FwWuGHLKE660WArsLgILa05JHBczOTqGWC5Vs9J0QtTOU9uAdbN60OxMsaiea/FbG+TTqqUD5pUITV0dghxHXDZZVV3iO6mTq5Au5OCQS0PwlTksHc+J18uWCsza0BlWjqXxlfAbebE/2EzIWYAYr3l7JzXQKElMaXIn5mHTxT7z9xrxnELiU+yqNtLsN+QVDY58v1bSrrbuaervqhczGQPRpLiG/xa4MwiR+mv8OG1iowCi2p67fmXNQmY7o/yWwux50N/1fC7f9nTttbMBnclWeugYxNZ7l5yjn1oUHz97l7qnQ8kHf5BojJkTh8daIEvYWgloqPluBeK4CSO6Fg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000070, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Current memblock_add_range() does the insertion with two round iteration. First round does the calculation of new region required, and second round does the actual insertion. Between them, if current max can't meet new region requirement, it is expanded. The worst case is: 1. cnt == max 2. new range overlaps all existing region This means the final cnt should be (2 * max + 1). Since we always double the array size, this means we only need to double the array twice at the worst case, which is fairly rare. For other cases, only once array double is enough. Let's double the array immediately when there is no room for new region. This simplify the code a little. Signed-off-by: Wei Yang CC: Jinyu Tang CC: Peng Zhang --- mm/memblock.c | 74 +++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 98d25689cf10..b46109300927 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -585,10 +585,9 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size, int nid, enum memblock_flags flags) { - bool insert = false; phys_addr_t obase = base; phys_addr_t end = base + memblock_cap_size(base, &size); - int idx, nr_new, start_rgn = -1, end_rgn; + int idx, start_rgn = -1, end_rgn; struct memblock_region *rgn; if (!size) @@ -606,25 +605,6 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, return 0; } - /* - * The worst case is when new range overlaps all existing regions, - * then we'll need type->cnt + 1 empty regions in @type. So if - * type->cnt * 2 + 1 is less than or equal to type->max, we know - * that there is enough empty regions in @type, and we can insert - * regions directly. - */ - if (type->cnt * 2 + 1 <= type->max) - insert = true; - -repeat: - /* - * The following is executed twice. Once with %false @insert and - * then with %true. The first counts the number of regions needed - * to accommodate the new area. The second actually inserts them. - */ - base = obase; - nr_new = 0; - for_each_memblock_type(idx, type, rgn) { phys_addr_t rbase = rgn->base; phys_addr_t rend = rbase + rgn->size; @@ -642,15 +622,17 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, WARN_ON(nid != memblock_get_region_node(rgn)); #endif WARN_ON(flags != rgn->flags); - nr_new++; - if (insert) { - if (start_rgn == -1) - start_rgn = idx; - end_rgn = idx + 1; - memblock_insert_region(type, idx++, base, - rbase - base, nid, - flags); + if (type->cnt >= type->max) { + if (memblock_double_array(type, obase, size) < 0) + return -ENOMEM; } + + if (start_rgn == -1) + start_rgn = idx; + end_rgn = idx + 1; + memblock_insert_region(type, idx++, base, + rbase - base, nid, + flags); } /* area below @rend is dealt with, forget about it */ base = min(rend, end); @@ -658,33 +640,21 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, /* insert the remaining portion */ if (base < end) { - nr_new++; - if (insert) { - if (start_rgn == -1) - start_rgn = idx; - end_rgn = idx + 1; - memblock_insert_region(type, idx, base, end - base, - nid, flags); + if (type->cnt >= type->max) { + if (memblock_double_array(type, obase, size) < 0) + return -ENOMEM; } - } - if (!nr_new) - return 0; + if (start_rgn == -1) + start_rgn = idx; + end_rgn = idx + 1; + memblock_insert_region(type, idx, base, end - base, + nid, flags); + } - /* - * If this was the first round, resize array and repeat for actual - * insertions; otherwise, merge and return. - */ - if (!insert) { - while (type->cnt + nr_new > type->max) - if (memblock_double_array(type, obase, size) < 0) - return -ENOMEM; - insert = true; - goto repeat; - } else { + if (start_rgn != -1) memblock_merge_regions(type, start_rgn, end_rgn); - return 0; - } + return 0; } /** From patchwork Sun Apr 14 00:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D996DC04FF6 for ; Sun, 14 Apr 2024 00:46:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7FB16B0082; Sat, 13 Apr 2024 20:46:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB9456B0083; Sat, 13 Apr 2024 20:46:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 998AD6B0085; Sat, 13 Apr 2024 20:46:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7BF8E6B0082 for ; Sat, 13 Apr 2024 20:46:04 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 401DF1C146F for ; Sun, 14 Apr 2024 00:46:04 +0000 (UTC) X-FDA: 82006295448.04.B28B5DF Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf27.hostedemail.com (Postfix) with ESMTP id 867F740005 for ; Sun, 14 Apr 2024 00:46:02 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YvqREDLo; spf=pass (imf27.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055562; a=rsa-sha256; cv=none; b=e+9kHIHPY/mVtmzk0hZZV5Dm/GZuqkbvKmECb5mBi21eRZsq6ZqjtiBkNvzohDJFVOdsCb NvJbQQSroCgtn5hip/pJVWW+p/RcxFcSsbMcSXjlwQEdfyd4APfYx7255r9tLSouZ/VbiT 9naMu/Igp6vmMTF0mSPtl28XhGF3tNU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YvqREDLo; spf=pass (imf27.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055562; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=qbLK5tRBmVc7HZgLA7VYsCQJdYnn3sm/iYsb9sV1GKc=; b=0Nhj4prYf+n35X4w7d6Xe1wRXjARH9wOdPXaNtlOtHruq+IaV5Ro9/9UxmA75GKnPOD5Mf s+sX00a+ei5Ln4/ozLfyJX4q40LhNTjz/MU4nhIbmMtY7FrCehbXzeHc/ibwQVgaXJ0+0v 9jGIMtzmuSsBJX9gc2UdbfiuMJLKQ/M= Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56bdf81706aso2427402a12.2 for ; Sat, 13 Apr 2024 17:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055561; x=1713660361; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=qbLK5tRBmVc7HZgLA7VYsCQJdYnn3sm/iYsb9sV1GKc=; b=YvqREDLo7MgMeuQM+/k+0X6PhrJSv6X/npkWQ9bDfMZjEfPf1WTAY79hegu3o0Hynx ACPume9aTDbxjZHwu6NmupIZCeLi0fQbCh08G3UkMQDjM4Om1ZSkSyDimsxiHDadUfUQ 0yaJ+tAvypbqQtrrOpCnJlxHWjQTyQDDYwAUQlU2cJiQyEn/K6Ru7Hl7udKUBseYMGME OErEN3WEj2+gwvyktNG6kLbVS3FyQWPQHYCgV2e43D+JXc7ACfqmwWFSYcnqAHKkvtYr sCn/0iin3MGgqdnSPQxNdIiqc8bz3Lsa2RfHy5iLH/FoclFWdecWSLpzwRhgFPkLx7hh RCDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055561; x=1713660361; h=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=qbLK5tRBmVc7HZgLA7VYsCQJdYnn3sm/iYsb9sV1GKc=; b=YOpMn8zrYz3bVUo4Suz5bF8JyULahjeJ6VyrMuqoUOpTiSohuH1NXsQGsKX7qCGJhE dDIBuUuiMiyQqb74Fu08e4RJVh++iL3DxC0947gDd4BYOKqSHuyCVHdghLALLvvm6FCg qcOqe5am5QL+pAZn0Ls6S6IQvYzPQuT1GE609T8u0o3IRoITshjYFYlUIMirkCVl2j0O ljmDUOYwu1MvFvhRZQwWlgVvYvGOJ3kmTamw0hODoLG9rPJI/kNs3lxANN4kramAWIWy 7m4K5pkH1UZQVIiDSkAXDWYVmKxq652d8CjxihSb//cSnnwgIabeWCP8JiBeplMzdNVI rT3A== X-Gm-Message-State: AOJu0YzOxoz+OU1qGInl6hi0qmd34dw1Has4J1nKfzf1q/RFy3Lp9bTW 56FFNjB9fEX7R5NmTZieWAwkIhMaqYIMMN9Ah4SxAaYzMDKaNjKt X-Google-Smtp-Source: AGHT+IEM85jnH1CrTVcYg68pELXlwPMcLdXbTXTVCpBEjjKv+5piCl0LGL4xz9kyg67sUscnmkvWxg== X-Received: by 2002:a50:d604:0:b0:56e:2cfc:1d3d with SMTP id x4-20020a50d604000000b0056e2cfc1d3dmr3759817edi.16.1713055560718; Sat, 13 Apr 2024 17:46:00 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id h6-20020a0564020e0600b0056fed5286b5sm2761067edh.55.2024.04.13.17.45.59 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:45:59 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 2/6] memblock tests: add the 129th memory block at all possible position Date: Sun, 14 Apr 2024 00:45:27 +0000 Message-Id: <20240414004531.6601-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 867F740005 X-Stat-Signature: r8ua7uifgdjusu4wge1gxijy4jtuzjz1 X-Rspam-User: X-HE-Tag: 1713055562-371134 X-HE-Meta: U2FsdGVkX1/BTkMps/Dsit5NyZK9AlX56zToxpnOpXX2EjRF8OhEQDeLY2Wpva9vO6KvjkmwIhU+WRlm1jPPMPnyYmdoWglPk6WchcNEH4oJidK80u8n+hWhbgG1jp3LvROvKLi1NQmkSzEwU7VpiymRWDRV2Yt4AlpY7qliTitVrWlt9NxDpAfJYKXWxniM3BD7P2JM+BD1yAQ7uYG9H0k6rlO6S5iSRhHQcon7qISyJZ039U9nt9iDL+WVK51gVT1DeJdZqyKimKrw4qOB+IGbIj7Q/Wz9/i8Tq/WZfcQ6XxEUFXMOckfXY9KxTfeP225fa4Hxf/cgCi5N1+jApUwLBZz5CtACJ5pHUZVypgpbz8VCTb7WBA8SnX9aG4ZHKs45EWBH3ruVQ6T9f+WpDa4ynxrs90NNI5cH4gkV/w26JJeHGFFf9qgQOHyAxv1piRqTG3Cdp0U2SM75zcnEXpUvawpnW/KanX4fGbTxjcVWEFTGhAE6dDqDthzugbbF9Hm1hIzCiP1cWVBNNOJEqWCX5JdAuESGajtNQZ+28A53kNsqyGmynr+Yh8+wvb2CylfPPm5uHiRUT3PXY97Vo/IsQJLScYtYXntCeW/aCaBmEPD3sT0hIlOcJZiB+UbPxkOgLGd02Kd6vqNtCLnjrUvRm0aEiSc1mlmVAEz3gg9y63FbFLPn6SBenkezE1bOpC0hUtnJs/cirI6bYFPKvaV1zFHweRVdX/4OHbajna3GdR/I622eEZXTVUzyFyL9sKe5eKnnJOt498hEuj5zEF8yhoPZlOY5Ijh06ApsudyFIrzpG9AdP/TnPHzv6Oc3FYUnaiY36xGe4lyHvZJYyhWmRKN92UuWjev/IngnyI2Kfsdmgc2JHowKlGSPzBYWutBOZ0zq7dBHsYtgFPlp8onns2HfrqVXT3MT7bAYm7xQMf5JdBiRmJpZ8HlWZJDooe41+ocNKINVIAe58aC 55HrG9Wl eYjqThWCSoC+d6co3i4UEG7O2BnDXcrGY1k/OdJB3njuxZ4HzDcDiTL4K+xz/6of3BuaC6jEA5GNf3tWr1qZXvKLCsBe1/exmvU5hbNVBOfITNFOTL4/p10dTTlGbDD2RyQ++sgjzUqjv/K3N5lBJXsBojohaxQiz3UdWJygcvyEdHapPQKM9uW74RN7hdkWTNH75jW8VtHlgELl51NSKVCVGPRI5TjqKHyG9gEci65IRopUx2+8VkNw3uBgDnmgIxpq8ibZ0cXHk6IMmVjIcglXZ1XIisseCGG+i0puRq4jgf89SjXA8pguza/CdRKnY3iqAfdrhUgEejHoKguYZTg9L6ftgPqUuJMB7oJRi5M2dUj/vC4+WGN2Uz5Xnz78OOCx96LYq9iK9T5qwMBaxn9J0HG7mQzt08zWq+shuuxHRQlVnwyc4182G5yvRwKRpkbfqCn2Qj2i+sfpWk7iazuz8Y2gIEHPjgqN/8k7RU/vbpU5zOpIVdaJkNdYf0REy1idh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000047, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: After previous change, we may double the array based on the position of the new range. Let's make sure the 129th memory block would double the size correctly at all possible position. Signed-off-by: Wei Yang --- tools/testing/memblock/tests/basic_api.c | 132 +++++++++++++---------- 1 file changed, 73 insertions(+), 59 deletions(-) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index f317fe691fc4..f1569ebb9872 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -431,84 +431,98 @@ static int memblock_add_near_max_check(void) */ static int memblock_add_many_check(void) { - int i; + int i, skip; void *orig_region; struct region r = { .base = SZ_16K, .size = SZ_16K, }; phys_addr_t new_memory_regions_size; - phys_addr_t base, size = SZ_64; + phys_addr_t base, base_start, size = SZ_64; phys_addr_t gap_size = SZ_64; PREFIX_PUSH(); - reset_memblock_regions(); - memblock_allow_resize(); - - dummy_physical_memory_init(); - /* - * We allocated enough memory by using dummy_physical_memory_init(), and - * split it into small block. First we split a large enough memory block - * as the memory region which will be choosed by memblock_double_array(). - */ - base = PAGE_ALIGN(dummy_physical_memory_base()); - new_memory_regions_size = PAGE_ALIGN(INIT_MEMBLOCK_REGIONS * 2 * - sizeof(struct memblock_region)); - memblock_add(base, new_memory_regions_size); - - /* This is the base of small memory block. */ - base += new_memory_regions_size + gap_size; - - orig_region = memblock.memory.regions; + /* Add the 129th memory block for all possible positions*/ + for (skip = 0; skip < INIT_MEMBLOCK_REGIONS; skip++) { + reset_memblock_regions(); + memblock_allow_resize(); - for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) { + dummy_physical_memory_init(); /* - * Add these small block to fulfill the memblock. We keep a - * gap between the nearby memory to avoid being merged. + * We allocated enough memory by using dummy_physical_memory_init(), and + * split it into small block. First we split a large enough memory block + * as the memory region which will be choosed by memblock_double_array(). */ - memblock_add(base, size); - base += size + gap_size; - - ASSERT_EQ(memblock.memory.cnt, i + 2); + base = PAGE_ALIGN(dummy_physical_memory_base()); + new_memory_regions_size = PAGE_ALIGN(INIT_MEMBLOCK_REGIONS * 2 * + sizeof(struct memblock_region)); + memblock_add(base, new_memory_regions_size); + + /* This is the base of small memory block. */ + base_start = base += new_memory_regions_size + gap_size; + orig_region = memblock.memory.regions; + + for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++, base += size + gap_size) { + if (i == skip) + continue; + /* + * Add these small block to fulfill the memblock. We keep a + * gap between the nearby memory to avoid being merged. + */ + memblock_add(base, size); + + if (i < skip) { + ASSERT_EQ(memblock.memory.cnt, i + 2); + ASSERT_EQ(memblock.memory.total_size, + new_memory_regions_size + (i + 1) * size); + } else { + ASSERT_EQ(memblock.memory.cnt, i + 1); + ASSERT_EQ(memblock.memory.total_size, + new_memory_regions_size + i * size); + } + } + + /* Add the skipped one to trigger memblock_double_array() */ + memblock_add(base_start + skip * (size + gap_size), size); + ASSERT_EQ(memblock.memory.cnt, i + 1); ASSERT_EQ(memblock.memory.total_size, new_memory_regions_size + - (i + 1) * size); - } + i * size); + /* + * At there, memblock_double_array() has been succeed, check if it + * update the memory.max. + */ + ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); - /* - * At there, memblock_double_array() has been succeed, check if it - * update the memory.max. - */ - ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); + /* memblock_double_array() will reserve the memory it used. Check it. */ + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, new_memory_regions_size); - /* memblock_double_array() will reserve the memory it used. Check it. */ - ASSERT_EQ(memblock.reserved.cnt, 1); - ASSERT_EQ(memblock.reserved.total_size, new_memory_regions_size); - - /* - * Now memblock_double_array() works fine. Let's check after the - * double_array(), the memblock_add() still works as normal. - */ - memblock_add(r.base, r.size); - ASSERT_EQ(memblock.memory.regions[0].base, r.base); - ASSERT_EQ(memblock.memory.regions[0].size, r.size); + /* + * Now memblock_double_array() works fine. Let's check after the + * double_array(), the memblock_add() still works as normal. + */ + memblock_add(r.base, r.size); + ASSERT_EQ(memblock.memory.regions[0].base, r.base); + ASSERT_EQ(memblock.memory.regions[0].size, r.size); - ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2); - ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size + - new_memory_regions_size + - r.size); - ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); + ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2); + ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size + + new_memory_regions_size + + r.size); + ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); - dummy_physical_memory_cleanup(); + dummy_physical_memory_cleanup(); - /* - * The current memory.regions is occupying a range of memory that - * allocated from dummy_physical_memory_init(). After free the memory, - * we must not use it. So restore the origin memory region to make sure - * the tests can run as normal and not affected by the double array. - */ - memblock.memory.regions = orig_region; - memblock.memory.cnt = INIT_MEMBLOCK_REGIONS; + /* + * The current memory.regions is occupying a range of memory that + * allocated from dummy_physical_memory_init(). After free the memory, + * we must not use it. So restore the origin memory region to make sure + * the tests can run as normal and not affected by the double array. + */ + memblock.memory.regions = orig_region; + memblock.memory.cnt = INIT_MEMBLOCK_REGIONS; + } test_pass_pop(); From patchwork Sun Apr 14 00:45:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 283A0C4345F for ; Sun, 14 Apr 2024 00:46:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30B546B0085; Sat, 13 Apr 2024 20:46:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 293EF6B0088; Sat, 13 Apr 2024 20:46:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEDC76B0087; Sat, 13 Apr 2024 20:46:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D190F6B0083 for ; Sat, 13 Apr 2024 20:46:05 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 73AC2C01DF for ; Sun, 14 Apr 2024 00:46:05 +0000 (UTC) X-FDA: 82006295490.14.EE41130 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf23.hostedemail.com (Postfix) with ESMTP id B0FF3140004 for ; Sun, 14 Apr 2024 00:46:03 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LmTxheSb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055563; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=jl1UMNnxlTwd3Yd2LNXESD1lrFK635rN9IkTCthCSr0=; b=D+LMbMqOKs+/q7IuN7qcPRDRb7YEhCdyqTktXhiyrUq5hocSMukBEuk8mixQ+kn2a0woyB uNXLtdTXB3P/oudcRlYaBkuCZsyvPqQqttgoAN9ryO5Fka5WuyVgMFMdYlRtE6XsYcCBbU Fs6AbkN5xI9ntYsdpcKIbsImULdZch4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LmTxheSb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055563; a=rsa-sha256; cv=none; b=ifxr/1OXSxWSdQwrdcPnuod8sLlnSD6GJUbattLLRixVg4jE6So7JjF8pYap8m70YH+fV0 Ofr6azDWtUZ35BB9RmgPvq6JOjZnfrZa9DAOar+30PVYixsg/HQn8uH4kYTAVp4pZ8NEYF 9pYGOTY98c9Xgc3Tf5ZVrxkpfcJtktQ= Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so2715385a12.3 for ; Sat, 13 Apr 2024 17:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055562; x=1713660362; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=jl1UMNnxlTwd3Yd2LNXESD1lrFK635rN9IkTCthCSr0=; b=LmTxheSblcuZZM320OFNmVtXIc4KrGQ8GtlnN+CpHdKOUgdA5jJQxbPqQKsPBpusaL mL/0lecEKJQYmWMjAc89u7Ub3+6kciWcfBIRSD89KnEF5BzSzkcEq+zDrld7u8DS1Ivo qYrxKKVyjfKLFDyW5NCrW1EklHqho2LmTqPVOAzw5CHmanyLHAJzbWrRlZa5fY3MB4bU i1IU3xGZ43Z016jJ6grDs7m/dvu4HbCxYWULAMgg7CaZIENDdwmF1rS/sre/81LFYSPN AnRwIYpjH2dq30t8HBiv98Wdfo1VDy9LY0/61Z5hA7eWAJGYnaNQ1v4Yo2HZrCJsmeso VQDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055562; x=1713660362; h=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=jl1UMNnxlTwd3Yd2LNXESD1lrFK635rN9IkTCthCSr0=; b=YHBo55/1HFL+c3r6mpmFDH9YroS3+vTQ7ckCclkeyNJ8QLMCWRl48ZrOdMVr2y4l6O LK83X71To9Dhy5uMFb9sw9K01bHIZMbiWox1zI8rl8N5Dan82bB8i3jjJvDJWplQ2phj RV/m72AdJFow9E2MCnutNrU6qSTwhQmQrgAwoXmP1u3jMKAAVYfyQ1ZR6CJYxmBlVBUM 8lWhKjI3jYc7N7Vv+v7E/lwJt6/LVN8GUTZepZ1IybF8S43Ly54Un8Oq4BPBYdyY/Rzo vR4ua89IufrzUTyVfVcAQDxgqdPNdECajpHDmyTbGa1LezSnWKkX6uTMBgVgI3/clFad LxfQ== X-Gm-Message-State: AOJu0Yyqw/o01r2Vixn0w6IevZei/1PfWmK0jzf/2sYsaaPTNwwuZclK 9ELTHD6X6KUMFzgssSuzdZjNis/7SWWZ+3K+r1P7+nbJkTt1ZLhV X-Google-Smtp-Source: AGHT+IF24Zm5BN66L/mKAGgZ6xUBukmBLF9RmhVoEl2YvMrM6U031gK8fCYhRQlhPkcPfPvHHqzzTQ== X-Received: by 2002:a50:cd9b:0:b0:56e:2a38:1fac with SMTP id p27-20020a50cd9b000000b0056e2a381facmr4128472edi.0.1713055562386; Sat, 13 Apr 2024 17:46:02 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id h6-20020a0564020e0600b0056fed5286b5sm2761084edh.55.2024.04.13.17.46.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:46:01 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 3/6] mm/memblock: fix comment for memblock_isolate_range() Date: Sun, 14 Apr 2024 00:45:28 +0000 Message-Id: <20240414004531.6601-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B0FF3140004 X-Stat-Signature: 8r1bk9fajp5h6hum6swaf7zhu18c585u X-Rspam-User: X-HE-Tag: 1713055563-855965 X-HE-Meta: U2FsdGVkX19ADRHzl8yXsqJLnM7b59nOBX18c8vC6pni/KzDpABqL//WDg523RDWU8P9+s5NXIVn/QybkHRWNJpdnaX1cYeapN582sh3VLDXmJFEESK8zrKRMw6DwAvheHAPff+ODtNGadaWMbQdnuM3q1v+HrsAjAh0DszwBOxztj5NSuo1HRzTg/v+RKPxDtsRli0awZMn2itvL8/wLXE/9cwTsp3RMVashJFsxq2y0a1Y0rXrNVbnrjMB0CxQSSWTIW/haDkTq/yjp6zrfStXuTF0r41mVCutmGkohGksL6Sl5JcNDyhIPcj15nJK8Dmg81tRgk5M+bA1xFffqkweB7x18kQ5k0gXyoEVvuttOMd90XnpDo1cwPxX9Oo/v6vDyLWDEGPayEBO39M4Vo1OVxbVGMHKhkWbWj4FlJlNtEBeSqrG7UFO47OEKPclbxHQowusT0QMM7DM6mNefHCKuebFU5HyaoG5c3f/F9B3zabrQ4Tr8wlK3JJrpS+BLSK/G85B8cBLKssIhlgW+bmbmSZYzfu7YL+3zECjj0Yw3Nq2KCptNJx8S0srNIpm31x82YMBvtC2/tYaz/uH23VBawRojHrqBYEogpuphlfmIvtEmJG2asXhgA3AQM46SUJbNbOHc24koecy/sNqisJ9LBnV/7lZr821QTPZ2BC14fATya/YJQFIk3qzyNV4WsQmCylLl8yZdMU8YdXa/9BtuDo3O8cp4lA9VM7XNJkGfQyqqujw2M8BepfTanxxdhGukJd9aKJ2GXI95zerNgOYHCmWBVi+GV5wYtYvBYc0cw8x7gW+SC0ZigGO/m3GiX+ZaEr8GTsrxtWQaWK1/he+Kk6XtWcXP/v+uAZD4PNkrH7yOSpjlmZvZ7Z6e6U+Qe1jXvB0H313UWXiTOcK1OZzumZcdhX/9CHA5R6uDDwX2xOPxC0ogT2nqVqwPWOIeBSq6NAkGVSa/f8oASM XfSrugWG sNLh/DFCh31DxjU3uj4ShVktx+aqQQwd/xCayoll9xI2HioNIO3pQMu4Gj23KineikFRIimTVQY6aCvNanofKNfJpyAUlIzVLDxpcWgmBUdlnXhm67blIhFRDlMQbw2q3LdXAJ6Tj3kCkV10pSX/mS4h24CSoWhB7l9Dg16RtcsDx+l9q60ZIaXOkdrl8l68cCqmT90SnegL2OXs5mOJZ2uAkqnXIaMbLFA/EpavHWLpbJgQu5N+axihGa+7DwED6MXUrRg/aWLxc9+iXNsPP6g2pni/L/whDYDRI2Mil1FF8t2Jm2fXf4fwX2LAClcqnIfCWnZRMp6pAXZo2wC7dgTxOzSb6ZP4ZgXXYgz0+6aoT6rwlKZUaMmLiAZwUB6K5OOSSeH1CZjMV09Dl7ttcl9IbCUDRswVtlTvWiMdlmEMNW0a8kGsGGrYL1VpStfISgFpRYOjUstt2tOY+eZWPBi1jfdWUOqUdEojPscBfUciw2dtpyJAHXN6sbOQ5qdGKREy8KgrsDSR45QVUkIfPYNRDepmB8En5mD5sYLpO3yw56bg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.012252, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The isolated range is [*@start_rgn, *@end_rgn - 1], while the comment says "the end region inside the range" is *@end_rgn. Let's correct it. Signed-off-by: Wei Yang --- mm/memblock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index b46109300927..2d7a2431803f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -742,12 +742,12 @@ bool __init_memblock memblock_validate_numa_coverage(unsigned long threshold_byt * @base: base of range to isolate * @size: size of range to isolate * @start_rgn: out parameter for the start of isolated region - * @end_rgn: out parameter for the end of isolated region + * @end_rgn: out parameter for the (end + 1) of isolated region * * Walk @type and ensure that regions don't cross the boundaries defined by * [@base, @base + @size). Crossing regions are split at the boundaries, * which may create at most two more regions. The index of the first - * region inside the range is returned in *@start_rgn and end in *@end_rgn. + * region inside the range is returned in *@start_rgn and (end + 1) in *@end_rgn. * * Return: * 0 on success, -errno on failure. From patchwork Sun Apr 14 00:45:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F85EC4345F for ; Sun, 14 Apr 2024 00:46:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5539D6B0087; Sat, 13 Apr 2024 20:46:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DD0A6B0088; Sat, 13 Apr 2024 20:46:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 330CB6B0089; Sat, 13 Apr 2024 20:46:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0CE846B0087 for ; Sat, 13 Apr 2024 20:46:07 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CBCAA14018E for ; Sun, 14 Apr 2024 00:46:06 +0000 (UTC) X-FDA: 82006295532.01.9C9DDF8 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf22.hostedemail.com (Postfix) with ESMTP id 48C4BC0005 for ; Sun, 14 Apr 2024 00:46:05 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bsx9sPix; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055565; a=rsa-sha256; cv=none; b=RuakuS0HFQO2V1190yaXLn8zJlOFUmPHgksV+dbmp+tdGujpW6vhgKwXPuHMC5vYAQjCYc Q8tSCQLfhICEiR+qIb/l/pMAd0J5dPXl/Riyda9aOsQaZvsKn/6gNv+wsAMvhxYc4qaqEH C3amOxucOOjMpJAsFNBv8NYStmEmkMI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bsx9sPix; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055565; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=pRb9y/cBVybmrEOvVi4M9YJvj2x4RiKjUdIpdofN424=; b=eYDVRHYyxGtq5eBNSLkBD5Okv+SP1UI9NYjbNg2M2xqeUpTwYUouRz5qhQ3oHmb+BQkmpy S57ghXmzvF7JuNPe3UJBmQlY/qAHB1OjvYUGooDMIVAJTOPwRJmBsSeMDEiWUg6xiS9cLd xKIbiO+Tdml8KnJzudiSNCGTBdnHMlg= Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a52592a0b0fso27043866b.1 for ; Sat, 13 Apr 2024 17:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055564; x=1713660364; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=pRb9y/cBVybmrEOvVi4M9YJvj2x4RiKjUdIpdofN424=; b=bsx9sPixZPF2VZEBlB0FEtJf21WZJGxGVZaGHAsLMZU1aqM9FO5bHoIIiRAqzS9nGe 7OlEyRlrjB3xRFunH81f+oWolPnrWfUGYIK5Dqo2stHhnOqwOjgYOZLAH65VXM+pH+Fy 7mk9F5qrFPIEHPs5rKPU4Ju/hwUhPJSJOfBY0WODuRJj8WKelGJRo+jDHCd0UJWGQ0kd AmGvBxLb/dhhZmQbBaGydc+htRAMcCBkErPM3BBCyzaqPuBxRQcnV7YbPPYMzG8YJypo ncTbmzuaF+mhvaquMBBpNX1rfUDcY+IuGUl15Eduagytd1jBoMFdyTSN4P5bL1v9oDbT uuHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055564; x=1713660364; h=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=pRb9y/cBVybmrEOvVi4M9YJvj2x4RiKjUdIpdofN424=; b=uHnpsr+g91MXCrSuYGH8niZ2d2LZVcdDwsnQyTguThmaMhm3IPzip7RRdXktQiW9M4 V91vzCCIg6EFUWjMzZYE7GtwuZlRO8gnju+dSL5Yl9OjTVEMZfWZLSP89tYjlQLwmdeu dGo1Yx39itp+nXZcfAsxZciu7QcHPtGVtqo8196m8MYnEHdk3gHZ1fpz0xiFgNBT3x9H kikq9IvlYh/3NB6wC09ltTfp0QaZaTkwMEOo8YC4ONSBvzawWUwnHu6BkmibFpTSXu4q swKaKAflTSVSWdSQlVvG2gGf5hAV36CFat9a0xfOvSiVvDdz6K8PMdJRXfvnveKRrKrj bGdA== X-Gm-Message-State: AOJu0YzGRUyUZwvLfs0sXMXHmtOX0Utr/bRbCcK7cuSNvlDD1DCXDNw8 cI44+Cv8BcwDzllSIQx/gLREmFvkaY8wMt0yi2W5fzWsWBl/3Mmp X-Google-Smtp-Source: AGHT+IFv0/R2LbrO0/cMbqJRXA6QvpIZCVcs/u2R1TM45rb9yx6IR647453b3o8ViyRJ/dkDdKMQoQ== X-Received: by 2002:a17:906:e06:b0:a52:53fc:b487 with SMTP id l6-20020a1709060e0600b00a5253fcb487mr893138eji.35.1713055563516; Sat, 13 Apr 2024 17:46:03 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 27-20020a170906319b00b00a4739efd7cesm3583376ejy.60.2024.04.13.17.46.02 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:46:02 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 4/6] mm/memblock: remove consecutive regions at once Date: Sun, 14 Apr 2024 00:45:29 +0000 Message-Id: <20240414004531.6601-4-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 48C4BC0005 X-Stat-Signature: z3bcj6nkxgsc6dsqej1hgqw3ui9gn5kz X-HE-Tag: 1713055565-197971 X-HE-Meta: U2FsdGVkX19wZORq1l/kF7pXxx801mYiYBZd3pSZmeVf/31L8swX2NZeKSoapOZ9K03GbGQmbGaZOJm11rco+7yxUQ+rq6Hf4QdmQOWEyp25M7qpuAxiTFcXvWAj4j24Zopn6E/9XpaYSe12jT2gwSm9Ah05WkIr6PpAdigBgTqmGhVHJlQookVktEgnJtaHFsLVNb2pHUfLkhP+MyXkSYduDTKTO+pZZfuIq77uZ+Wc5A8E79qMcAl3QWWHqGvp1R3Mmd1jMgbnXIV7vKMwy64s0pGc5DkGUkwJt3OTLDMz/TGhA0xL5iihnXdrQ0LvsDFLQaaYZ+zcrLBEqvYklv50XQWopRtxHm4T0c0wMZJPrO1w6OW6lpOYceCDK6Tjx6KEuIUZkly57TqlJvSWdbv362DwXVkTt5x9Wr9agGqr48BKyNP12JEH+LioGupYiscYQsWEwizeZjmLr6hvpiucCgahO+chB4KLNDAqNyjXgUekXWRL5ff8trKwtaa5/6liUOrvS2AstQc6NVJS/H1ImKII/6hw8sUc5fQgSeHjgkSCrd1fs5QAeZywtD4T6wIzN4f6YgfYZiRlTT9IbzMohxVG1locuQhj13yGTWBLYXQlYud30mf/EwkuzRSBKAce2AYBc7PzYaAX/3Zf60s1FJIdlj7eobnZtEmpwo+SE8imFAux/phd9gmfQok33za81Kutc8MpVr1qcKiXczrYRql8e2rPGI3snO0mowzH+Bq+tHcoo2+Rk6j5KMG/EjNf7FNX0dJGiICJ1u/DjnrFsq5YHb/IU+Ei+2Td/c9Jr9wHsNpFoySb1R6NwY5uUHdlRysNP403qukn2+YM8kpcT2t2SWEaB9SBIbdwwI4fQIbrbsZ5AQJ505578KYxe8RlOUw3/G0mosypXBqKy8E+Xs5g9K4/N5xm+zUE1Zik9yx9eZITnPLa0XbRptkTd18ZcabeP/5ehiuT+R6 rsNUsozn Me+f4o6ICxZooWCJ+62jO447gFJfA9+1OH8KTuvlVmWdkf6tLLdh8BnzYyf6dlz3CnkU8QYNT0m6jP6XujYxOc7WC7zZgBH4VGBvvEyH7DgSI1JReP6o5u3R0M/6rz/JBb51sVId2PO2F9a/y7X4yjNcKC2mt32U3IqH7jcaEshceMmw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004804, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In memblock_remove_range, we would remove consecutive regions after isolation. Instead of removing each region from end to start one by one, we could remove those consecutive regions at once. Signed-off-by: Wei Yang --- mm/memblock.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 2d7a2431803f..3fecee4bd41a 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -343,12 +343,15 @@ static phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start, return ret; } -static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r) +static void __init_memblock memblock_remove_regions(struct memblock_type *type, + unsigned long r, + unsigned int num) { - type->total_size -= type->regions[r].size; - memmove(&type->regions[r], &type->regions[r + 1], - (type->cnt - (r + 1)) * sizeof(type->regions[r])); - type->cnt--; + for (int i = 0; i < num; i++) + type->total_size -= type->regions[r + i].size; + memmove(&type->regions[r], &type->regions[r + num], + (type->cnt - (r + num)) * sizeof(type->regions[r])); + type->cnt -= num; /* Special case for empty arrays */ if (type->cnt == 0) { @@ -360,6 +363,11 @@ static void __init_memblock memblock_remove_region(struct memblock_type *type, u } } +static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r) +{ + memblock_remove_regions(type, r, 1); +} + #ifndef CONFIG_ARCH_KEEP_MEMBLOCK /** * memblock_discard - discard memory and reserved arrays if they were allocated @@ -816,14 +824,14 @@ static int __init_memblock memblock_remove_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { int start_rgn, end_rgn; - int i, ret; + int ret; ret = memblock_isolate_range(type, base, size, &start_rgn, &end_rgn); if (ret) return ret; - for (i = end_rgn - 1; i >= start_rgn; i--) - memblock_remove_region(type, i); + if (end_rgn - start_rgn) + memblock_remove_regions(type, start_rgn, end_rgn - start_rgn); return 0; } From patchwork Sun Apr 14 00:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CB58C4345F for ; Sun, 14 Apr 2024 00:46:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DD406B0088; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 863A86B0089; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B3686B008A; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D5506B0088 for ; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D6D261A017C for ; Sun, 14 Apr 2024 00:46:07 +0000 (UTC) X-FDA: 82006295574.16.7360934 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf03.hostedemail.com (Postfix) with ESMTP id 41BDC2000D for ; Sun, 14 Apr 2024 00:46:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kRqbqYjV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055566; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=FbZA/eGRF3szqNEMlv7D5KkYUB2wbEeZywcYOLzw0lv9bXt5xwyd3IA0YrvcHiOzMKitXl 718QPyHFRYFkOFziFfDeGVtJH425FbFf6JcJrW1nezxAUVFDE/56yUecLeQlk9Fvgk29lv lBW2o3GQQcgM4AbeXaT7u1q5mQDFanY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kRqbqYjV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055566; a=rsa-sha256; cv=none; b=BZf/7cvnhU6eqfJW1x+5wc+j8Sy/aSVWh9sEy9/z+yfrh9EzlpcprhZksBaclsztoPWjXf ceuxHRv/KArwLLRVMFls1C7RFzHcpckkJe380/nNo7oyuNSQqE3c9PGFkZNAgsvqaiUa76 1iv33fhubKTEnMVqeUa4uU8s2d0/py4= Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a51a7dc45easo213502066b.2 for ; Sat, 13 Apr 2024 17:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055565; x=1713660365; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=kRqbqYjVXpcWNL5upi/VTx34lJBOCjSqSezdGbn1wyNJLjG4fUPWiOJs/z51QuGwV5 ne6pl5lPajg4PHHUrcPpY6k+90bIvYm1cHcoc1v3gXH2B7kQ+pjsMbuUYF4zRJZkW9Ie wsUe2EpFeLuCtg7oWIPPpnWLWfl2FzIIWLqn9Ajl0mATWSQxDgA/2xh6lT1q+gIpNQME 0iwI5usLqFRx6BLV/t5pptkb6xlSWCdttuhvJYSdvfTcJ0Vkn21DYQMhE4q9lK9p9fMe XauDDE4WZQtXQ4qFPXTHtcdJtmt2iY5Uz3CQTO2iUN4rlmIpGzZfdi6E0k6Pk0pEzjnn +Pmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055565; x=1713660365; h=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=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=Dml7tuzR75rVrqo3DjhGcnAsCfMhWOIbsZzYmGaYEZ+QARVWwzviNCqWUGgLLdKBaC Q3KZcueqNiktLseSyLe+tUrfyqwbBlmzSYspJl1yEfNRrvZU2lTXbu2Rvz/MJZJcKlzK EIIPBMohRYjiZb4HBHJq5kEi+vR2j0y9+Ak0VpMzS/W3hv+OGagQ5GZs5/YLlFam8D+G 86fhpF6Z2p+fSM5OO9wVWFBiwrjT71r3Z6fnm9nMG7OcRp2PJjhSZqt+QM54fK0t7ohX llYGaGRcL6gduMCvohOGnbO8YTLMeoHTlbLJOPIZHf2mzdi42P6JpMD3HJ6IvlqaPZYp QPaw== X-Gm-Message-State: AOJu0YzIS/zd3qlF6RICfHM85EK5I9+j8FFOUKbqv5l0bXTr78a8hEVi TRbRHVW4m++9RZp1Wuk6nYBMUsdk2I3swNckX6JqKLAg8d7pEyy9 X-Google-Smtp-Source: AGHT+IGF6/k0J1LpByQUbQDGxMgnmnDGxE1zqOHpq4sHUArSFWiijLFsN1hi4xEVPed2D5oBOm2jog== X-Received: by 2002:a17:906:dc8:b0:a52:5350:bc5f with SMTP id p8-20020a1709060dc800b00a525350bc5fmr1436399eji.2.1713055564558; Sat, 13 Apr 2024 17:46:04 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id x16-20020a170906135000b00a51a7832a7asm3594690ejb.199.2024.04.13.17.46.03 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:46:04 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 5/6] memblock tests: add memblock_overlaps_region_checks Date: Sun, 14 Apr 2024 00:45:30 +0000 Message-Id: <20240414004531.6601-5-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 41BDC2000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: spmarrbuhufeqcig67qypcu5zpbq9uyh X-HE-Tag: 1713055566-127057 X-HE-Meta: U2FsdGVkX1+tjsAF0zEmE7+wVGcF2AmaV2cQHm5KJYJQKVw/kBvg3IQgi+nLl964d0Ue2EOvSQJdaeljTmWQPaIz/cr2QbawcD7xK9F0865SSVhhatEgwrQRdzaX7k4EH9DehwUqxXh2JLXbnh8I/ZA1B0X9sup8/Hvqvrt4R0fjPAu9TO7eEdMlwdBVefvVTJO3AU0deywiTQIEciq8vL+/GjRO1r2aSxcwsjG8N6RRk9BSDis+TegWXTcJXUxa9IAWTzxf6FU6U4eTh1gBzLQ2QOtJwI+12GIgM3pupIw/RfBcg6XRaddGGasZEiFQsMXhvtsvqgUKZy4wNvldsiOpvtHu2W4Lm4MOv6A1h+BEG7iLt+bdIdjdJRdbFTE885Jm4RBY+QYgcBay3fa4BsWmZOqBWMOaNNNaX9hQ3jlX9QzAJ1F1fSgiyfHOmPjnXWORQqRVAFw+CW3uK1BGSkmhLmNcobOaFmhvNfeVPy8/Kdi8+F7uueFQzmaeyp8Ok/PYAaXi/8CycoNuJ+pcrScL0S7Ajq7KdmsI6mtqcBjvET/pD4UTRcfPDTxmIWoftk5AzCxI3C4fRylimlqKVpzem7oh4OhuwKR01WCn+f4DbH1wki+/2s5v1B8zaZcoSlpRTG13i3/Nb3cM/oMoE+xK9pRu04N/mJ+DuP/6N2PlgCnvBceCSEBr39okrh6VRv8FJERbgcJ5JGJBoJAzdZxUFXqZTWfGTgSsvh6czVuobElOCebPVqNxH6wvaEU9LX1J/cn8g/0WEXnxQlt5xifIy3RS9taF5hMP1ZO3gEy7m+RxKinYySEmRgPQf6oURhKDk3kAs0IcxivQxpQD2g/iZZFX65o/v+ajEj2P+F2BagyVfCCZHvCen+8KxrWyP98RsfN5AlOpYDxn4Jh8BuOcKOqZVgsCars2+66u3/ur2HPNdJdrfgFDOVGOXnpulVHXOvqwQi3ldkYdTly ZAv9P+gv E5aTeFSPf4csfgP39obrB/AtqVQiu6J5evlM4qeJYQAlb4Rat7iKfF8JWDBS8a9Xm1no2Tq++NTejjOQROhyNObSIm9IkTOW3Zq90xGAYxUZVZvoyt90LASYu8/ueRJa25WqYxA3Iin12rfCZE9mp2wEzHa6mTkbTtK330us6fDptMm7OrOYpmudAoNTNHfAoATTfkF7yVGArhVaOYhEmqO4yMMg67zs6MQ2v X-Bogosity: Ham, tests=bogofilter, spamicity=0.000554, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a test case for memblock_overlaps_region(). Signed-off-by: Wei Yang --- tools/testing/memblock/tests/basic_api.c | 48 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.h | 3 ++ 2 files changed, 51 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index f1569ebb9872..5adb0c1eaab9 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -2143,6 +2143,53 @@ static int memblock_trim_memory_checks(void) return 0; } +static int memblock_overlaps_region_check(void) +{ + struct region r = { + .base = SZ_1G, + .size = SZ_4M + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_add(r.base, r.size); + + /* Far Away */ + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1M, SZ_1M)); + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_2G, SZ_1M)); + + /* Neighbor */ + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_1M, SZ_1M)); + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_4M, SZ_1M)); + + /* Partial Overlap */ + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_1M, SZ_2M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_2M, SZ_2M)); + + /* Totally Overlap */ + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G, SZ_4M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_2M, SZ_8M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_1M, SZ_1M)); + + test_pass_pop(); + + return 0; +} + +static int memblock_overlaps_region_checks(void) +{ + prefix_reset(); + prefix_push("memblock_overlaps_region"); + test_print("Running memblock_overlaps_region tests...\n"); + + memblock_overlaps_region_check(); + + prefix_pop(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); @@ -2152,6 +2199,7 @@ int memblock_basic_checks(void) memblock_free_checks(); memblock_bottom_up_checks(); memblock_trim_memory_checks(); + memblock_overlaps_region_checks(); return 0; } diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index b5ec59aa62d7..d8f4c9e64055 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -39,6 +39,9 @@ enum test_flags { assert((_expected) == (_seen)); \ } while (0) +#define ASSERT_TRUE(_seen) ASSERT_EQ(true, _seen) +#define ASSERT_FALSE(_seen) ASSERT_EQ(false, _seen) + /** * ASSERT_NE(): * Check the condition From patchwork Sun Apr 14 00:45:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEF2BC4345F for ; Sun, 14 Apr 2024 00:46:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 442316B008A; Sat, 13 Apr 2024 20:46:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CBDD6B0092; Sat, 13 Apr 2024 20:46:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8F66B0093; Sat, 13 Apr 2024 20:46:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E3FBE6B008A for ; Sat, 13 Apr 2024 20:46:09 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B0F14A01E1 for ; Sun, 14 Apr 2024 00:46:09 +0000 (UTC) X-FDA: 82006295658.29.8A2F2F2 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf09.hostedemail.com (Postfix) with ESMTP id EC5AE14000E for ; Sun, 14 Apr 2024 00:46:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="VOw0n4M/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055568; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=w/dvtf5OnUdjQidRgA75fz8JoBIkn3GX6IPfWGFBXt8=; b=i2lD3HpeE/J/ZuXC0K1LetIOYdHECptgpruYK9TDRtQg7dfTPxccVwga+mGDnYBw9jRtV8 ce8MH5ctijOv4ke0msOsZSgYTXPrYqHVcfHWeMSZRL00P8R/StCHgiOt1re3cgBBxC+IA4 VgzWB5G7v4766uPKxFpoIRkRZnkuHQI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="VOw0n4M/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055568; a=rsa-sha256; cv=none; b=IAHYLWCN+PgNl7BfirR4/tYjQWlIA+uMT55iWI2UnLq9bx7OPcg6na7731dyS61NLccTGJ ZzdlLUoyk7ctA5Diu4VgrIF0RT47ppSVHwEBdGWcSb7FjnDnlp0pxcqiYhRZCscebfrPYb +4kgW4il3bgy9zh9xeu/0aec3+lWXWU= Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d895e2c6efso26015441fa.0 for ; Sat, 13 Apr 2024 17:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055566; x=1713660366; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=w/dvtf5OnUdjQidRgA75fz8JoBIkn3GX6IPfWGFBXt8=; b=VOw0n4M/RlhzuMtGqoRg8FZCUqRV3gBB8h62eoppPij2zUsP0bBZwzvyKtnf3fJHe+ yQh+q6RFBx9fiRS5olR7UBDXwHHIG/Y1uNbCLLrSBy1J46fUysuMgb03MSuzpIan+BFP 02rJ1+1qbnCDdFWw/ulfCnkwkDS4CzRSS0DV4k3IlhAIXzZZsN0b2zkv9/Yo+XKzlxWR c9w3bFamua2ny/kBJiuA+1wJu2BhcRLlptNUQCX2kBU1LeUv0fUKQYEPuzApZH6ZNeYT 3MhWMUBLgUSJGGOygFRqB9e92mjdR+vXNC06BzpI3v2akZwy8iyo5cIsG/qkKy0gKrdz sxtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055566; x=1713660366; h=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=w/dvtf5OnUdjQidRgA75fz8JoBIkn3GX6IPfWGFBXt8=; b=rvS33iCaxVnf1xABMV/1PPcKqxkuHhqvWYcCOIiQrR1U2rAAOMJR0L6tLj5wwdeheP 7jT29Bwd4+yMDnHEercLTypHVriklML0Q0+8uPf1rs2MNyqFggXz42I4WPpIilvD40n0 7wXrSnPAruIfhMyJEe3wNNhxzS9D4PQaVfOQjYgaQ+4i3ijhR5n8goTxDDairM9Tl5I7 CNySyPLLIR+xMHZhgVFOGe/TAaqhvLpAPdr6ciMwuyU1J+fT0yJG1okPm1uKoIREC6C/ wb1lbyZiA3LNM2VPzWRS2ygGHJGTrjYI7u/i+Og352nYXxNy8Vdznddf/o+G9VuWsPVp w0WA== X-Gm-Message-State: AOJu0YzN6TsykhxAEbOsPkmPRqlNKx9p5Rrk9Jsz2b63NR6CHPMuV0H6 XQcPgq5RFrP9t8LDXDJUtBdQ0XBrxBaTgLRI4IDaAdKua98dmZx8 X-Google-Smtp-Source: AGHT+IF8r4PaSqCdZEsz5ZQikXIGPm2x4/7yXMdnCDUjHGr9cWvEYc0lHYJDJqnG7YjuSBEf5aPKlg== X-Received: by 2002:a2e:9ada:0:b0:2d8:6a04:6ac4 with SMTP id p26-20020a2e9ada000000b002d86a046ac4mr4010246ljj.28.1713055566106; Sat, 13 Apr 2024 17:46:06 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id q26-20020a056402041a00b0056e78224d82sm3077837edv.81.2024.04.13.17.46.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:46:05 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 6/6] mm/memblock: return true directly on finding overlap region Date: Sun, 14 Apr 2024 00:45:31 +0000 Message-Id: <20240414004531.6601-6-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: EC5AE14000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: o369wm8rcfwjtk1cg4mxjowypqajz7hm X-HE-Tag: 1713055567-888667 X-HE-Meta: U2FsdGVkX1+aMWRAX7NvPuQb8r/jzBhWfmTzHKL9pvR1O85aYH3APo1sc57z0Anw6j4B7ojjzQnacgeV6roGyFZJjbsnmvFOMzuU8YByTEUBKSCASUhv7tljhqYXBt2/lrMZDSIKfZ1ykw+Kpe+mjyUoN2ImUH7P5zEAyYPcJBIXENFeA1DgR/DtsgIig063Z/DurH2C4dULrkz/Lnk3Ii94z6TM/ECKbsrQ2gvcVqA2CwWQqHXeQlXnKy/OGd2MSZgbEzwpky4Z37dzk7Cp+lSJqVO9vaX6wGKBMsiXRyTJNEs8g8sFQbcC29rRGHoaQDxhNtj8t682kk03LA7XSJkUt3qYCHAv+W7MLdXjP6ut+rzLSOWl99smXZ2RVCd4C5HKDd2XAyG/eLyRjjyOnXhhBP04UMMkij+HaBLTFHK4XxR3MW2TbQq91uI0ykh2AcIQb3fAzSzhr4DhhUpzanm/8aMgN994XLbsblLFcUxCrNpF64C+COuSLNkrEc7fXqfQ/H6O05511RH+lDYz7xe3NDp7rdn+CONPsz0NxHAVjTlaIudrOlXjqQaRhJeZBGJm8AlerCPZ0hdWgAezugS5B4BVsY2y2hbgH6Qau5zPssO2RiDoloxl/SOfN3P3Ez7rVtxwIQOIREzQg4Go4/VDQewRVudBNtg9Rm+NFlwn6WtlvPYetnE/DldldNfMdCI+2jM74b0KYdOutS1QmyCu1BoRP2EWNmIXyIkuQT3tpEIuHTNMiKCgDAcw7gsEYHaVjdl4VXGXbYKh6zXVKbaQHRl6sJwHYQSgukHfs45p5VqRGYlh8T8nS4fxpqwRjrycRp/iFVpWomJnFXKPVbuULEO0zAhxB/pxyJ4nM4EJKgcLOX4XrbzA6l8D3pZrLRE6ibfR/h2HvS1h7xGAwIvhFXS+2bLVPIctHMvJyhAPSUxBu3wxr+bqd6Cw8RnuZPjqBFFHSPyWriXauU/ NQ+TXj5B W+e1hWSjpJUbYCXeDBzXzoWqcuXDnah+UoqEnupok0d7cvpvV+TF0wYDdilxDm9vNV9Zy9gkq4bivuh9ot74Y/QS/TSXras6QA1pasIPf21heaM/95D/Vu7bHMunAL7wHrlxvOygTsvV7p8bSFhOacgchOjri34I4CZXgkHebamFTHty0+tB7vFLF1b20DgsRMNJwSibeFwvEhdbRbeIXObN7/rax80R45pIG7CI38WuHFB7AUBbCPJERTJ4htHiMcW+iK5Hi7eNGZ+TE5QMttZodcT3f4NuH39wRt+mbB+AN6fa1M6lSGCEm0NrdjsRdXVYTNMo1MozVPGj9trXI+J9RnPzJ/y2mUypnhFCji3NwfKp1JVsneqDJQD0YB1xzJlSLxkXMB2VArwklZ6tw/MtIM4Ln4om2OThVidTQHZZwR/o4nqjwv3kOsGPTortVU9gOKsTwrePPauXZ5XxwadmTgoy+iBxngLrG3EEwtQcmg+qBJ3tB+r74J4f9KeNkIYgM X-Bogosity: Ham, tests=bogofilter, spamicity=0.006012, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Not necessary to break and check i against type->cnt again. Signed-off-by: Wei Yang --- mm/memblock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 3fecee4bd41a..77719126208a 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -194,8 +194,8 @@ bool __init_memblock memblock_overlaps_region(struct memblock_type *type, for (i = 0; i < type->cnt; i++) if (memblock_addrs_overlap(base, size, type->regions[i].base, type->regions[i].size)) - break; - return i < type->cnt; + return true; + return false; } /**