Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp967367imm; Wed, 23 May 2018 08:14:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpC5028Otg0iH6x5bwN6joIRnVBPKC3HGLRpDBDqqqxX4GJMiyS2+cK1fcGfPRW8ePrjfBa X-Received: by 2002:a62:5c06:: with SMTP id q6-v6mr3327311pfb.118.1527088482735; Wed, 23 May 2018 08:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527088482; cv=none; d=google.com; s=arc-20160816; b=IaIrOTGlunnbXC6xUJpztbkJmGt2i20XPJ6LQ2947Yo+5SnJXDmID/8siaq2ZYtX3g jhT8zHKANpG9xCFGN68eGRBXK4/CoT0x/xS8vn+miXzB9o6ryxbt0FeNp3Bocew429A7 hWHvTF/lFetPX5pic5FBk7vU8Zr4Q7woVwUo7txBGh9hftAt6BypFabrAl2QcaW7B11P natOFS5Qv53rXTjJspxCaCEz3G8mBN1KeAUfXK1vR36clVATeN9PjD1zSX6rpHv6HKoW 1PAATm73Ns+WduMFw2dSeoAoPwfFEhHr7fBbCTssaNDMFvkcdourXtmOKR3JVzIkPzQ7 7W3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=sbCJ2Y9pqlCgGOwt2xLKG0P6GUoHRHwHggo9UFpgOwo=; b=i+TgqK/gyfBshRZfsX/2yWVl1qGwjoGkyXkC9bouThs8cHeLy78uYfoKUz4COeMG9a 2w79ldjz0oqoDVNXUa23y576x0YYP364jxwL29UHNyILmAaGhqhEkAcLa2o+TRn/t+xp cX2zgjROMOQyivOGhUAtzlCc6hw1zvx5+A71diNH67/P7WgSMid1JelLSxNjB6eJu1IQ 9eQEcb+8tGnER7noVDF3ZtwdioMUODOMG6tiPJ18IKLmm+ARGF/d2xzksHyWgTRgj4qK K/DcanI8WAcWZ18DwpWmfpI/3ZajWhR1OTJ/4OKkTvLzUcpNYRNGBzg5+bPV9whhZenA aHqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 202-v6si19538416pfx.61.2018.05.23.08.14.27; Wed, 23 May 2018 08:14:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933619AbeEWPNo (ORCPT + 99 others); Wed, 23 May 2018 11:13:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59994 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933518AbeEWPMX (ORCPT ); Wed, 23 May 2018 11:12:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2A27818BAF8; Wed, 23 May 2018 15:12:22 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-112.ams2.redhat.com [10.36.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5238810C564A; Wed, 23 May 2018 15:12:21 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand , Andrew Morton , Michal Hocko , Vlastimil Babka , Dan Williams , Reza Arbab , Pavel Tatashin , Thomas Gleixner Subject: [PATCH v1 06/10] mm/memory_hotplug: onlining pages can only fail due to notifiers Date: Wed, 23 May 2018 17:11:47 +0200 Message-Id: <20180523151151.6730-7-david@redhat.com> In-Reply-To: <20180523151151.6730-1-david@redhat.com> References: <20180523151151.6730-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 23 May 2018 15:12:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 23 May 2018 15:12:22 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Onlining pages can only fail if a notifier reported a problem (e.g. -ENOMEM). Remove and restructure error handling. While at it, document how online_pages() can be used right now. Cc: Andrew Morton Cc: Michal Hocko Cc: Vlastimil Babka Cc: Dan Williams Cc: Reza Arbab Cc: Pavel Tatashin Cc: Thomas Gleixner Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c971295a1100..8c0b7d85252b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -902,7 +902,26 @@ static struct zone * __meminit move_pfn_range(int online_type, int nid, return zone; } -/* Must be protected by mem_hotplug_begin() or a device_lock */ +/** + * online_pages - online pages in a given range (that are currently offline) + * @start_pfn: start pfn of the memory range + * @nr_pages: the number of pages + * @online_type: how to online pages (esp. to which zone to add them) + * + * This function onlines the given pages. Usually, any alignemt / size + * can be used. However, all pages of memory to be removed later on in + * one piece via remove_memory() should be onlined the same way and at + * least the first page should be onlined if anything else is onlined. + * The zone of the first page is used to fixup zones when removing memory + * later on (see __remove_pages()). + * + * Returns 0 if sucessful, an error code if a memory notifier reported a + * problem (e.g. -ENOMEM). + * + * Bad things will happen if pages in the range are already online. + * + * Must be protected by mem_hotplug_begin() or a device_lock + */ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type) { unsigned long flags; @@ -923,8 +942,13 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ ret = memory_notify(MEM_GOING_ONLINE, &arg); ret = notifier_to_errno(ret); - if (ret) - goto failed_addition; + if (ret) { + pr_debug("online_pages [mem %#010llx-%#010llx] failed\n", + (unsigned long long) pfn << PAGE_SHIFT, + (((unsigned long long) pfn + nr_pages) << PAGE_SHIFT) - 1); + memory_notify(MEM_CANCEL_ONLINE, &arg); + return ret; + } /* * If this zone is not populated, then it is not in zonelist. @@ -936,13 +960,9 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ setup_zone_pageset(zone); } - ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages, - online_pages_range); - if (ret) { - if (need_zonelists_rebuild) - zone_pcp_reset(zone); - goto failed_addition; - } + /* onlining pages cannot fail */ + walk_system_ram_range(pfn, nr_pages, &onlined_pages, + online_pages_range); zone->present_pages += onlined_pages; @@ -972,13 +992,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ if (onlined_pages) memory_notify(MEM_ONLINE, &arg); return 0; - -failed_addition: - pr_debug("online_pages [mem %#010llx-%#010llx] failed\n", - (unsigned long long) pfn << PAGE_SHIFT, - (((unsigned long long) pfn + nr_pages) << PAGE_SHIFT) - 1); - memory_notify(MEM_CANCEL_ONLINE, &arg); - return ret; } #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ -- 2.17.0