From patchwork Tue Jan 22 10:37:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10775333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AE666C2 for ; Tue, 22 Jan 2019 10:37:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 275022A518 for ; Tue, 22 Jan 2019 10:37:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B1A02A527; Tue, 22 Jan 2019 10:37:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FCCC2A518 for ; Tue, 22 Jan 2019 10:37:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A13D18E0005; Tue, 22 Jan 2019 05:37:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A22F8E0001; Tue, 22 Jan 2019 05:37:46 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 866018E0005; Tue, 22 Jan 2019 05:37:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 285688E0001 for ; Tue, 22 Jan 2019 05:37:46 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id e29so9296773ede.19 for ; Tue, 22 Jan 2019 02:37:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=vBHlJiRDY8N9YGhkp2mdFx+Qk2/DA3qOKHFkJdj/Kws=; b=Ha/TI9JOcnJ0ue/iO1q341pKxoSzLbpYRQkyWQna9C1UvBHZTWtYmVNtkDwGEzppc/ NXRfUJ2UXjhNGnIJNvnvjRrlVpHOJrn2dW5Ko3lsNG87WB0Dq/QSwmKTgfYpH67i5FZp /tiELPU3ipM0W8+VtP9V2TW/PG6KDGbbPJV+c1L7nyXNPj556znxpmPhbPZP/gEztu7K wXP/NAoFNxgVAWiorcOeaOTDtCKDilYUZ4doiwBTMC7O4RJ4aXIGix45Q3aLow0cCy3G YYYVmcYhJ5FzuW9GxRuP1GzH81vnelvColeyUEgNSAUCWTRmoRPi4EhfynCFxMnKM4Ev 8S2w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AJcUukfXYHR2LRJN3vUxZ8EatGTDsFN6uPvQD/wkJmkwIuK+73HfmOh0 obb1vMn5If03sTfy+FAPbViN2UAmH+dzuvgSxzIWiB30Sma2P0VvAABQsaDKtcMjM/fkv9Eapbm aPAUTpyikmRvjYTUAZU8aDK5UVWtzmKqkD1S7tRURt7DxdSxR/bsDPAzGd8R6k0S1UQ== X-Received: by 2002:a50:a3d4:: with SMTP id t20mr30846470edb.159.1548153465592; Tue, 22 Jan 2019 02:37:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN7I9TNn4CRWHyVs0cOCS4Zy1DjRQ3L6NomSdNPfk/4g1q2U53tlw1rCshf8qJ24B0iyt3Wl X-Received: by 2002:a50:a3d4:: with SMTP id t20mr30846402edb.159.1548153464403; Tue, 22 Jan 2019 02:37:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548153464; cv=none; d=google.com; s=arc-20160816; b=i/Mm0jLbjOZKApZPGw/hh60U+EJQDY58Jj+7DDc/URkMKmb6BRew7fqHhbKbln2bUp 5G8Oi54ukxGsGBS6XTpvixNSID4FGpeprLmVHy1VoKeSBzX5Zj4macDy4g4o5or3vsNE 5FznAKPWwkCnHWOYRrN8rg4JzfqZddx6hKhfvU+0WHsuHVslI+Mze2oYpzFuc9xy88Np cH342Vabfn8pZMsl6I6jXNUmz3OvTOosRLzNwQqb3hHO3kRksT8hN5ZZSQDivbEi29im Qq47A4F02r7Dz2gYBEj0Hx5siLTYuM0dbMF0v/3O0VVcvnvhX9k1hXAcMc9DILjXX/dH DL6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=vBHlJiRDY8N9YGhkp2mdFx+Qk2/DA3qOKHFkJdj/Kws=; b=B5McWMYRMFe04dAeROEp/RHPzpG2/zrWt9ZbqhoVAMNGLMJcrW367PxK9tNrL1FoU6 eMpmJkwqjbTWwHm2bvY4MAHafL9VDQmCRiOn0MAzOj3ZQ5R+NhMT3gx1MZewrrnCjZX2 lsAXK850v1SSzyUAR1Li7t9q9/VhqfCUFxYQ+so7xCh0TbZCb3bkuylu8rdrmb+JbzlT f1V7YX5BsuIFvg9X+THu7YPExK1xVCzKJP86roPl15E/g4x6NHjA276Cy3ygmf3HxKI3 w1VnWZnd0ykJEAb252djV2RdaYCKwUoD7gKKrnoVheZAPKfUJSKLWx7jVF2PgA3QYHmt fL9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id f10-v6si3340651eja.11.2019.01.22.02.37.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 02:37:44 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 22 Jan 2019 11:37:43 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 22 Jan 2019 10:37:18 +0000 From: Oscar Salvador To: linux-mm@kvack.org Cc: mhocko@suse.com, dan.j.williams@intel.com, Pavel.Tatashin@microsoft.com, david@redhat.com, linux-kernel@vger.kernel.org, dave.hansen@intel.com, Oscar Salvador Subject: [RFC PATCH v2 1/4] mm, memory_hotplug: cleanup memory offline path Date: Tue, 22 Jan 2019 11:37:05 +0100 Message-Id: <20190122103708.11043-2-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20190122103708.11043-1-osalvador@suse.de> References: <20190122103708.11043-1-osalvador@suse.de> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko check_pages_isolated_cb currently accounts the whole pfn range as being offlined if test_pages_isolated suceeds on the range. This is based on the assumption that all pages in the range are freed which is currently the case in most cases but it won't be with later changes. I haven't double checked but if the range contains invalid pfns we could theoretically over account and underflow zone's managed pages. Move the offlined pages counting to offline_isolated_pages_cb and rely on __offline_isolated_pages to return the correct value. check_pages_isolated_cb will still do it's primary job and check the pfn range. While we are at it remove check_pages_isolated and offline_isolated_pages and use directly walk_system_ram_range as do in online_pages. Signed-off-by: Michal Hocko Signed-off-by: Oscar Salvador --- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 45 +++++++++++------------------------------- mm/page_alloc.c | 11 +++++++++-- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index d56bfbacf7d6..1a230dde6027 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -85,7 +85,7 @@ extern int add_one_highpage(struct page *page, int pfn, int bad_ppro); extern int online_pages(unsigned long, unsigned long, int); extern int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn, unsigned long *valid_start, unsigned long *valid_end); -extern void __offline_isolated_pages(unsigned long, unsigned long); +extern unsigned long __offline_isolated_pages(unsigned long, unsigned long); typedef int (*online_page_callback_t)(struct page *page, unsigned int order); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ec22c86d9f89..6efa44087b37 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1451,17 +1451,12 @@ static int offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages, void *data) { - __offline_isolated_pages(start, start + nr_pages); + unsigned long offlined_pages; + offlined_pages = __offline_isolated_pages(start, start + nr_pages); + *(unsigned long *)data += offlined_pages; return 0; } -static void -offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) -{ - walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL, - offline_isolated_pages_cb); -} - /* * Check all pages in range, recoreded as memory resource, are isolated. */ @@ -1469,26 +1464,7 @@ static int check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages, void *data) { - int ret; - long offlined = *(long *)data; - ret = test_pages_isolated(start_pfn, start_pfn + nr_pages, true); - offlined = nr_pages; - if (!ret) - *(long *)data += offlined; - return ret; -} - -static long -check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn) -{ - long offlined = 0; - int ret; - - ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined, - check_pages_isolated_cb); - if (ret < 0) - offlined = (long)ret; - return offlined; + return test_pages_isolated(start_pfn, start_pfn + nr_pages, true); } static int __init cmdline_parse_movable_node(char *p) @@ -1573,7 +1549,7 @@ static int __ref __offline_pages(unsigned long start_pfn, unsigned long end_pfn) { unsigned long pfn, nr_pages; - long offlined_pages; + unsigned long offlined_pages = 0; int ret, node; unsigned long flags; unsigned long valid_start, valid_end; @@ -1650,13 +1626,16 @@ static int __ref __offline_pages(unsigned long start_pfn, goto failed_removal_isolated; } /* check again */ - offlined_pages = check_pages_isolated(start_pfn, end_pfn); - } while (offlined_pages < 0); + ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL, + check_pages_isolated_cb); + } while (ret); - pr_info("Offlined Pages %ld\n", offlined_pages); /* Ok, all of our target is isolated. We cannot do rollback at this point. */ - offline_isolated_pages(start_pfn, end_pfn); + walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined_pages, + offline_isolated_pages_cb); + + pr_info("Offlined Pages %ld\n", offlined_pages); /* reset pagetype flags and makes migrate type to be MOVABLE */ undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); /* removal success */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d7a521971a05..cad7468a0f20 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8479,7 +8479,7 @@ void zone_pcp_reset(struct zone *zone) * All pages in the range must be in a single zone and isolated * before calling this. */ -void +unsigned long __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) { struct page *page; @@ -8487,12 +8487,15 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) unsigned int order, i; unsigned long pfn; unsigned long flags; + unsigned long offlined_pages = 0; + /* find the first valid pfn */ for (pfn = start_pfn; pfn < end_pfn; pfn++) if (pfn_valid(pfn)) break; if (pfn == end_pfn) - return; + return offlined_pages; + offline_mem_sections(pfn, end_pfn); zone = page_zone(pfn_to_page(pfn)); spin_lock_irqsave(&zone->lock, flags); @@ -8510,12 +8513,14 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) if (unlikely(!PageBuddy(page) && PageHWPoison(page))) { pfn++; SetPageReserved(page); + offlined_pages++; continue; } BUG_ON(page_count(page)); BUG_ON(!PageBuddy(page)); order = page_order(page); + offlined_pages += 1 << order; #ifdef CONFIG_DEBUG_VM pr_info("remove from free list %lx %d %lx\n", pfn, 1 << order, end_pfn); @@ -8528,6 +8533,8 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) pfn += (1 << order); } spin_unlock_irqrestore(&zone->lock, flags); + + return offlined_pages; } #endif