From mboxrd@z Thu Jan 1 00:00:00 1970 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 9AC96C43460 for ; Thu, 6 May 2021 15:28:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EBF561C1C for ; Thu, 6 May 2021 15:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235836AbhEFP3y (ORCPT ); Thu, 6 May 2021 11:29:54 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:57335 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235640AbhEFP2L (ORCPT ); Thu, 6 May 2021 11:28:11 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 71F10580B96; Thu, 6 May 2021 11:27:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 06 May 2021 11:27:12 -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=qMAcSPfa3+cns kyYYIug3mYJD6YPqlrp2UQ4EuPYWbE=; b=vtLuAgKHZkDwSV7IEZxfPQeS0i3od uHpKdWO1xcEauvSAdrI0PKRkEwsYOnT4bXXbgcJ7k+PfuFslrZeyYZS735rskONI iamYJyO1wXcaPT7TJQ03m0Uc3uGQ7qFAOQHQKoT42rWc1TzStBMxZEqD2gnhAm7i 7z6qcArs4OOnyZCf4w+Eq7DZtkzw/BjhgNu2sLVFuYHp0PcxhOre0uFmxb6zTUoi E8FBovJ39w2c32lrc7+rIROM1vd2Rvzl5CLItfaWfphh145TnW9ZyGxcQhhLvGVG TGgIHJwei7XBBlErWT+PQ59ZJV1I468hx8tF2+reH07GsMVBX6l1mju3A== 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=qMAcSPfa3+cnskyYYIug3mYJD6YPqlrp2UQ4EuPYWbE=; b=A/fF9xZE aVi6cOoeWYwnn/g0KjDniMYoWv/W0ohiBN2QsYTn6BHlLnDf2TDA8t7uH5T7/N7p f1T4CifW3tWAl0rxH0XcTRRLmYVK31P/vzemd6wPDJW0wMnCkdEntCf33G3781H1 D96lT9GosU4olO9VFDPbOgt2Yg0w4OgmJc72YlvF8E7+e/8jJgMJ7sp8pqsnYs6n w+INleKbjrPR9bGljr/C0b53Q2bs4MxAVIPEqstzpY4SwNOzZuDloMcGEDcs6XNr CKImonVyY0GNaPlhwbeNoZSn1RT2cayY8mVAYcMGqjcGZGLfUiGHcHE3H6LYCmnG k0FIJQRqYNwB4Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdegtddgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepieejue dvueduuefhgefhheeiuedvtedvuefgieegveetueeiueehtdegudehfeelnecukfhppeef hedrudeigedrvdegiedrfeegnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpe 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:27:08 -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 5/7] mm: memory_hotplug, sparse: enable memory hotplug/hotremove subsections Date: Thu, 6 May 2021 11:26:21 -0400 Message-Id: <20210506152623.178731-6-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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zi Yan Remove the section size alignment checks for memory hotplug/hotremove, so that we can online/offline subsection memory. Signed-off-by: Zi Yan --- mm/memory_hotplug.c | 16 +++++++++------- mm/page_isolation.c | 4 ---- mm/sparse.c | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 6e93b0ecc5cb..5384bb62ac10 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -661,12 +661,15 @@ static void online_pages_range(unsigned long start_pf= n, unsigned long nr_pages) * When using memmap_on_memory, the range might not be aligned to * MAX_ORDER_NR_PAGES - 1, but pageblock aligned. __ffs() will detect * this and the first chunk to online will be pageblock_nr_pages. + * When onlining subsections, the range might be smaller than MAX_ORDER + * - 1, use __ffs(nr_pages) to get the right size. */ for (pfn =3D start_pfn; pfn < end_pfn;) { - int order =3D min(MAX_ORDER - 1UL, __ffs(pfn)); + int order =3D min3(MAX_ORDER - 1UL, __ffs(pfn), __ffs(nr_pages)); =20 (*online_page_callback)(pfn_to_page(pfn), order); pfn +=3D (1UL << order); + nr_pages -=3D (1UL << order); } =20 /* mark all involved sections as online */ @@ -912,16 +915,16 @@ int __ref online_pages(unsigned long pfn, unsigned lo= ng nr_pages, struct zone *z struct memory_notify arg; =20 /* - * {on,off}lining is constrained to full memory sections (or more + * {on,off}lining is constrained to memory subsections (or more * precisly to memory blocks from the user space POV). * memmap_on_memory is an exception because it reserves initial part * of the physical memory space for vmemmaps. That space is pageblock * aligned. */ if (WARN_ON_ONCE(!nr_pages || - !IS_ALIGNED(pfn, pageblock_nr_pages) || - !IS_ALIGNED(pfn + nr_pages, PAGES_PER_SECTION))) + !IS_ALIGNED(pfn + nr_pages, PAGES_PER_SUBSECTION))) { return -EINVAL; + } =20 mem_hotplug_begin(); =20 @@ -1702,15 +1705,14 @@ int __ref offline_pages(unsigned long start_pfn, un= signed long nr_pages) char *reason; =20 /* - * {on,off}lining is constrained to full memory sections (or more + * {on,off}lining is constrained to memory subsections (or more * precisly to memory blocks from the user space POV). * memmap_on_memory is an exception because it reserves initial part * of the physical memory space for vmemmaps. That space is pageblock * aligned. */ if (WARN_ON_ONCE(!nr_pages || - !IS_ALIGNED(start_pfn, pageblock_nr_pages) || - !IS_ALIGNED(start_pfn + nr_pages, PAGES_PER_SECTION))) + !IS_ALIGNED(start_pfn + nr_pages, PAGES_PER_SUBSECTION))) return -EINVAL; =20 mem_hotplug_begin(); diff --git a/mm/page_isolation.c b/mm/page_isolation.c index c1b9b8848382..7f1791faf03f 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -147,7 +147,6 @@ __first_valid_page(unsigned long pfn, unsigned long nr_= pages) * be MIGRATE_ISOLATE. * @start_pfn: The lower PFN of the range to be isolated. * @end_pfn: The upper PFN of the range to be isolated. - * start_pfn/end_pfn must be aligned to pageblock_order. * @migratetype: Migrate type to set in error recovery. * @flags: The following flags are allowed (they can be combined in * a bit mask) @@ -190,9 +189,6 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, unsigned long undo_pfn; struct page *page; =20 - BUG_ON(!IS_ALIGNED(start_pfn, pageblock_nr_pages)); - BUG_ON(!IS_ALIGNED(end_pfn, pageblock_nr_pages)); - for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D pageblock_nr_pages) { diff --git a/mm/sparse.c b/mm/sparse.c index 1c2957807882..09b5e6978ab0 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -251,7 +251,8 @@ void __init subsection_map_init(unsigned long pfn, unsi= gned long nr_pages) /* Record a memory area against a node. */ static void __init memory_present(int nid, unsigned long start, unsigned l= ong end) { - unsigned long pfn; + unsigned long pfn, nr_pages; + unsigned long section, end_sec, start_sec; =20 #ifdef CONFIG_SPARSEMEM_EXTREME if (unlikely(!mem_section)) { @@ -268,9 +269,17 @@ static void __init memory_present(int nid, unsigned lo= ng start, unsigned long en =20 start &=3D PAGE_SECTION_MASK; mminit_validate_memmodel_limits(&start, &end); - for (pfn =3D start; pfn < end; pfn +=3D PAGES_PER_SECTION) { - unsigned long section =3D pfn_to_section_nr(pfn); + start_sec =3D pfn_to_section_nr(start); + end_sec =3D pfn_to_section_nr(end - 1); + pfn =3D start; + nr_pages =3D end - start; + + for (section =3D start_sec; section <=3D end_sec; section++) { struct mem_section *ms; + unsigned long pfns; + + pfns =3D min(nr_pages, PAGES_PER_SECTION + - (pfn & ~PAGE_SECTION_MASK)); =20 sparse_index_init(section, nid); set_section_nid(section, nid); @@ -281,6 +290,8 @@ static void __init memory_present(int nid, unsigned lon= g start, unsigned long en SECTION_IS_ONLINE; section_mark_present(ms); } + pfn +=3D pfns; + nr_pages -=3D pfns; } } =20 --=20 2.30.2