From patchwork Fri Jun 29 02:29:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10495529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E520760325 for ; Fri, 29 Jun 2018 02:30:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C132A6B0 for ; Fri, 29 Jun 2018 02:30:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C48DD2A6E0; Fri, 29 Jun 2018 02:30:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AD222A6B0 for ; Fri, 29 Jun 2018 02:30:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235116B000D; Thu, 28 Jun 2018 22:30:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1BCB86B000E; Thu, 28 Jun 2018 22:30:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ADA16B0010; Thu, 28 Jun 2018 22:30:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f197.google.com (mail-qt0-f197.google.com [209.85.216.197]) by kanga.kvack.org (Postfix) with ESMTP id D9A226B000D for ; Thu, 28 Jun 2018 22:30:38 -0400 (EDT) Received: by mail-qt0-f197.google.com with SMTP id j28-v6so7794311qtc.10 for ; Thu, 28 Jun 2018 19:30:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=prJMZsopAOGvd4i4ZRQwEORKw4GozwPrjoRsWm2lbeQ=; b=eJDq8TMbYF0T8nwGn5Q9HRS+shCcwrn9N8v2ajmojxmmmcLJOP4hDrtiR5f2d3+Txf MLTTjinuyDzax6SEIlSC+Tuc50xB8MB1ncGHsBnS3HUn2KIJ4Ii1M6tVFQwm/Z6nc8vZ +Xa+FATtYGrDKqeCEstHICdqfzVJOwJ80AkqWkUGpkqWBPP8kx1tHkOuRK5c+GDaZ5Dx xXKASqF1YRKhTRPjnhc1h4vxMjNCauazbiwcbIP0XM4Jad8Q099HsP05WQqbtktDAfwO eWVsOG07IozNA7FjD2a4I4PtgFMxxgvYuG7noSMjyJiM9RhwVrMsizBMxoKxwqej+U3G C6AQ== X-Gm-Message-State: APt69E1U9ZkFsgrugVgBGfkmORo3yRBf8xmmGUWFNHnaxOlFJ1BNYAqq pfyJ1uI+KUpuLuh8guLaKy5KailgmWCnMPhWcKJhwDD/J2aMbIpnaEVMcJk0xlYd0tBRwfriqC8 qmfCPVKnp8Ss6zS8iaJg21HRZBOHW8qhsrxiwKzh3bSIEGN9fAg4mAbllYeN+xLt+Q6PacqQxI8 7YwG3YP2OUX16EBwkjGLcCSjeks4rerJl+PlCgD/ZAhuzY8B3A/KJYvypDgiXD46HevkqZpipSq Ul6lck9olkmHDJfb1uPOUxumsMwG7+NOss9BiNVUpfh7w8Lpm/Nogen1DovwhlNrcart0IyicTu ocVLDLnMYBJFAwK5opMNm2l9pFfdXyKQLPap0kbS7P/hzUIs/rqyR3L5aIbd41mGt06RRd6sHid i X-Received: by 2002:a0c:d5b0:: with SMTP id g45-v6mr9084528qvi.162.1530239438679; Thu, 28 Jun 2018 19:30:38 -0700 (PDT) X-Received: by 2002:a0c:d5b0:: with SMTP id g45-v6mr9084505qvi.162.1530239438086; Thu, 28 Jun 2018 19:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530239438; cv=none; d=google.com; s=arc-20160816; b=QEfTmv4uR+3NhlO8mHAAeYMvmGHhDgIoSLklIfu0qp5kp1l3bqL1s2YBPca0KPT57O 5tTHwKGYidsvi2d5SfRwLXVDj6WeAx/YuAfifJzEysk9ge8G2ZWSANrTXslYXJ94PEVx YX96vv64P97/vNRKsGB5cUtaQ+EQk1Sc4efM3RsHYWEi8VXxLBr8JVeM1PGMslrO14pj eh5r08A4txYzaMAYEBtdW0BN/Yyml3YmCUnjUVqJany8FzMxivR7x6SR6gzD2dGcrj24 d6KD3J1zUdTjV8jUvwAT0PT6JocbSGWW1klMJyx53dgz2mU0DXPENxAbVF+7jF4P/WFb a6Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=prJMZsopAOGvd4i4ZRQwEORKw4GozwPrjoRsWm2lbeQ=; b=ZJlomPKDAMZj9M0vM81b9xjCR5/mJSX2bqAoAfa33Uir20vEbyfHXKs0nE+WQfQs38 eJGd20cgv00mSwa/FA00wRFEwi+aqNbd+PUfBHrLih2W5jVfq6pfgbrncDmZWSPtBOUx bsKrLaYHZLhXCt/VSddrx/EJ7cqeoA693IAz6o2yq86CevG2hnyg48zeMHcp5IrPNqKD K/zH7vV5xq13K9bBcKLawTz75u188edE2bG9NX+eeRK60vL6lnQxvefkXh/xgCQMEJEZ s6Bi+ROciPW9ezSKgVomSmsYvF2tmYE0Nln6/5tDkK2s6Lnc+A6NVsYCLt+zaEveWYc/ BZEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lgz2ZEIT; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w8-v6sor4594338qti.107.2018.06.28.19.30.38 for (Google Transport Security); Thu, 28 Jun 2018 19:30:38 -0700 (PDT) Received-SPF: pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lgz2ZEIT; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=prJMZsopAOGvd4i4ZRQwEORKw4GozwPrjoRsWm2lbeQ=; b=lgz2ZEITaTVt04bNM0MT1SISuJTXx0Rrp9eDDycJTaX5aaZ2EjdEkQIohH1B4y5DJ1 UVtQ05IMUPPQDIkMJomg4YdUJZdcRLkstlBJEJrl0EphcxFg2qo31ZgwygThX1wsIBUS I7i4MMopE7BZN7yy/IdUjYiQBmMKyS118ZTsDrbJnogA8q3ub001IAScmRzo2y+dgS2N G1/ImPXpnQ7Cx+on6s9Qd5DXMS7oule9bzFoqJXSgqtJ3CLUNb0UU/3XXJwxNgLJ4N4y F411z6/P0abiJ8Eqsk4pIg7nfNf//HZ6Zab/BvUPZRskxzfOfDuir+diI5NAVptBt5lP uUjg== X-Google-Smtp-Source: AAOMgpcqIJfzdL/03nyFApzj1RxfQp6BJ298UNev1sqy6C08/xo2E1+n4eX8mzOaHT7tnEzj84w41Q== X-Received: by 2002:aed:2a4a:: with SMTP id k10-v6mr4494886qtf.102.1530239437883; Thu, 28 Jun 2018 19:30:37 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id y25-v6sm6390186qtc.48.2018.06.28.19.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 19:30:37 -0700 (PDT) From: Jia He To: Russell King , Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , "H. Peter Anvin" Cc: Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Daniel Vacek , Eugeniu Rosca , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, James Morse , Ard Biesheuvel , Steve Capper , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , richard.weiyang@gmail.com, Jia He , Jia He Subject: [PATCH v9 3/6] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Date: Fri, 29 Jun 2018 10:29:20 +0800 Message-Id: <1530239363-2356-4-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530239363-2356-1-git-send-email-hejianet@gmail.com> References: <1530239363-2356-1-git-send-email-hejianet@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns where possible") optimized the loop in memmap_init_zone(). But there is still some room for improvement. E.g. if pfn and pfn+1 are in the same memblock region, we can simply pfn++ instead of doing the binary search in memblock_next_valid_pfn. Furthermore, if the pfn is in a *gap* of two memory region, skip to next region directly if possible. Signed-off-by: Jia He --- include/linux/early_pfn.h | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/include/linux/early_pfn.h b/include/linux/early_pfn.h index 1b001c7..f9e40c3 100644 --- a/include/linux/early_pfn.h +++ b/include/linux/early_pfn.h @@ -3,31 +3,52 @@ #ifndef __EARLY_PFN_H #define __EARLY_PFN_H #ifdef CONFIG_HAVE_MEMBLOCK_PFN_VALID +static int early_region_idx __init_memblock = -1; ulong __init_memblock memblock_next_valid_pfn(ulong pfn) { struct memblock_type *type = &memblock.memory; - unsigned int right = type->cnt; - unsigned int mid, left = 0; + struct memblock_region *regions = type->regions; + uint right = type->cnt; + uint mid, left = 0; + ulong start_pfn, end_pfn, next_start_pfn; phys_addr_t addr = PFN_PHYS(++pfn); + /* fast path, return pfn+1 if next pfn is in the same region */ + if (early_region_idx != -1) { + start_pfn = PFN_DOWN(regions[early_region_idx].base); + end_pfn = PFN_DOWN(regions[early_region_idx].base + + regions[early_region_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return pfn; + + early_region_idx++; + next_start_pfn = PFN_DOWN(regions[early_region_idx].base); + + if (pfn >= end_pfn && pfn <= next_start_pfn) + return next_start_pfn; + } + + /* slow path, do the binary searching */ do { mid = (right + left) / 2; - if (addr < type->regions[mid].base) + if (addr < regions[mid].base) right = mid; - else if (addr >= (type->regions[mid].base + - type->regions[mid].size)) + else if (addr >= (regions[mid].base + regions[mid].size)) left = mid + 1; else { - /* addr is within the region, so pfn is valid */ + early_region_idx = mid; return pfn; } } while (left < right); if (right == type->cnt) return -1UL; - else - return PHYS_PFN(type->regions[right].base); + + early_region_idx = right; + + return PHYS_PFN(regions[early_region_idx].base); } EXPORT_SYMBOL(memblock_next_valid_pfn); #endif /*CONFIG_HAVE_MEMBLOCK_PFN_VALID*/