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.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 090ECCA9EAF for ; Thu, 24 Oct 2019 19:44:54 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A922B21655 for ; Thu, 24 Oct 2019 19:44:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fA35Lm0/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A922B21655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46zd4M3v6QzDqHJ for ; Fri, 25 Oct 2019 06:44:51 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=205.139.110.120; helo=us-smtp-1.mimecast.com; envelope-from=david@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="fA35Lm0/"; dkim-atps=neutral Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46zR0D6JFFzDqTq for ; Thu, 24 Oct 2019 23:10:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571919034; 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=ci8rTmGAQWvcufbTawC9IhJzwFepcNIlGotHVYhTC24=; b=fA35Lm0/4rM/DhyvYKjMnPhH55wQsNmhGbLvVb0qOLKPQw18ljSS1iirjVBN/wxmH+Aqxd fnfIFsiaTedNXl9CtUswpGbJ7MuVSSzTWDTS8eoFXrLpyyxD7LxbRPFokiqIPCPmTLwcOG U5DCep5yfeeT2q4kG7Q6vZa7RpD0A8c= 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-190-OyS-w0OOPfCXkYu6xkkqOg-1; Thu, 24 Oct 2019 08:10:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17898800D49; Thu, 24 Oct 2019 12:10:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-141.ams2.redhat.com [10.36.116.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9159B52D1; Thu, 24 Oct 2019 12:10:01 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Subject: [PATCH v1 01/10] mm/memory_hotplug: Don't allow to online/offline memory blocks with holes Date: Thu, 24 Oct 2019 14:09:29 +0200 Message-Id: <20191024120938.11237-2-david@redhat.com> In-Reply-To: <20191024120938.11237-1-david@redhat.com> References: <20191024120938.11237-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: OyS-w0OOPfCXkYu6xkkqOg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Fri, 25 Oct 2019 06:41:16 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 , Dave Hansen , Alexander Duyck , Michal Hocko , linux-mm@kvack.org, Pavel Tatashin , Paul Mackerras , "H. Peter Anvin" , Wanpeng Li , Alexander Duyck , "K. Y. Srinivasan" , Dan Williams , Kees Cook , devel@driverdev.osuosl.org, Stefano Stabellini , Stephen Hemminger , "Aneesh Kumar K.V" , Joerg Roedel , x86@kernel.org, YueHaibing , "Matthew Wilcox \(Oracle\)" , Mike Rapoport , Peter Zijlstra , Ingo Molnar , Vlastimil Babka , Anthony Yznaga , Oscar Salvador , "Isaac J. Manjarres" , Matt Sickler , Juergen Gross , Anshuman Khandual , Haiyang Zhang , Sasha Levin , kvm-ppc@vger.kernel.org, Qian Cai , Alex Williamson , Mike Rapoport , Borislav Petkov , Nicholas Piggin , Andy Lutomirski , xen-devel@lists.xenproject.org, Boris Ostrovsky , Vitaly Kuznetsov , Allison Randal , Jim Mattson , Mel Gorman , Cornelia Huck , Pavel Tatashin , Sean Christopherson , Thomas Gleixner , Johannes Weiner , Paolo Bonzini , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Our onlining/offlining code is unnecessarily complicated. Only memory blocks added during boot can have holes (a range that is not IORESOURCE_SYSTEM_RAM). Hotplugged memory never has holes (e.g., see add_memory_resource()). All boot memory is alread online. Therefore, when we stop allowing to offline memory blocks with holes, we implicitly no longer have to deal with onlining 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 (unmovable data might have easily ended up on that memory during boot). So stopping to do that should not really hurt (+ people are not even aware of a setup where that used to work and that the existing code still works correctly with memory holes). For the use case of offlining memory to unplug DIMMs, we should see no change. (holes on DIMMs would be weird). Please note that hardware errors (PG_hwpoison) are not memory holes and not affected by this change when offlining. Cc: Andrew Morton Cc: Michal Hocko Cc: Oscar Salvador Cc: Pavel Tatashin Cc: Dan Williams Cc: Anshuman Khandual 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..8d81730cf036 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 * Don't allow to offline memory blocks that contain holes. +=09 * Consecuently, memory blocks with holes can never get onlined +=09 * (hotplugged memory has no holes and all boot memory is online). +=09 * This allows to simplify the onlining/offlining code quite a lot. +=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 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.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 3AAFDCA9EAF for ; Thu, 24 Oct 2019 12:10:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 09C8320856 for ; Thu, 24 Oct 2019 12:10:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZsNhtg6+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09C8320856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNbwp-0004n4-Bu; Thu, 24 Oct 2019 12:10:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNbwo-0004mx-F7 for xen-devel@lists.xenproject.org; Thu, 24 Oct 2019 12:10:34 +0000 X-Inumbo-ID: 47189400-f657-11e9-a531-bc764e2007e4 Received: from us-smtp-delivery-1.mimecast.com (unknown [205.139.110.61]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 47189400-f657-11e9-a531-bc764e2007e4; Thu, 24 Oct 2019 12:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571919032; 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=ci8rTmGAQWvcufbTawC9IhJzwFepcNIlGotHVYhTC24=; b=ZsNhtg6+dHzPcwSVwjXIgwuRpJm6zYtwBax/d+6eoWSCur2yTWxbtJPLhhHmNn8DDxOdG/ FCV9fGARW7QmrSToNDPYny63UzkQ58We2FTFTsqO8pkYNPZaLTHaQ14kBMl/z67w471myj TbflBaG/0ZYtQfEUDZQeeIqqCd8W/nM= 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-190-OyS-w0OOPfCXkYu6xkkqOg-1; Thu, 24 Oct 2019 08:10:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17898800D49; Thu, 24 Oct 2019 12:10:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-141.ams2.redhat.com [10.36.116.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9159B52D1; Thu, 24 Oct 2019 12:10:01 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Date: Thu, 24 Oct 2019 14:09:29 +0200 Message-Id: <20191024120938.11237-2-david@redhat.com> In-Reply-To: <20191024120938.11237-1-david@redhat.com> References: <20191024120938.11237-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: OyS-w0OOPfCXkYu6xkkqOg-1 X-Mimecast-Spam-Score: 0 Subject: [Xen-devel] [PATCH v1 01/10] 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: 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" , Dan Williams , Kees Cook , devel@driverdev.osuosl.org, Stefano Stabellini , Stephen Hemminger , "Aneesh Kumar K.V" , Joerg Roedel , x86@kernel.org, YueHaibing , "Matthew Wilcox \(Oracle\)" , Mike Rapoport , Peter Zijlstra , Ingo Molnar , Vlastimil Babka , Anthony Yznaga , Oscar Salvador , "Isaac J. Manjarres" , Matt Sickler , Juergen Gross , Anshuman Khandual , Haiyang Zhang , Sasha Levin , kvm-ppc@vger.kernel.org, Qian Cai , Alex Williamson , Mike Rapoport , Borislav Petkov , Nicholas Piggin , Andy Lutomirski , xen-devel@lists.xenproject.org, Boris Ostrovsky , Vitaly Kuznetsov , Allison Randal , Jim Mattson , Christophe Leroy , Mel Gorman , Cornelia Huck , Pavel Tatashin , Sean Christopherson , Thomas Gleixner , Johannes Weiner , Paolo Bonzini , Andrew Morton , linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" T3VyIG9ubGluaW5nL29mZmxpbmluZyBjb2RlIGlzIHVubmVjZXNzYXJpbHkgY29tcGxpY2F0ZWQu IE9ubHkgbWVtb3J5CmJsb2NrcyBhZGRlZCBkdXJpbmcgYm9vdCBjYW4gaGF2ZSBob2xlcyAoYSBy YW5nZSB0aGF0IGlzIG5vdApJT1JFU09VUkNFX1NZU1RFTV9SQU0pLiBIb3RwbHVnZ2VkIG1lbW9y eSBuZXZlciBoYXMgaG9sZXMgKGUuZy4sIHNlZQphZGRfbWVtb3J5X3Jlc291cmNlKCkpLiBBbGwg Ym9vdCBtZW1vcnkgaXMgYWxyZWFkIG9ubGluZS4KClRoZXJlZm9yZSwgd2hlbiB3ZSBzdG9wIGFs bG93aW5nIHRvIG9mZmxpbmUgbWVtb3J5IGJsb2NrcyB3aXRoIGhvbGVzLCB3ZQppbXBsaWNpdGx5 IG5vIGxvbmdlciBoYXZlIHRvIGRlYWwgd2l0aCBvbmxpbmluZyBtZW1vcnkgYmxvY2tzIHdpdGgg aG9sZXMuCgpUaGlzIGFsbG93cyB0byBzaW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orCQkJICAgICAgY291bnRfc3lzdGVtX3JhbV9wYWdlc19jYik7CisJaWYgKG5yX3BhZ2VzICE9 IGVuZF9wZm4gLSBzdGFydF9wZm4pIHsKKwkJcmV0ID0gLUVJTlZBTDsKKwkJcmVhc29uID0gIm1l bW9yeSBob2xlcyI7CisJCWdvdG8gZmFpbGVkX3JlbW92YWw7CisJfQorCiAJLyogVGhpcyBtYWtl cyBob3RwbHVnIG11Y2ggZWFzaWVyLi4uYW5kIHJlYWRhYmxlLgogCSAgIHdlIGFzc3VtZSB0aGlz IGZvciBub3cuIC4qLwogCWlmICghdGVzdF9wYWdlc19pbl9hX3pvbmUoc3RhcnRfcGZuLCBlbmRf cGZuLCAmdmFsaWRfc3RhcnQsCkBAIC0xNDcyLDcgKzE0OTUsNiBAQCBzdGF0aWMgaW50IF9fcmVm IF9fb2ZmbGluZV9wYWdlcyh1bnNpZ25lZCBsb25nIHN0YXJ0X3BmbiwKIAogCXpvbmUgPSBwYWdl X3pvbmUocGZuX3RvX3BhZ2UodmFsaWRfc3RhcnQpKTsKIAlub2RlID0gem9uZV90b19uaWQoem9u ZSk7Ci0JbnJfcGFnZXMgPSBlbmRfcGZuIC0gc3RhcnRfcGZuOwogCiAJLyogc2V0IGFib3ZlIHJh bmdlIGFzIGlzb2xhdGVkICovCiAJcmV0ID0gc3RhcnRfaXNvbGF0ZV9wYWdlX3JhbmdlKHN0YXJ0 X3BmbiwgZW5kX3BmbiwKLS0gCjIuMjEuMAoKCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fClhlbi1kZXZlbCBtYWlsaW5nIGxpc3QKWGVuLWRldmVsQGxpc3Rz LnhlbnByb2plY3Qub3JnCmh0dHBzOi8vbGlzdHMueGVucHJvamVjdC5vcmcvbWFpbG1hbi9saXN0 aW5mby94ZW4tZGV2ZWw= 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 A461DCA9EAF for ; Thu, 24 Oct 2019 12:10:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 451BC20856 for ; Thu, 24 Oct 2019 12:10:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b+EbEB1H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 451BC20856 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 B15F56B0005; Thu, 24 Oct 2019 08:10:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC5F76B0006; Thu, 24 Oct 2019 08:10:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98F046B0007; Thu, 24 Oct 2019 08:10:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 796046B0005 for ; Thu, 24 Oct 2019 08:10:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 096F35DE6 for ; Thu, 24 Oct 2019 12:10:35 +0000 (UTC) X-FDA: 76078561230.18.mask99_50104b8ef34e X-HE-Tag: mask99_50104b8ef34e X-Filterd-Recvd-Size: 8235 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 12:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571919033; 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=ci8rTmGAQWvcufbTawC9IhJzwFepcNIlGotHVYhTC24=; b=b+EbEB1H8i/ejT2M75aHaGw2j0rJ0ABfhJFoTuhTD+7B/St95Gi/87TlFsoarrjYBvyTgO BM1VfcmXnQPR6ji6iMDeACQ/PUNwj6SDMntFSdoCt5XtWKSs8klFMA2Vw3dTRAPg0ltvC2 1XIDQ5Fhg/zW2DqVsdRujPC63NDH6CM= 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-190-OyS-w0OOPfCXkYu6xkkqOg-1; Thu, 24 Oct 2019 08:10:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17898800D49; Thu, 24 Oct 2019 12:10:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-141.ams2.redhat.com [10.36.116.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9159B52D1; Thu, 24 Oct 2019 12:10:01 +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 , Benjamin Herrenschmidt , Borislav Petkov , Boris Ostrovsky , Christophe Leroy , Cornelia Huck , Dan Williams , Dave Hansen , Haiyang Zhang , "H. Peter Anvin" , Ingo Molnar , "Isaac J. Manjarres" , Jim Mattson , Joerg Roedel , Johannes Weiner , Juergen Gross , KarimAllah Ahmed , Kees Cook , "K. Y. Srinivasan" , "Matthew Wilcox (Oracle)" , Matt Sickler , Mel Gorman , Michael Ellerman , Michal Hocko , Mike Rapoport , Mike Rapoport , Nicholas Piggin , 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?= , Sasha Levin , Sean Christopherson , Stefano Stabellini , Stephen Hemminger , Thomas Gleixner , Vitaly Kuznetsov , Vlastimil Babka , Wanpeng Li , YueHaibing Subject: [PATCH v1 01/10] mm/memory_hotplug: Don't allow to online/offline memory blocks with holes Date: Thu, 24 Oct 2019 14:09:29 +0200 Message-Id: <20191024120938.11237-2-david@redhat.com> In-Reply-To: <20191024120938.11237-1-david@redhat.com> References: <20191024120938.11237-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: OyS-w0OOPfCXkYu6xkkqOg-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 (a range that is not IORESOURCE_SYSTEM_RAM). Hotplugged memory never has holes (e.g., see add_memory_resource()). All boot memory is alread online. Therefore, when we stop allowing to offline memory blocks with holes, we implicitly no longer have to deal with onlining 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 (unmovable data might have easily ended up on that memory during boot). So stopping to do that should not really hurt (+ people are not even aware of a setup where that used to work and that the existing code still works correctly with memory holes). For the use case of offlining memory to unplug DIMMs, we should see no change. (holes on DIMMs would be weird). Please note that hardware errors (PG_hwpoison) are not memory holes and not affected by this change when offlining. Cc: Andrew Morton Cc: Michal Hocko Cc: Oscar Salvador Cc: Pavel Tatashin Cc: Dan Williams Cc: Anshuman Khandual 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..8d81730cf036 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 * Don't allow to offline memory blocks that contain holes. +=09 * Consecuently, memory blocks with holes can never get onlined +=09 * (hotplugged memory has no holes and all boot memory is online). +=09 * This allows to simplify the onlining/offlining code quite a lot. +=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