From patchwork Thu May 6 15:26:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 12242439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AA12C433ED for ; Thu, 6 May 2021 15:26:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7280661460 for ; Thu, 6 May 2021 15:26:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7280661460 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=sent.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 138F96B006E; Thu, 6 May 2021 11:26:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10F236B0070; Thu, 6 May 2021 11:26:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECAAB6B0071; Thu, 6 May 2021 11:26:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id D18AB6B006E for ; Thu, 6 May 2021 11:26:56 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7B1748249980 for ; Thu, 6 May 2021 15:26:56 +0000 (UTC) X-FDA: 78111184032.06.6964E7F Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by imf02.hostedemail.com (Postfix) with ESMTP id B000C40002FE for ; Thu, 6 May 2021 15:26:23 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id C9638580B88; Thu, 6 May 2021 11:26:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 06 May 2021 11:26:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; s=fm3; bh=w/fhaxzE6d3YP b1A8ivd0FpL8urp0tMSoQqWGTkdTJo=; b=o2YReWlDTlx7hyCpQBDboch01MrBw 7XjJMkWcuWMdUU1UCbOJp6jbpppf/8T43xKOvA3KqIUNAcD7v47a11NT+xE3hVeB 5b9FUBMWLt8yl8x2GL7hpBmyu0//rDLHhFvGadX7Xjxee5PW3R+2Ci1JHCC2zryY 85K32UJuosb15JwG8Xyx7FDxRVfU6Z5I54Gt62vGPLz1HjySj/2AMI38Hm3OloNu JKqxAV3dK2QbmCg4fI1l2AnmsyZtBAWWhs2IQA9FQaemR+Sx5JbXM1ZZR9dwYFlU C7Eose+28so1eMCpyft0SwgW6vAUbncK/pFMt373bKzzosve58IgxM5/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:reply-to:subject :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=w/fhaxzE6d3YPb1A8ivd0FpL8urp0tMSoQqWGTkdTJo=; b=gQxWE4lU bK4F3yUwJzuKmVDo6qBZZlUL1+ZhYW79mLrY/NP7hMvxe4QA/VdzOH5NgZtGzztt nLlUbawg/piw67Kt61d9nCOR/eIxuJzlMPCqG3htIOfA5weA9IxRRKcVdDX5rvpR uZb8ucV3epyency4S+Gbfytw4h2mQlN//neD+N/IjPEVtx8/hmw3ZP/EfT3NMsmr ZiDQPAV5uDotoT6oGL9dqWiWFlo1hURybsVJtWEzrPXPoRWeObyIZ2xPjV44153I /lNHUHmErSufySKQUGqMZFLDCcr/12lBtKF/ULXTHLphvcuy7YO1OAy75/Ft0kWk GJbcGmY9CSUidg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdegtddgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepieejue dvueduuefhgefhheeiuedvtedvuefgieegveetueeiueehtdegudehfeelnecukfhppeef hedrudeigedrvdegiedrfeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Received: from Threadripper.local (ec2-35-164-246-34.us-west-2.compute.amazonaws.com [35.164.246.34]) by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 May 2021 11:26:50 -0400 (EDT) From: Zi Yan To: David Hildenbrand , Oscar Salvador Cc: Michael Ellerman , Benjamin Herrenschmidt , Thomas Gleixner , x86@kernel.org, Andy Lutomirski , "Rafael J . Wysocki" , Andrew Morton , Mike Rapoport , Anshuman Khandual , Michal Hocko , Dan Williams , Wei Yang , linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Zi Yan Subject: [RFC PATCH 1/7] mm: sparse: set/clear subsection bitmap when pages are onlined/offlined. Date: Thu, 6 May 2021 11:26:17 -0400 Message-Id: <20210506152623.178731-2-zi.yan@sent.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210506152623.178731-1-zi.yan@sent.com> References: <20210506152623.178731-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B000C40002FE X-Stat-Signature: kfxpo53k8afmwqqsb47w84ipuazaxiti Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=o2YReWlD; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=gQxWE4lU; spf=pass (imf02.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.230 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received-SPF: none (sent.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=new4-smtp.messagingengine.com; client-ip=66.111.4.230 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620314783-266308 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: From: Zi Yan subsection bitmap was set/cleared when a section is added/removed, but pfn_to_online_page() uses subsection bitmap to check if the page is online, which is not accurate. It was working when a whole section is added/removed during memory hotplug and hotremove. When the following patches enable memory hotplug and hotremove for subsections, subsection bitmap needs to be changed during page online/offline time, otherwise, pfn_to_online_page() will not give right answers. Move the subsection bitmap manipulation code from section_activate() to online_mem_sections() and section_deactivate() to offline_mem_sections(), respectively. Signed-off-by: Zi Yan --- mm/sparse.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index b2ada9dc00cb..7637208b8874 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -606,6 +606,7 @@ void __init sparse_init(void) #ifdef CONFIG_MEMORY_HOTPLUG +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages); /* Mark all memory sections within the pfn range as online */ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn) { @@ -621,9 +622,12 @@ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn) ms = __nr_to_section(section_nr); ms->section_mem_map |= SECTION_IS_ONLINE; + fill_subsection_map(pfn, min(end_pfn, pfn + PAGES_PER_SECTION) - pfn); } } +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages); +static bool is_subsection_map_empty(struct mem_section *ms); /* Mark all memory sections within the pfn range as offline */ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) { @@ -641,7 +645,13 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) continue; ms = __nr_to_section(section_nr); - ms->section_mem_map &= ~SECTION_IS_ONLINE; + + if (end_pfn < pfn + PAGES_PER_SECTION) { + clear_subsection_map(pfn, end_pfn - pfn); + if (is_subsection_map_empty(ms)) + ms->section_mem_map &= ~SECTION_IS_ONLINE; + } else + ms->section_mem_map &= ~SECTION_IS_ONLINE; } } @@ -668,6 +678,17 @@ static void free_map_bootmem(struct page *memmap) vmemmap_free(start, end, NULL); } +static int subsection_map_intersects(struct mem_section *ms, unsigned long pfn, + unsigned long nr_pages) +{ + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; + unsigned long *subsection_map = &ms->usage->subsection_map[0]; + + subsection_mask_set(map, pfn, nr_pages); + + return bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION); +} + static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) { DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; @@ -760,6 +781,12 @@ static void free_map_bootmem(struct page *memmap) } } +static int subsection_map_intersects(struct mem_section *ms, unsigned long pfn, + unsigned long nr_pages) +{ + return 0; +} + static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) { return 0; @@ -800,7 +827,10 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, struct page *memmap = NULL; bool empty; - if (clear_subsection_map(pfn, nr_pages)) + if (WARN((IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) && !ms->usage) || + subsection_map_intersects(ms, pfn, nr_pages), + "section already deactivated (%#lx + %ld)\n", + pfn, nr_pages)) return; empty = is_subsection_map_empty(ms); @@ -855,7 +885,7 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, ms->usage = usage; } - rc = fill_subsection_map(pfn, nr_pages); + rc = !nr_pages || subsection_map_intersects(ms, pfn, nr_pages); if (rc) { if (usage) ms->usage = NULL;