Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1466956pxy; Thu, 6 May 2021 08:31:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+Bxja5ISHBQojfOE2qqrMHLCJLTHjBUPjfbijhdDx/p2COLBpcSfA9x1DubuZBdCE6l8Y X-Received: by 2002:a17:902:e5c5:b029:ed:23f3:2b10 with SMTP id u5-20020a170902e5c5b02900ed23f32b10mr5451994plf.50.1620315108163; Thu, 06 May 2021 08:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620315108; cv=none; d=google.com; s=arc-20160816; b=hjo+Qe7Z6j3IpzWqnpoH60u7aTgSqvtj3D3NX04EC992pXVHGNUuJdTKAkqBAFh5CX HMIiKGZ4AkG/iOqNiwPd8Ouj7lnF1QMTpCCFo5XVUpMqKx2yhhkFu47G+E+nFFNijvUS /UOe5hXppCbXwaPGbw40tYV/MuOu88LTOfafESHIpnT4zpDbfzHu4JwtYxtmkhpPqXNk czoBNfV11KW7g87kBQI9a0mVBLh8mZDZBAGIrneZRR4Pi5sn0fu2VbIjC4kwB5xJC0I8 E+I6gF61hkmbN2io4MrqGXA5e3d4JYuHYdmpLCivDxfyNGibH8q1UwGT1QOTeLdPIx8e JAsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=qMAcSPfa3+cnskyYYIug3mYJD6YPqlrp2UQ4EuPYWbE=; b=munjdN0IZT2OfV7HuH/SIeYst/JaizlTGseqGnFL9J2XEdq1r1k1ej7HBc5rvaaLvQ 9DIM1o5duqJGABuUryZ863KulQUN0QDZ7LMyFh4kxruTt7L9fyChnZudh4GIu4JLaU7Q MfMB42VvaMTsfSYaMEtklN4ovFhtoVpdzHfxyAtAfecvcPp8B6oA4bN4w3HXkD1XX0Dp /gUryorLso0eiZ/eFEoOjm1cpgNAF9C4pNYP6RC0b0aSZmOhcZmosY2xZeTQ+70wjhkp U3WyzYRZRgYnce18sdnPThMz+IZbSPMijZF3tYKyfaMwmfmvY9DZ9cilmdjJRE4X8OyF Hp4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=vtLuAgKH; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="A/fF9xZE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 3si3694481plc.345.2021.05.06.08.31.34; Thu, 06 May 2021 08:31:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=vtLuAgKH; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="A/fF9xZE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235829AbhEFP3y (ORCPT + 99 others); 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