From nobody Mon Feb 9 15:10:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571764499; cv=none; d=zoho.com; s=zohoarc; b=WiLPuAQtBVbjdj+GnT+aFD/hNuphqV3jEDcku2QMwNdYI52PQeBR7FKAVSEJk5JtYTMjyrJXlkfqTAXAPeyt6rRS6g2x5TtX+vgg/Dg8DGU+iyVZoEwwULrnH9SKkUGegboJJuTWc6W7NAWZo1AXnxVIglg0//LtpzGBoFow3JA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571764499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JozlZHet3LSer3dpdszdcwLOQrmO8wKT7l4bx0vWeiY=; b=Kivq54PbCT8ThFXS9ij2Yfvkc1L+mwMEEqyA/5AxUB3pLL3+1sWVgJck81eD79e2bVoQ+pZZrFULwuqHh2lvgj8iAEifZgvZK6IjIn0H8TtN++REqTOcB29MHa5C3cVjftKI8hhPJzVdsvSENF1oDD1QAzNg6hscAmFM7iqxrsA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1571764499619931.0996156178502; Tue, 22 Oct 2019 10:14:59 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iMxj4-00061f-PX; Tue, 22 Oct 2019 17:13:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iMxj3-00061U-04 for xen-devel@lists.xenproject.org; Tue, 22 Oct 2019 17:13:41 +0000 Received: from us-smtp-1.mimecast.com (unknown [207.211.31.81]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 4a92d35d-f4ef-11e9-946f-12813bfff9fa; Tue, 22 Oct 2019 17:13:39 +0000 (UTC) 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) X-Inumbo-ID: 4a92d35d-f4ef-11e9-946f-12813bfff9fa 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= From: David Hildenbrand To: linux-kernel@vger.kernel.org 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 Subject: [Xen-devel] [PATCH RFC v1 01/12] mm/memory_hotplug: Don't allow to online/offline memory blocks with holes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , Sasha Levin , linux-hyperv@vger.kernel.org, Michal Hocko , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, David Hildenbrand , KarimAllah Ahmed , Benjamin Herrenschmidt , Dave Hansen , Alexander Duyck , Michal Hocko , Paul Mackerras , linux-mm@kvack.org, Pavel Tatashin , Paul Mackerras , Michael Ellerman , "H. Peter Anvin" , Wanpeng Li , Alexander Duyck , "K. Y. Srinivasan" , Fabio Estevam , Ben Chan , Kees Cook , devel@driverdev.osuosl.org, Stefano Stabellini , Stephen Hemminger , "Aneesh Kumar K.V" , Joerg Roedel , x86@kernel.org, YueHaibing , Mike Rapoport , Madhumitha Prabakaran , Peter Zijlstra , Ingo Molnar , Vlastimil Babka , Nishka Dasgupta , Anthony Yznaga , Oscar Salvador , Dan Carpenter , "Isaac J. Manjarres" , Matt Sickler , Juergen Gross , Anshuman Khandual , Haiyang Zhang , =?UTF-8?q?Simon=20Sandstr=C3=B6m?= , Dan Williams , kvm-ppc@vger.kernel.org, Qian Cai , Alex Williamson , Mike Rapoport , Borislav Petkov , Nicholas Piggin , Andy Lutomirski , xen-devel@lists.xenproject.org, Boris Ostrovsky , Todd Poynor , Vitaly Kuznetsov , Allison Randal , Jim Mattson , Christophe Leroy , Vandana BN , Jeremy Sowden , Greg Kroah-Hartman , Cornelia Huck , Pavel Tatashin , Mel Gorman , Sean Christopherson , Rob Springer , Thomas Gleixner , Johannes Weiner , Paolo Bonzini , Andrew Morton , linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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) node_clear_state(node, N_MEMORY); } =20 +static int count_system_ram_pages_cb(unsigned long start_pfn, + unsigned long nr_pages, void *data) +{ + unsigned long *nr_system_ram_pages =3D data; + + *nr_system_ram_pages +=3D nr_pages; + return 0; +} + static int __ref __offline_pages(unsigned long start_pfn, unsigned long end_pfn) { - unsigned long pfn, nr_pages; + unsigned long pfn, nr_pages =3D 0; unsigned long offlined_pages =3D 0; int ret, node, nr_isolate_pageblock; unsigned long flags; @@ -1461,6 +1470,20 @@ static int __ref __offline_pages(unsigned long start= _pfn, =20 mem_hotplug_begin(); =20 + /* + * We don't allow to offline memory blocks that contain holes + * and consecuently don't allow to online memory blocks that contain + * holes. This allows to simplify the code quite a lot and we don't + * have to mess with PG_reserved pages for memory holes. + */ + walk_system_ram_range(start_pfn, end_pfn - start_pfn, &nr_pages, + count_system_ram_pages_cb); + if (nr_pages !=3D end_pfn - start_pfn) { + ret =3D -EINVAL; + reason =3D "memory holes"; + goto failed_removal; + } + /* This makes hotplug much easier...and readable. we assume this for now. .*/ if (!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 zone =3D page_zone(pfn_to_page(valid_start)); node =3D zone_to_nid(zone); - nr_pages =3D end_pfn - start_pfn; =20 /* set above range as isolated */ ret =3D start_isolate_page_range(start_pfn, end_pfn, --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel