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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 861C5CA9EB9 for ; Tue, 22 Oct 2019 17:13:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D3D42184C for ; Tue, 22 Oct 2019 17:13:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HjwTHavs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D3D42184C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E402D6B0006; Tue, 22 Oct 2019 13:13:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEE506B0007; Tue, 22 Oct 2019 13:13:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB6C46B0008; Tue, 22 Oct 2019 13:13:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id A5F406B0006 for ; Tue, 22 Oct 2019 13:13:41 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 5A4B4181AEF15 for ; Tue, 22 Oct 2019 17:13:41 +0000 (UTC) X-FDA: 76072067442.12.glove64_3d40246e1294d X-HE-Tag: glove64_3d40246e1294d X-Filterd-Recvd-Size: 8270 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Oct 2019 17:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571764419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZH06pjD8CJbFdhi6tvHbczu1qJrML9IKvQHQzytrv0=; b=HjwTHavssJir/f35aIosF2GH9mBMREjy/yTEf/2cBJgw3Y/CJvc2mVC4q2udJV7TUDP+aD SEiVBUQOI9SFhqcpzzZm+gSBxu0Q3t3/FeWm20V5+CJ4/qjz6FOvJJDLb/STPXKPoqDK2Z BPmhDQ/SbjKrZq1zmNNMzrRT2TAvWsA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-GNMLLVycPz2hWyHgrsFHmQ-1; Tue, 22 Oct 2019 13:13:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03CD81800D6A; Tue, 22 Oct 2019 17:13:31 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-248.ams2.redhat.com [10.36.116.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id C74C05DA8D; Tue, 22 Oct 2019 17:13:07 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Michal Hocko , Andrew Morton , kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, devel@driverdev.osuosl.org, xen-devel@lists.xenproject.org, x86@kernel.org, Alexander Duyck , Alexander Duyck , Alex Williamson , Allison Randal , Andy Lutomirski , "Aneesh Kumar K.V" , Anshuman Khandual , Anthony Yznaga , Ben Chan , Benjamin Herrenschmidt , Borislav Petkov , Boris Ostrovsky , Christophe Leroy , Cornelia Huck , Dan Carpenter , Dan Williams , Dave Hansen , Fabio Estevam , Greg Kroah-Hartman , Haiyang Zhang , "H. Peter Anvin" , Ingo Molnar , "Isaac J. Manjarres" , Jeremy Sowden , Jim Mattson , Joerg Roedel , Johannes Weiner , Juergen Gross , KarimAllah Ahmed , Kate Stewart , Kees Cook , "K. Y. Srinivasan" , Madhumitha Prabakaran , Matt Sickler , Mel Gorman , Michael Ellerman , Michal Hocko , Mike Rapoport , Mike Rapoport , Nicholas Piggin , Nishka Dasgupta , Oscar Salvador , Paolo Bonzini , Paul Mackerras , Paul Mackerras , Pavel Tatashin , Pavel Tatashin , Peter Zijlstra , Qian Cai , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Rob Springer , Sasha Levin , Sean Christopherson , =?UTF-8?q?Simon=20Sandstr=C3=B6m?= , Stefano Stabellini , Stephen Hemminger , Thomas Gleixner , Todd Poynor , Vandana BN , Vitaly Kuznetsov , Vlastimil Babka , Wanpeng Li , YueHaibing Subject: [PATCH RFC v1 01/12] mm/memory_hotplug: Don't allow to online/offline memory blocks with holes Date: Tue, 22 Oct 2019 19:12:28 +0200 Message-Id: <20191022171239.21487-2-david@redhat.com> In-Reply-To: <20191022171239.21487-1-david@redhat.com> References: <20191022171239.21487-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: GNMLLVycPz2hWyHgrsFHmQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable 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: Our onlining/offlining code is unnecessarily complicated. Only memory blocks added during boot can have holes. Hotplugged memory never has holes. That memory is already online. When we stop allowing to offline memory blocks with holes, we implicitly stop to online memory blocks with holes. This allows to simplify the code. For example, we no longer have to worry about marking pages that fall into memory holes PG_reserved when onlining memory. We can stop setting pages PG_reserved. Offlining memory blocks added during boot is usually not guranteed to work either way. So stopping to do that (if anybody really used and tested this over the years) should not really hurt. For the use case of offlining memory to unplug DIMMs, we should see no change. (holes on DIMMs would be weird) Cc: Andrew Morton Cc: Michal Hocko Cc: Oscar Salvador Cc: Pavel Tatashin Cc: Dan Williams Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 561371ead39a..7210f4375279 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1447,10 +1447,19 @@ static void node_states_clear_node(int node, struct= memory_notify *arg) =09=09node_clear_state(node, N_MEMORY); } =20 +static int count_system_ram_pages_cb(unsigned long start_pfn, +=09=09=09=09 unsigned long nr_pages, void *data) +{ +=09unsigned long *nr_system_ram_pages =3D data; + +=09*nr_system_ram_pages +=3D nr_pages; +=09return 0; +} + static int __ref __offline_pages(unsigned long start_pfn, =09=09 unsigned long end_pfn) { -=09unsigned long pfn, nr_pages; +=09unsigned long pfn, nr_pages =3D 0; =09unsigned long offlined_pages =3D 0; =09int ret, node, nr_isolate_pageblock; =09unsigned long flags; @@ -1461,6 +1470,20 @@ static int __ref __offline_pages(unsigned long start= _pfn, =20 =09mem_hotplug_begin(); =20 +=09/* +=09 * We don't allow to offline memory blocks that contain holes +=09 * and consecuently don't allow to online memory blocks that contain +=09 * holes. This allows to simplify the code quite a lot and we don't +=09 * have to mess with PG_reserved pages for memory holes. +=09 */ +=09walk_system_ram_range(start_pfn, end_pfn - start_pfn, &nr_pages, +=09=09=09 count_system_ram_pages_cb); +=09if (nr_pages !=3D end_pfn - start_pfn) { +=09=09ret =3D -EINVAL; +=09=09reason =3D "memory holes"; +=09=09goto failed_removal; +=09} + =09/* This makes hotplug much easier...and readable. =09 we assume this for now. .*/ =09if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start, @@ -1472,7 +1495,6 @@ static int __ref __offline_pages(unsigned long start_= pfn, =20 =09zone =3D page_zone(pfn_to_page(valid_start)); =09node =3D zone_to_nid(zone); -=09nr_pages =3D end_pfn - start_pfn; =20 =09/* set above range as isolated */ =09ret =3D start_isolate_page_range(start_pfn, end_pfn, --=20 2.21.0