Received: by 10.213.65.68 with SMTP id h4csp3831626imn; Tue, 3 Apr 2018 11:21:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+vapNCDMiR4Suh8gHSeOJVe7tn3Bzy8BBGLgP3ZHaX2PT6cjNQJgpSTlRqSeCBpzadcODk X-Received: by 2002:a17:902:650e:: with SMTP id b14-v6mr15390617plk.147.1522779682661; Tue, 03 Apr 2018 11:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522779682; cv=none; d=google.com; s=arc-20160816; b=ZjKJqIJG432gpACpy+qi+k6l7LgcmZIIlA0BhJnuGQMnfw1guVrGpvHRxHYnxEuMen tqNeAkpOIF+9jaZqiPQxd3rixLnYr+BJnBvAcFmelqTROLmZYregsNIM7GklZVcDt+gx 12qzqY8r83K+MlAvCAn5VgWNQsaKlOVay8Xb2AAM2Al3EzVTJYgnthvtyx9aYqORBu+q 82pN/m7jfbrgO7NkQCmzaYAVPAwkllMxopQl1K0CrIO+P8Ihu/X2CaYW/Qaz2r8vOk8r Qp95DB2KmhrYKFSvamA0ZPuYJmpB52sACwEu2imLPbMRn6acLWfSdxTQXCwgRtU1EvyX qGfA== 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:to:from:dkim-signature:arc-authentication-results; bh=1Rteudv6ASX2ROe69v6p1uIgOJF9/EU1FgMfyEh6aGs=; b=rD/s3jKKvtqkQcjtGLmHaJCn3Bnu+eAqJQFs54YMppWHt9kPVOu1fzGTKy8QGd2CPa lWJSowX26WLQSBTmshOBGguTCiYqMzpWJ7F3X3qH0tYT1RsIiNqzeEHiFxrCjAx6Aay3 aSqONELryrslNBqroADP6YYda1Zbuexu8IqNMWFV2zIzrpMnZEG9Llx6YJmp554Blkm2 6bXAnQhYd3Lw5Ibi2KVUrap83Fm3DZApJ4yR/Bytvev5IVU0tL0DGssENlk1SsI0Q8o4 V0Gd0HjAy8/IZy8u5I1MhjQEjVMniIZAjTbi8XOeRkB9Ek3RKbB8k/Pb+dLKpeuqcHM6 ozTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=Ez0db2Dz; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7-v6si1088851plo.389.2018.04.03.11.21.08; Tue, 03 Apr 2018 11:21:22 -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=@oracle.com header.s=corp-2017-10-26 header.b=Ez0db2Dz; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753155AbeDCSRX (ORCPT + 99 others); Tue, 3 Apr 2018 14:17:23 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:47060 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbeDCSRV (ORCPT ); Tue, 3 Apr 2018 14:17:21 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33IGtHq142178; Tue, 3 Apr 2018 18:16:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=1Rteudv6ASX2ROe69v6p1uIgOJF9/EU1FgMfyEh6aGs=; b=Ez0db2DzgknB1kiYIOzc0jWB1sDO+1DJvCsmtaJxIJh9Q7UMiiv0yDyLklLZ/kFbNE7q t02FUTDqUDGt8D+wFXWJ9LlIRWTYtXvEGogTnKoIzD/pS6fDQEOJdE0tUDlHjWT+Hong N42//DTjxPzwSkkyaB0OVxF3+L2Q2uUaO/bMZAsYyamBaWotKTngOjQEt0E9zN+FNQ2w VU2JPYiP1IZ/ZhEmInJVbGqn/n1+Btu2A92urAyA5VWVyKOHhyMXX3FzfN4aEmOU0h6Z qKrZrcT5SdyRy1mtApw3AVGdN5I0rO1rOUQsDtFeSwG/6U9lw1e6xFE1S94jrRToFq8q uw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2h4erm001a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 18:16:56 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w33IGux0015631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 18:16:56 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33IGtXv029466; Tue, 3 Apr 2018 18:16:55 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 11:16:55 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, akpm@linux-foundation.org, mgorman@techsingularity.net, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, vbabka@suse.cz, bharata@linux.vnet.ibm.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, dan.j.williams@intel.com, kirill.shutemov@linux.intel.com, bhe@redhat.com, alexander.levin@microsoft.com Subject: [v6 4/6] mm/memory_hotplug: optimize probe routine Date: Tue, 3 Apr 2018 14:16:41 -0400 Message-Id: <20180403181643.28127-5-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180403181643.28127-1-pasha.tatashin@oracle.com> References: <20180403181643.28127-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8852 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030185 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When memory is hotplugged pages_correctly_reserved() is called to verify that the added memory is present, this routine traverses through every struct page and verifies that PageReserved() is set. This is a slow operation especially if a large amount of memory is added. Instead of checking every page, it is enough to simply check that the section is present, has mapping (struct page array is allocated), and the mapping is online. In addition, we should not excpect that probe routine sets flags in struct page, as the struct pages have not yet been initialized. The initialization should be done in __init_single_page(), the same as during boot. Signed-off-by: Pavel Tatashin Reviewed-by: Ingo Molnar Acked-by: Michal Hocko --- drivers/base/memory.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index fe4b24f05f6a..deb3f029b451 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -187,13 +187,14 @@ int memory_isolate_notify(unsigned long val, void *v) } /* - * The probe routines leave the pages reserved, just as the bootmem code does. - * Make sure they're still that way. + * The probe routines leave the pages uninitialized, just as the bootmem code + * does. Make sure we do not access them, but instead use only information from + * within sections. */ -static bool pages_correctly_reserved(unsigned long start_pfn) +static bool pages_correctly_probed(unsigned long start_pfn) { - int i, j; - struct page *page; + unsigned long section_nr = pfn_to_section_nr(start_pfn); + unsigned long section_nr_end = section_nr + sections_per_block; unsigned long pfn = start_pfn; /* @@ -201,21 +202,24 @@ static bool pages_correctly_reserved(unsigned long start_pfn) * SPARSEMEM_VMEMMAP. We lookup the page once per section * and assume memmap is contiguous within each section */ - for (i = 0; i < sections_per_block; i++, pfn += PAGES_PER_SECTION) { + for (; section_nr < section_nr_end; section_nr++) { if (WARN_ON_ONCE(!pfn_valid(pfn))) return false; - page = pfn_to_page(pfn); - - for (j = 0; j < PAGES_PER_SECTION; j++) { - if (PageReserved(page + j)) - continue; - - printk(KERN_WARNING "section number %ld page number %d " - "not reserved, was it already online?\n", - pfn_to_section_nr(pfn), j); + if (!present_section_nr(section_nr)) { + pr_warn("section %ld pfn[%lx, %lx) not present", + section_nr, pfn, pfn + PAGES_PER_SECTION); + return false; + } else if (!valid_section_nr(section_nr)) { + pr_warn("section %ld pfn[%lx, %lx) no valid memmap", + section_nr, pfn, pfn + PAGES_PER_SECTION); + return false; + } else if (online_section_nr(section_nr)) { + pr_warn("section %ld pfn[%lx, %lx) is already online", + section_nr, pfn, pfn + PAGES_PER_SECTION); return false; } + pfn += PAGES_PER_SECTION; } return true; @@ -237,7 +241,7 @@ memory_block_action(unsigned long phys_index, unsigned long action, int online_t switch (action) { case MEM_ONLINE: - if (!pages_correctly_reserved(start_pfn)) + if (!pages_correctly_probed(start_pfn)) return -EBUSY; ret = online_pages(start_pfn, nr_pages, online_type); -- 2.16.3