Received: by 10.213.65.68 with SMTP id h4csp1652829imn; Thu, 5 Apr 2018 01:08:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/3drEaO9kH4mg8n49F/gRzFESPhh3kZdr+/kkhk2ujzuJs0D774rq/FYSmGWUT+hKDFKt X-Received: by 2002:a17:902:7894:: with SMTP id q20-v6mr22283063pll.86.1522915720750; Thu, 05 Apr 2018 01:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522915720; cv=none; d=google.com; s=arc-20160816; b=dB6p6BqfCRBgP/C+RELmnCBR33fVd2UE+GiCPpwd2/Kae/nW5wBSKilcjSLOWC0QjB dwyc3ebDe/mFazZznFZXZ9/518eKn6o0s2b1YGXkzrb9ibQScOmi65/sl1sRczMpfZMi gtea/xg0I15sN2vdoN74/PBX9qgWV1UyKUYTJXlbARmYfmez+5KcXurA9UnXRkV4o3DE ZSkbFxlKNCwbHUnF8WLROGdQuVznk7qEO7SquH402DhR/Xx/ZbAsjsJv9SECEahmlaCr 9vno+CnlyvabZagzJGXLYt6u32vr0MSJ4NUggY/YdbfbpEfRU3O5pyvzvjfBHv1PdSkX 6TQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=yP8AwBNdbCp8zdCZ0aY/sYN+4ol/odIDNOPeJGGjQtSOymy+Zgo0Y6tze+cq6xcqvT iqtwrhjk0BHQErCwehGUSMSiPiyeluYuW8Y0YrQrxlMGuFnDh29OMoRPVwQOFmcRmJvA GbzKY6PQMTYuw2SUZcuQCHLBebZQSv5y5uQ9bfQza5hJnyyzPEUK0H2ewAa2J+p14aBv xfSkYw9SlaQz+5Q+IP9Mdmb53Fo5CBCp5KpGTCHYt34d0U/w89lQVV5hl11Sfd1khNTo rNNKr929bLry4qFsCqytrIvG7Vpw5KHAsO3JvdkjTzLuUeK7PK3RmSrxK3KOLDHod77J d40g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TFn2gDSi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66-v6si5749716pld.315.2018.04.05.01.08.26; Thu, 05 Apr 2018 01:08:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TFn2gDSi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbeDEIFa (ORCPT + 99 others); Thu, 5 Apr 2018 04:05:30 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:38408 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbeDEIFZ (ORCPT ); Thu, 5 Apr 2018 04:05:25 -0400 Received: by mail-pl0-f66.google.com with SMTP id k6-v6so12952719pls.5 for ; Thu, 05 Apr 2018 01:05:25 -0700 (PDT) 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=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=TFn2gDSieLwf2+iSC9j4T+7O1VoDltt0bxsu3h1caZZKREdNmnPfLvYArFuaoeigu/ mE/RT8HIW9ep77mvWZc7AtHhNO90jiB+kHfokdvJw6yFU6cmxWXrOU2QzsepsACKTz3/ n+vgGG0xVJ5c8uY6421dDoZnLC51j9tX42z6q4FfJ34xVPdFwWTj1njtX5rkGIARAgfA zpjRwCsvDMlV2E2PyIqIcyR4oZxHpIpCAao7Oz8mWlzAEY89dELcE/BummLJwFw0pLwF A2rwfKTcESr4gcMdarBBbyUxEgQ+Cgf1FDSxwVD2hnIcjlLH2dbUFhE4Ly+VnZfYR85A uqjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=lgc9mqQA+rWMxz40SKlziYCUzIiib1u4RbA1/dSJvy0xavUh8n+AbH26WKtSCc/tGM EnrUFs9zlNUmO6H8OTx8F0Plsb8vFWVHNJEkUPc2gOd5esPsEpug8r+KNQ/+QCAJ18iH 2VxmUlU8r+yTdt+8isyKM5HQ6RJVv+i7/kLPWqRUl5XcEDetrSQQVJXqX6UUhvMZt/JW EzCn4LKY4+6LEnHC5L5rzmx6ndKFf+VPD3aBNxiP/jwt4kG25FU+TIroVecYH/ShzZ98 ZHkWRIW42Ct2ivo2qrhQ1pfM5E4ux1LD9XddzkHkrPPVGOFartPRladT/YiFWld3aBPQ w/fQ== X-Gm-Message-State: AElRT7HiizKtpBnZ1YMeg1A9yqjDez/waCbocD0cKMavsnwaUMU7FC4e CtgocI8Ox4YjrWP4nYqAXtI= X-Received: by 10.99.37.196 with SMTP id l187mr14241483pgl.221.1522915525312; Thu, 05 Apr 2018 01:05:25 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id 2sm14983690pft.33.2018.04.05.01.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 01:05:24 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Cc: Wei Yang , Kees Cook , Laura Abbott , Vladimir Murzin , Philip Derrin , AKASHI Takahiro , James Morse , Steve Capper , Pavel Tatashin , Gioh Kim , Vlastimil Babka , Mel Gorman , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Daniel Jordan , Daniel Vacek , Eugeniu Rosca , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jia He , Jia He Subject: [PATCH v7 2/5] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Date: Thu, 5 Apr 2018 01:04:35 -0700 Message-Id: <1522915478-5044-3-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522915478-5044-1-git-send-email-hejianet@gmail.com> References: <1522915478-5044-1-git-send-email-hejianet@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Jia He --- include/linux/arm96_common.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/include/linux/arm96_common.h b/include/linux/arm96_common.h index a6f68ea..2f4dea4 100644 --- a/include/linux/arm96_common.h +++ b/include/linux/arm96_common.h @@ -5,32 +5,47 @@ #ifndef __ARM96_COMMON_H #define __ARM96_COMMON_H #ifdef CONFIG_HAVE_ARCH_PFN_VALID +static int early_region_idx __init_memblock = -1; /* HAVE_MEMBLOCK is always enabled on arm and arm64 */ 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; 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; + } + + /* 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_ARCH_PFN_VALID*/ -- 2.7.4