From patchwork Fri Nov 16 10:12:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10685837 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 128F514BD for ; Fri, 16 Nov 2018 10:13:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F28972CDA3 for ; Fri, 16 Nov 2018 10:13:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5C812CDA9; Fri, 16 Nov 2018 10:13:15 +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 4B0392CDA3 for ; Fri, 16 Nov 2018 10:13:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EA3D6B08EC; Fri, 16 Nov 2018 05:13:13 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 99ED56B08ED; Fri, 16 Nov 2018 05:13:13 -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 88D696B08EE; Fri, 16 Nov 2018 05:13:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 475A56B08EC for ; Fri, 16 Nov 2018 05:13:13 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id m1-v6so16591728plb.13 for ; Fri, 16 Nov 2018 02:13:13 -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=ztfFhJ4CoNc6R6R9Q/LETEEhgVHfk7yPaMYc3owaP6o=; b=T50jTD3BG6GJIKPb5GzQ+0B6T+jtLXEqrMXBUucfT2XVigwGNvvlyx8VmZcsu63m2R SZiOqdzO6pBXgi8vmym09EUQ4IO45DOeV+6HLye9AR8dyRWfdsTFqREbuZdHJ0vf0KDS NQAnA+vPIRd/KqjC3iyJz0Lw3YpPoAajS4Snb/Es4it4A29PifHuV6SlN/a1EbXAQnRd o4IWmbUKKhNBzClyMwlZDEFVve8pMuUP7rP9ZV5LC1lhtohk8QStv2cTciLTxCx/QSBv VYyri15Ct0R0xSMOglpI+46jDGpRjKWzrOzCrqrswPxfDr8CNrJRn/jPbmMHR9y7688a ihMw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com X-Gm-Message-State: AGRZ1gJm6DmjYENqrCNvYOHyu7ft5uU2/LIYTvYT8pXemc1kirpZTcep fHgTCzl1YmdlAJEDtqhygzhNl8kYXJbrqbOwCCAUfN7H1DQpYr6fVDZ8IFbRVpVokZkuqbSNz/K q5HchtBr6GRiP1xKCoo+kiiyBIZwJXH2FaftPRAPaxjJ7dxZEvrkebTBNWx3+laH2Rg== X-Received: by 2002:a65:66ce:: with SMTP id c14mr9272185pgw.450.1542363192943; Fri, 16 Nov 2018 02:13:12 -0800 (PST) X-Google-Smtp-Source: AJdET5f97oNrO+Ir/U6nO/W/IcnV99T68Q/IYgNk0H470l8WfpllT0omzx64u7BeKPGyhgplCLT5 X-Received: by 2002:a65:66ce:: with SMTP id c14mr9272112pgw.450.1542363191257; Fri, 16 Nov 2018 02:13:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542363191; cv=none; d=google.com; s=arc-20160816; b=Qy+kDyDN/H7fhwGAl6VGI4KKFxR7z2zCFB9X/QNLIz5Dn+bfP6dBWTzWdW7fIr68DP Mf8Gb02kxi9WMzkQDHcr3nBsg7y2E7r6aComxBV0QI2h+W6uCcsZreo4NaWzENLG//Hk O3Ko5MTu+E9isMeJB64Szcyr/rHgvjPJF1ySwRrPwq0cDbiDF90Znq2niRQVh3zIgZPi AGSJY0n3W8Q3gU6mJhwC6eNpofKWjHgwcTu3v7iztAQXJbWydBW7KsTnlDI/lZ5QYQXM ZmAMZ3KbWitFRhlwHvvQPEEM9wP6MSXx5HhThmF/w3E+CLhlogPPfl/inm3tybjMg/dy TlDw== 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=ztfFhJ4CoNc6R6R9Q/LETEEhgVHfk7yPaMYc3owaP6o=; b=lj1HSlr/nAQho1CP8OWHpeqAyClLc3GWg42sZvmZQhJnS28fVKg23XF2Q/YXMYWgfE yC24keP2vpzkTElkRK6xhOTB3k+bYkO4E5fSaXzm6o20s+au8xtPBHvxO+RhvSkvufxj nzo5JDPoQG8lMpSUq4JXZ/vy1YFhpYSgc6pp1yi/rBItCj91D2abYbYNVuGY2R57FGfb ASQhvY5l7cNAG27lzZ4U/8Q1qNAjwX4XShhMDeZPDcfAlA9b0TVIkIlmNcPQSpaKEslW b6jbpR2qLHVQB3FzYne7dXeQz2KLpjkaCKye3cSc7U4ah1iGFG4RJrfyAllWbNmDKhwp EudQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id 37si29215850pgs.447.2018.11.16.02.13.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 02:13:11 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.com 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.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 16 Nov 2018 11:13:09 +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); Fri, 16 Nov 2018 10:12:50 +0000 From: Oscar Salvador To: linux-mm@kvack.org Cc: mhocko@suse.com, david@redhat.com, rppt@linux.vnet.ibm.com, akpm@linux-foundation.org, arunks@codeaurora.org, bhe@redhat.com, dan.j.williams@intel.com, Pavel.Tatashin@microsoft.com, Jonathan.Cameron@huawei.com, jglisse@redhat.com, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 1/4] mm, memory_hotplug: cleanup memory offline path Date: Fri, 16 Nov 2018 11:12:19 +0100 Message-Id: <20181116101222.16581-2-osalvador@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181116101222.16581-1-osalvador@suse.com> References: <20181116101222.16581-1-osalvador@suse.com> 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 | 44 +++++++++++------------------------------- mm/page_alloc.c | 11 +++++++++-- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 84e9ae205930..1cb7054cdc03 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 dbbb94547ad0..d19e5f33e33b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1442,17 +1442,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. */ @@ -1460,26 +1455,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) @@ -1564,7 +1540,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; @@ -1633,13 +1609,15 @@ static int __ref __offline_pages(unsigned long start_pfn, if (ret) goto failed_removal; /* check again */ - offlined_pages = check_pages_isolated(start_pfn, end_pfn); - if (offlined_pages < 0) + if (walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL, + check_pages_isolated_cb)) { goto repeat; - 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 ae31839874b8..3d417c724551 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8111,7 +8111,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; @@ -8119,12 +8119,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); @@ -8142,12 +8145,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); @@ -8160,6 +8165,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 From patchwork Fri Nov 16 10:12:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10685839 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 C6ADA14E2 for ; Fri, 16 Nov 2018 10:13:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B52162CDA3 for ; Fri, 16 Nov 2018 10:13:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A91E12CDA9; Fri, 16 Nov 2018 10:13:18 +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 AEE4C2CDA3 for ; Fri, 16 Nov 2018 10:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35CE06B08ED; Fri, 16 Nov 2018 05:13:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 30CE36B08EE; Fri, 16 Nov 2018 05:13:15 -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 1B0F66B08EF; Fri, 16 Nov 2018 05:13:15 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id C7F3F6B08ED for ; Fri, 16 Nov 2018 05:13:14 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id e97-v6so16619616plb.10 for ; Fri, 16 Nov 2018 02:13:14 -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=j/iD4L4/NyWvDvTnmOPO+Xpu7UTUniMCP+wcgznEXd4=; b=i3Yu8LdZfj6qqiRj59fZR3bGVPhy2nkHJvct5kUMV8oider1AgFVq4EZJbOAHiXq2c v1xGAUVEs8Dmc4vgw2nqwOKJ6wIYGqPN4xEpboRUeA8VKEpfSn5clb4WlV9NTFwrMBe+ c0aj92Z9yIjxy0Z2/nd9VsVeW6XgHMR5vTpOlQEx6Mat6Hym9pESzCRZ+6SNSbAmlQ27 gKdsioeH8/7RRwcGtGm9fkX0UY5P39cxa02SfyZUnuid2LEUmduTw6sXoIPLz+e3pDsN Exr+txG62EUMZhlUN6sro+cs5SXtg5Q2bFm4RdJCOdJyqgp53XYX5bEmADXDamKUoThv cG1A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com X-Gm-Message-State: AGRZ1gJOglooKkiUE3+ZKKjKbHnEscJP00Lx8Ey6vxtA3OcPC0efCTm3 yhqLYRsjHD2QAVHC/4K+0DPkx4axRQGIWhuAyQrstoYVWIRIOc7V3w5Xm8jevVihAuVKqrnvGKR Sj17eiyXla1zcAEHvML8sfLzQZ7LzbPwpDWstBhQoG4OsCtqLN3DwoqM7CObqSG13cg== X-Received: by 2002:a62:1709:: with SMTP id 9mr10257876pfx.249.1542363194437; Fri, 16 Nov 2018 02:13:14 -0800 (PST) X-Google-Smtp-Source: AJdET5fOougjTodNXIeCIkIjw+ew6XJQjjrpRvcdSWpsiEAoLF15DeTW21wgWtSDOykEm2k1M1dq X-Received: by 2002:a62:1709:: with SMTP id 9mr10257820pfx.249.1542363193309; Fri, 16 Nov 2018 02:13:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542363193; cv=none; d=google.com; s=arc-20160816; b=PNsFBnIE3bHzpmQMPeQKmyiBjbT/0aLv1Oc+iOnSAttsA7enkSO864h8eVZZa/HrOK HwMEHAU6hTCBXVRiBlwDZVlTQG3cWWi6q4M1xi4baqDyxd0sJ9hDTmWu3EqSYwobG3S/ LOxJ2HlI6YhEiIi2t/pnDVpFw+71geYgNUYNaiW7U+ZHuwKikObh035if6Yiw7k7yYQV rft47+2Q/Xwgm8XuTPGEo0hE1YTOt8DITPJGFDjv6DQrlNsPtyNSBRgocmDL0Qdo7sNH OcIyui08BvofDrwqyZp/hZNa5h5TRcz5z3TFyIfCClGtLkmUN2TLU2rtZz2NlxyPci/r yteg== 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=j/iD4L4/NyWvDvTnmOPO+Xpu7UTUniMCP+wcgznEXd4=; b=owthiSZUf0TzKwH4j6ZtX4AnOKhqXVU5+unmXG/aOBZZEm2Uq7lhaQcpHN6pFQJZ60 e0LKtYzNLoXm7Ho+IOFge+t0WdxXu5NkGA9TariAy8aMWTPDafu2g0VisC0Eb1JvAXsk nFOzVrYB7wby1M0Y0QISiMyQLA9Yp8rxeXofFPDROrOdmlRtUDFTxo6oVCqv08MCpyeR VevGi1JkU5Qu7Kwe8Nr1D0Q+H1OCsIcMNz6IltcHLj9GwHMGbyUc4gPr8Roxh6LvNuhk wJfTrGIWpAi2teHCKbOEnW4i10xXhWGeiA4zPvLoxvyXqEWCX5fg/YSlYJ2m7+crml8g nvbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id s36-v6si32469860pld.387.2018.11.16.02.13.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 02:13:13 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.com 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.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 16 Nov 2018 11:13:10 +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); Fri, 16 Nov 2018 10:12:51 +0000 From: Oscar Salvador To: linux-mm@kvack.org Cc: mhocko@suse.com, david@redhat.com, rppt@linux.vnet.ibm.com, akpm@linux-foundation.org, arunks@codeaurora.org, bhe@redhat.com, dan.j.williams@intel.com, Pavel.Tatashin@microsoft.com, Jonathan.Cameron@huawei.com, jglisse@redhat.com, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 2/4] mm, memory_hotplug: provide a more generic restrictions for memory hotplug Date: Fri, 16 Nov 2018 11:12:20 +0100 Message-Id: <20181116101222.16581-3-osalvador@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181116101222.16581-1-osalvador@suse.com> References: <20181116101222.16581-1-osalvador@suse.com> 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 arch_add_memory, __add_pages take a want_memblock which controls whether the newly added memory should get the sysfs memblock user API (e.g. ZONE_DEVICE users do not want/need this interface). Some callers even want to control where do we allocate the memmap from by configuring altmap. This is currently done quite ugly by searching for altmap down in memory hotplug (to_vmem_altmap). It should be the caller to provide the altmap down the call chain. Add a more generic hotplug context for arch_add_memory and __add_pages. struct mhp_restrictions contains flags which contains additional features to be enabled by the memory hotplug (MHP_MEMBLOCK_API currently) and altmap for alternative memmap allocator. Please note that the complete altmap propagation down to vmemmap code is still not done in this patch. It will be done in the follow up to reduce the churn here. This patch shouldn't introduce any functional change. Signed-off-by: Michal Hocko Signed-off-by: Oscar Salvador --- arch/ia64/mm/init.c | 5 ++--- arch/powerpc/mm/mem.c | 6 +++--- arch/s390/mm/init.c | 6 +++--- arch/sh/mm/init.c | 6 +++--- arch/x86/mm/init_32.c | 6 +++--- arch/x86/mm/init_64.c | 10 +++++----- include/linux/memory_hotplug.h | 27 ++++++++++++++++++++------- kernel/memremap.c | 6 +++++- mm/memory_hotplug.c | 10 ++++++---- 9 files changed, 50 insertions(+), 32 deletions(-) diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index d5e12ff1d73c..c0c6da053db8 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c @@ -645,14 +645,13 @@ mem_init (void) } #ifdef CONFIG_MEMORY_HOTPLUG -int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int arch_add_memory(int nid, u64 start, u64 size, struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; int ret; - ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + ret = __add_pages(nid, start_pfn, nr_pages, restrictions); if (ret) printk("%s: Problem encountered in __add_pages() as ret=%d\n", __func__, ret); diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 0a64fffabee1..2535471daad7 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -117,8 +117,8 @@ int __weak remove_section_mapping(unsigned long start, unsigned long end) return -ENODEV; } -int __meminit arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int __meminit arch_add_memory(int nid, u64 start, u64 size, + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; @@ -135,7 +135,7 @@ int __meminit arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap * } flush_inval_dcache_range(start, start + size); - return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + return __add_pages(nid, start_pfn, nr_pages, restrictions); } #ifdef CONFIG_MEMORY_HOTREMOVE diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 76d0708438e9..4139affd6157 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -224,8 +224,8 @@ device_initcall(s390_cma_mem_init); #endif /* CONFIG_CMA */ -int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int arch_add_memory(int nid, u64 start, u64 size, + struct mhp_restrictions *restrictions) { unsigned long start_pfn = PFN_DOWN(start); unsigned long size_pages = PFN_DOWN(size); @@ -235,7 +235,7 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, if (rc) return rc; - rc = __add_pages(nid, start_pfn, size_pages, altmap, want_memblock); + rc = __add_pages(nid, start_pfn, size_pages, restrictions); if (rc) vmem_remove_mapping(start, size); return rc; diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c index c8c13c777162..f0b489d6f73b 100644 --- a/arch/sh/mm/init.c +++ b/arch/sh/mm/init.c @@ -418,15 +418,15 @@ void free_initrd_mem(unsigned long start, unsigned long end) #endif #ifdef CONFIG_MEMORY_HOTPLUG -int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int arch_add_memory(int nid, u64 start, u64 size, + struct mhp_restrictions *restrictions) { unsigned long start_pfn = PFN_DOWN(start); unsigned long nr_pages = size >> PAGE_SHIFT; int ret; /* We only have ZONE_NORMAL, so this is easy.. */ - ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + ret = __add_pages(nid, start_pfn, nr_pages, restrictions); if (unlikely(ret)) printk("%s: Failed, __add_pages() == %d\n", __func__, ret); diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c index 49ecf5ecf6d3..c47b33019dbc 100644 --- a/arch/x86/mm/init_32.c +++ b/arch/x86/mm/init_32.c @@ -850,13 +850,13 @@ void __init mem_init(void) } #ifdef CONFIG_MEMORY_HOTPLUG -int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int arch_add_memory(int nid, u64 start, u64 size, + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; - return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + return __add_pages(nid, start_pfn, nr_pages, restrictions); } #ifdef CONFIG_MEMORY_HOTREMOVE diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 5fab264948c2..fd06bcbd9535 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -783,11 +783,11 @@ static void update_end_of_memory_vars(u64 start, u64 size) } int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, - struct vmem_altmap *altmap, bool want_memblock) + struct mhp_restrictions *restrictions) { int ret; - ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + ret = __add_pages(nid, start_pfn, nr_pages, restrictions); WARN_ON_ONCE(ret); /* update max_pfn, max_low_pfn and high_memory */ @@ -797,15 +797,15 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, return ret; } -int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, - bool want_memblock) +int arch_add_memory(int nid, u64 start, u64 size, + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; init_memory_mapping(start, start + size); - return add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + return add_pages(nid, start_pfn, nr_pages, restrictions); } #define PAGE_INUSE 0xFD diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 1cb7054cdc03..7249dab00ac9 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -96,7 +96,7 @@ extern void __online_page_set_limits(struct page *page); extern void __online_page_increment_counters(struct page *page); extern void __online_page_free(struct page *page); -extern int try_online_node(int nid); + extern int try_online_node(int nid); extern bool memhp_auto_online; /* If movable_node boot option specified */ @@ -113,20 +113,33 @@ extern int __remove_pages(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap); #endif /* CONFIG_MEMORY_HOTREMOVE */ +/* + * Do we want sysfs memblock files created. This will allow userspace to online + * and offline memory explicitly. Lack of this bit means that the caller has to + * call move_pfn_range_to_zone to finish the initialization. + */ + +#define MHP_MEMBLOCK_API 1<<0 + +/* Restrictions for the memory hotplug */ +struct mhp_restrictions { + unsigned long flags; /* MHP_ flags */ + struct vmem_altmap *altmap; /* use this alternative allocatro for memmaps */ +}; + /* reasonably generic interface to expand the physical pages */ extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, - struct vmem_altmap *altmap, bool want_memblock); + struct mhp_restrictions *restrictions); #ifndef CONFIG_ARCH_HAS_ADD_PAGES static inline int add_pages(int nid, unsigned long start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap, - bool want_memblock) + unsigned long nr_pages, struct mhp_restrictions *restrictions) { - return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); + return __add_pages(nid, start_pfn, nr_pages, restrictions); } #else /* ARCH_HAS_ADD_PAGES */ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, - struct vmem_altmap *altmap, bool want_memblock); + struct mhp_restrictions *restrictions); #endif /* ARCH_HAS_ADD_PAGES */ #ifdef CONFIG_NUMA @@ -328,7 +341,7 @@ extern int __add_memory(int nid, u64 start, u64 size); extern int add_memory(int nid, u64 start, u64 size); extern int add_memory_resource(int nid, struct resource *resource, bool online); extern int arch_add_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap, bool want_memblock); + struct mhp_restrictions *restrictions); extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/kernel/memremap.c b/kernel/memremap.c index 9eced2cc9f94..248082bfea5c 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -143,6 +143,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) struct resource *res = &pgmap->res; struct dev_pagemap *conflict_pgmap; pgprot_t pgprot = PAGE_KERNEL; + struct mhp_restrictions restrictions = {}; int error, nid, is_ram; align_start = res->start & ~(SECTION_SIZE - 1); @@ -195,6 +196,9 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) if (error) goto err_pfn_remap; + /* We do not want any optional features only our own memmap */ + restrictions.altmap = altmap; + mem_hotplug_begin(); error = kasan_add_zero_shadow(__va(align_start), align_size); if (error) { @@ -202,7 +206,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) goto err_kasan; } - error = arch_add_memory(nid, align_start, align_size, altmap, false); + error = arch_add_memory(nid, align_start, align_size, &restrictions); if (!error) move_pfn_range_to_zone(&NODE_DATA(nid)->node_zones[ZONE_DEVICE], align_start >> PAGE_SHIFT, diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index d19e5f33e33b..8a97bda770c1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -270,12 +270,12 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn, * add the new pages. */ int __ref __add_pages(int nid, unsigned long phys_start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap, - bool want_memblock) + unsigned long nr_pages, struct mhp_restrictions *restrictions) { unsigned long i; int err = 0; int start_sec, end_sec; + struct vmem_altmap *altmap = restrictions->altmap; /* during initialize mem_map, align hot-added range to section */ start_sec = pfn_to_section_nr(phys_start_pfn); @@ -296,7 +296,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, for (i = start_sec; i <= end_sec; i++) { err = __add_section(nid, section_nr_to_pfn(i), altmap, - want_memblock); + restrictions->flags & MHP_MEMBLOCK_API); /* * EEXIST is finally dealt with by ioresource collision @@ -1100,6 +1100,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) u64 start, size; bool new_node = false; int ret; + struct mhp_restrictions restrictions = {}; start = res->start; size = resource_size(res); @@ -1124,7 +1125,8 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) new_node = ret; /* call arch's memory hotadd */ - ret = arch_add_memory(nid, start, size, NULL, true); + restrictions.flags = MHP_MEMBLOCK_API; + ret = arch_add_memory(nid, start, size, &restrictions); if (ret < 0) goto error; From patchwork Fri Nov 16 10:12:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10685843 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 519C014BD for ; Fri, 16 Nov 2018 10:13:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C0C32CDA3 for ; Fri, 16 Nov 2018 10:13:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D85F2CDA9; Fri, 16 Nov 2018 10:13:24 +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 BB17E2CDA3 for ; Fri, 16 Nov 2018 10:13:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 707306B08EF; Fri, 16 Nov 2018 05:13:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 690C06B08F0; Fri, 16 Nov 2018 05:13:18 -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 5581A6B08F1; Fri, 16 Nov 2018 05:13:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 06B696B08EF for ; Fri, 16 Nov 2018 05:13:18 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id a24-v6so18426616pfn.12 for ; Fri, 16 Nov 2018 02:13:17 -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=Z5Zg9XCZq0zVh5ZJ3vhgOot8MCsp3XxjOIKtJa/m2lM=; b=VpIjcdY7jwEwRtlzhkaK+PSXEHIQCrM8QUgFdLdxZlYHP1ygnY9/Okrm48saHZw2+g v3FnLXkipxcd5HAeaMg+92Frc0NVFQB4xt/KEitmzhFtQY5HgTMt0OmZMT2BrnObuYIJ 4ChRG6r0hf1tId7M35f63pqTjDPmb5erYItwD5aU2MUHn3Ny1D1al6O0rrDbxSFK9ORq LB213AEjVdArigZAalHz+R/LkBJuNj9fctCHnvZW2ssivDlUBZEQH2ILJ25vabKj97tl EcnnXCJ5eukKkLmNElJ4l+8wtJcOjsiyIMRnd8+s9tcFvzERAxHNSNo/DdQN5VZaj1KP INIw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com X-Gm-Message-State: AGRZ1gJxWbbC1pnJqOpg3tfXx8fgj9Pe7+ZrerdRDv0XKwdyjK1OTswp lS+wD2mjhGbXEK7EELvqFBDvbU7tEvM+pe7uBSM8b9P1xsf9YtcFzGiQzISBNpTU1wKFNPFAePs wte7slNDb/TBE4WspXppsEpg/7w7n0cN6jYjg0RDrAbT/fqFGqrS+vwPtlnqRrZxSfA== X-Received: by 2002:a63:9712:: with SMTP id n18mr9176924pge.295.1542363197485; Fri, 16 Nov 2018 02:13:17 -0800 (PST) X-Google-Smtp-Source: AJdET5e/8RCr7me/sxGq3VsvgrxB5qYl7HE5nUJkQJaznMn27ekPHGXIjJ2cdJ5tAMaT7SYnf4gm X-Received: by 2002:a63:9712:: with SMTP id n18mr9176862pge.295.1542363196065; Fri, 16 Nov 2018 02:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542363196; cv=none; d=google.com; s=arc-20160816; b=oBWXrdXFL5yi0OOHngPCz/Uz2VvknLY4t8+/wYpajoCIjk0ibb5/8k+vNH1vBiqWkk arjecQeWe58b1R65OMVIKRKfecpoBUbYlAnHJkRDjZ+OqZ7+/uxAzXyXyU/RINtgpWnC poc1xbGM/+waHne9op8nPeDY1LaE+WX+9mminMOihR1gwybI2Dj0BqI/3C2hVw4alX9m m6VWu9EPR9AeW26em/9mx4cR/t7cL/6Whoz8gozUZRjGI8Db8PL28zLXIGiOvakH76ty RbQAgKyckyb93JLAoYVs47lRnYCpjMf0P1B2rw2KAVipAZO78yRshutbmtDvcu5mL669 5uQA== 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=Z5Zg9XCZq0zVh5ZJ3vhgOot8MCsp3XxjOIKtJa/m2lM=; b=hcpG8XZx1g/x0RHSiyc29VO0ZRznxmN5bA8thf4cheqrmMlERH+v4Zgy1zevLDYGDw MVJitPQhgeYuUQtZi+/B8zQ88a+hH6ojLuAh9/bEmJWzaMi8S1DeYkY768H3I+DsKVDX dEUW8iB05BLDNP01l+PiH8xA+hM4sKMHMgcA9atRuZmyYeZBbnph4U8oquoKAWhnVNOt dH0JCVKtdtLpVsdKfndUeAwnu4dnkCzq4suV/W0VQcsIJdOrA8STkRY8ijVbe1L8yWUq 6MQGLTXkP7cyexv/RAtIkFvWZDqEibJKntdj7y04DKNkTX5eaT0gQkzJlyP9ML/NfB/1 MSiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id v9si397107pfl.45.2018.11.16.02.13.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 02:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.com 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.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 16 Nov 2018 11:13:13 +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); Fri, 16 Nov 2018 10:12:51 +0000 From: Oscar Salvador To: linux-mm@kvack.org Cc: mhocko@suse.com, david@redhat.com, rppt@linux.vnet.ibm.com, akpm@linux-foundation.org, arunks@codeaurora.org, bhe@redhat.com, dan.j.williams@intel.com, Pavel.Tatashin@microsoft.com, Jonathan.Cameron@huawei.com, jglisse@redhat.com, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 3/4] mm, memory_hotplug: allocate memmap from the added memory range for sparse-vmemmap Date: Fri, 16 Nov 2018 11:12:21 +0100 Message-Id: <20181116101222.16581-4-osalvador@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181116101222.16581-1-osalvador@suse.com> References: <20181116101222.16581-1-osalvador@suse.com> 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: Oscar Salvador Physical memory hotadd has to allocate a memmap (struct page array) for the newly added memory section. Currently, kmalloc is used for those allocations. This has some disadvantages: a) an existing memory is consumed for that purpose (~2MB per 128MB memory section) b) if the whole node is movable then we have off-node struct pages which has performance drawbacks. a) has turned out to be a problem for memory hotplug based ballooning because the userspace might not react in time to online memory while the memory consumed during physical hotadd consumes enough memory to push system to OOM. 31bc3858ea3e ("memory-hotplug: add automatic onlining policy for the newly added memory") has been added to workaround that problem. We can do much better when CONFIG_SPARSEMEM_VMEMMAP=y because vmemap page tables can map arbitrary memory. That means that we can simply use the beginning of each memory section and map struct pages there. struct pages which back the allocated space then just need to be treated carefully. Add {_Set,_Clear}PageVmemmap helpers to distinguish those pages in pfn walkers. We do not have any spare page flag for this purpose so use the combination of PageReserved bit which already tells that the page should be ignored by the core mm code and store VMEMMAP_PAGE (which sets all bits but PAGE_MAPPING_FLAGS) into page->mapping. On the memory hotplug front add a new MHP_MEMMAP_FROM_RANGE restriction flag. User is supposed to set the flag if the memmap should be allocated from the hotadded range. Please note that this is just a hint and architecture code can veto this if this cannot be supported. E.g. s390 cannot support this currently beause the physical memory range is made accessible only during memory online. Implementation wise we reuse vmem_altmap infrastructure to override the default allocator used by __vmemap_populate. Once the memmap is allocated we need a way to mark altmap pfns used for the allocation and this is done by a new vmem_altmap::flush_alloc_pfns callback. mark_vmemmap_pages implementation then simply __SetPageVmemmap all struct pages backing those pfns. The callback is called from sparse_add_one_section. mark_vmemmap_pages will take care of marking the pages as PageVmemmap, and to increase the refcount of the first Vmemmap page. This is done to know how much do we have to defer the call to vmemmap_free(). We also have to be careful about those pages during online and offline operations. They are simply skipped now so online will keep them reserved and so unusable for any other purpose and offline ignores them so they do not block the offline operation. When hot-remove the range, since sections are removed sequantially starting from the first one and moving on, __kfree_section_memmap will catch the first Vmemmap page and will get its reference count. In this way, __kfree_section_memmap knows how much does it have to defer the call to vmemmap_free(). in case we are hot-removing a range that used altmap, the call to vmemmap_free must be done backwards, because the beginning of memory is used for the pagetables. Doing it this way, we ensure that by the time we remove the pagetables, those pages will not have to be referenced anymore. Please note that only the memory hotplug is currently using this allocation scheme. The boot time memmap allocation could use the same trick as well but this is not done yet. Signed-off-by: Oscar Salvador --- arch/arm64/mm/mmu.c | 5 ++- arch/powerpc/mm/init_64.c | 2 ++ arch/s390/mm/init.c | 6 ++++ arch/x86/mm/init_64.c | 7 ++++ include/linux/memory_hotplug.h | 8 ++++- include/linux/memremap.h | 65 +++++++++++++++++++++++++++++++-- include/linux/page-flags.h | 18 ++++++++++ kernel/memremap.c | 6 ---- mm/compaction.c | 3 ++ mm/hmm.c | 6 ++-- mm/memory_hotplug.c | 81 +++++++++++++++++++++++++++++++++++++++--- mm/page_alloc.c | 22 ++++++++++-- mm/page_isolation.c | 13 ++++++- mm/sparse.c | 46 ++++++++++++++++++++++++ 14 files changed, 268 insertions(+), 20 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 394b8d554def..8fa6e2ade5be 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -733,7 +733,10 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, if (pmd_none(READ_ONCE(*pmdp))) { void *p = NULL; - p = vmemmap_alloc_block_buf(PMD_SIZE, node); + if (altmap) + p = altmap_alloc_block_buf(PMD_SIZE, altmap); + else + p = vmemmap_alloc_block_buf(PMD_SIZE, node); if (!p) return -ENOMEM; diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c index 7a9886f98b0c..03f014abd4eb 100644 --- a/arch/powerpc/mm/init_64.c +++ b/arch/powerpc/mm/init_64.c @@ -278,6 +278,8 @@ void __ref vmemmap_free(unsigned long start, unsigned long end, continue; page = pfn_to_page(addr >> PAGE_SHIFT); + if (PageVmemmap(page)) + continue; section_base = pfn_to_page(vmemmap_section_start(start)); nr_pages = 1 << page_order; diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 4139affd6157..bc1523bcb09d 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -231,6 +231,12 @@ int arch_add_memory(int nid, u64 start, u64 size, unsigned long size_pages = PFN_DOWN(size); int rc; + /* + * Physical memory is added only later during the memory online so we + * cannot use the added range at this stage unfortunatelly. + */ + restrictions->flags &= ~MHP_MEMMAP_FROM_RANGE; + rc = vmem_add_mapping(start, size); if (rc) return rc; diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index fd06bcbd9535..d5234ca5c483 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -815,6 +815,13 @@ static void __meminit free_pagetable(struct page *page, int order) unsigned long magic; unsigned int nr_pages = 1 << order; + /* + * runtime vmemmap pages are residing inside the memory section so + * they do not have to be freed anywhere. + */ + if (PageVmemmap(page)) + return; + /* bootmem page has reserved flag */ if (PageReserved(page)) { __ClearPageReserved(page); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 7249dab00ac9..244e0e2c030c 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -118,9 +118,15 @@ extern int __remove_pages(struct zone *zone, unsigned long start_pfn, * and offline memory explicitly. Lack of this bit means that the caller has to * call move_pfn_range_to_zone to finish the initialization. */ - #define MHP_MEMBLOCK_API 1<<0 +/* + * Do we want memmap (struct page array) allocated from the hotadded range. + * Please note that only SPARSE_VMEMMAP implements this feauture and some + * architectures might not support it even for that memory model (e.g. s390) + */ +#define MHP_MEMMAP_FROM_RANGE 1<<1 + /* Restrictions for the memory hotplug */ struct mhp_restrictions { unsigned long flags; /* MHP_ flags */ diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 0ac69ddf5fc4..863f339224e6 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -5,6 +5,8 @@ #include #include +#include +#include struct resource; struct device; @@ -16,13 +18,18 @@ struct device; * @free: free pages set aside in the mapping for memmap storage * @align: pages reserved to meet allocation alignments * @alloc: track pages consumed, private to vmemmap_populate() + * @flush_alloc_pfns: callback to be called on the allocated range after it + * @nr_sects: nr of sects filled with memmap allocations + * is mapped to the vmemmap - see mark_vmemmap_pages */ struct vmem_altmap { - const unsigned long base_pfn; + unsigned long base_pfn; const unsigned long reserve; unsigned long free; unsigned long align; unsigned long alloc; + int nr_sects; + void (*flush_alloc_pfns)(struct vmem_altmap *self); }; /* @@ -133,8 +140,62 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap); struct dev_pagemap *get_dev_pagemap(unsigned long pfn, struct dev_pagemap *pgmap); -unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); +static inline unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) +{ + /* number of pfns from base where pfn_to_page() is valid */ + return altmap->reserve + altmap->free; +} + void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns); + +static inline void mark_vmemmap_pages(struct vmem_altmap *self) +{ + unsigned long pfn = self->base_pfn + self->reserve; + unsigned long nr_pages = self->alloc; + unsigned long align = PAGES_PER_SECTION * sizeof(struct page); + struct page *head; + unsigned long i; + + pr_debug("%s: marking %px - %px as Vmemmap\n", __func__, + pfn_to_page(pfn), + pfn_to_page(pfn + nr_pages - 1)); + /* + * We keep track of the sections using this altmap by means + * of a refcount, so we know how much do we have to defer + * the call to vmemmap_free for this memory range. + * The refcount is kept in the first vmemmap page. + * For example: + * We add 10GB: (ffffea0004000000 - ffffea000427ffc0) + * ffffea0004000000 will have a refcount of 80. + */ + head = (struct page *)ALIGN_DOWN((unsigned long)pfn_to_page(pfn), align); + head = (struct page *)((unsigned long)head - (align * self->nr_sects)); + page_ref_inc(head); + + /* + * We have used a/another section only with memmap allocations. + * We need to keep track of it in order to get the first head page + * to increase its refcount. + * This makes it easier to compute. + */ + if (!((page_ref_count(head) * PAGES_PER_SECTION) % align)) + self->nr_sects++; + + /* + * All allocations for the memory hotplug are the same sized so align + * should be 0 + */ + WARN_ON(self->align); + for (i = 0; i < nr_pages; i++, pfn++) { + struct page *page = pfn_to_page(pfn); + __SetPageVmemmap(page); + init_page_count(page); + } + + self->alloc = 0; + self->base_pfn += nr_pages + self->reserve; + self->free -= nr_pages; +} #else static inline void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 50ce1bddaf56..e79054fcc96e 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -437,6 +437,24 @@ static __always_inline int __PageMovable(struct page *page) PAGE_MAPPING_MOVABLE; } +#define VMEMMAP_PAGE ~PAGE_MAPPING_FLAGS +static __always_inline int PageVmemmap(struct page *page) +{ + return PageReserved(page) && (unsigned long)page->mapping == VMEMMAP_PAGE; +} + +static __always_inline void __ClearPageVmemmap(struct page *page) +{ + ClearPageReserved(page); + page->mapping = NULL; +} + +static __always_inline void __SetPageVmemmap(struct page *page) +{ + SetPageReserved(page); + page->mapping = (void *)VMEMMAP_PAGE; +} + #ifdef CONFIG_KSM /* * A KSM page is one of those write-protected "shared pages" or "merged pages" diff --git a/kernel/memremap.c b/kernel/memremap.c index 248082bfea5c..10f5bd912780 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -239,12 +239,6 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) } EXPORT_SYMBOL(devm_memremap_pages); -unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) -{ - /* number of pfns from base where pfn_to_page() is valid */ - return altmap->reserve + altmap->free; -} - void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns) { altmap->alloc -= nr_pfns; diff --git a/mm/compaction.c b/mm/compaction.c index 7c607479de4a..c94a480e01b5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -768,6 +768,9 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, page = pfn_to_page(low_pfn); + if (PageVmemmap(page)) + goto isolate_fail; + if (!valid_page) valid_page = page; diff --git a/mm/hmm.c b/mm/hmm.c index 90c34f3d1243..ec1e8d97a3ce 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -1072,6 +1072,7 @@ static int hmm_devmem_pages_create(struct hmm_devmem *devmem) resource_size_t key, align_start, align_size, align_end; struct device *device = devmem->device; int ret, nid, is_ram; + struct mhp_restrictions restrictions = {}; align_start = devmem->resource->start & ~(PA_SECTION_SIZE - 1); align_size = ALIGN(devmem->resource->start + @@ -1142,11 +1143,10 @@ static int hmm_devmem_pages_create(struct hmm_devmem *devmem) * want the linear mapping and thus use arch_add_memory(). */ if (devmem->pagemap.type == MEMORY_DEVICE_PUBLIC) - ret = arch_add_memory(nid, align_start, align_size, NULL, - false); + ret = arch_add_memory(nid, align_start, align_size, &restrictions); else ret = add_pages(nid, align_start >> PAGE_SHIFT, - align_size >> PAGE_SHIFT, NULL, false); + align_size >> PAGE_SHIFT, &restrictions); if (ret) { mem_hotplug_done(); goto error_add_memory; diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 8a97bda770c1..5a53d29b4101 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -276,11 +276,22 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, int err = 0; int start_sec, end_sec; struct vmem_altmap *altmap = restrictions->altmap; + struct vmem_altmap __memblk_altmap; /* during initialize mem_map, align hot-added range to section */ start_sec = pfn_to_section_nr(phys_start_pfn); end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1); + if(!altmap && (restrictions->flags & MHP_MEMMAP_FROM_RANGE)) { + __memblk_altmap.base_pfn = phys_start_pfn; + __memblk_altmap.alloc = 0; + __memblk_altmap.align = 0; + __memblk_altmap.free = nr_pages; + __memblk_altmap.nr_sects = 0; + __memblk_altmap.flush_alloc_pfns = mark_vmemmap_pages; + altmap = &__memblk_altmap; + } + if (altmap) { /* * Validate altmap is within bounds of the total request @@ -685,13 +696,72 @@ static int online_pages_blocks(unsigned long start, unsigned long nr_pages) return onlined_pages; } +static int __online_pages_range(unsigned long start_pfn, unsigned long nr_pages) +{ + if (PageReserved(pfn_to_page(start_pfn))) + return online_pages_blocks(start_pfn, nr_pages); + + return 0; +} + + static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages, - void *arg) + void *arg) { unsigned long onlined_pages = *(unsigned long *)arg; + unsigned long pfn = start_pfn; + unsigned long end_pfn = start_pfn + nr_pages; + bool vmemmap_page = false; - if (PageReserved(pfn_to_page(start_pfn))) - onlined_pages = online_pages_blocks(start_pfn, nr_pages); + for (; pfn < end_pfn; pfn++) { + struct page *p = pfn_to_page(pfn); + + /* + * Let us check if we got vmemmap pages. + */ + if (PageVmemmap(p)) { + vmemmap_page = true; + break; + } + } + + if (!vmemmap_page) { + /* + * We can send the whole range to __online_pages_range, + * as we know for sure that there are not vmemmap pages. + */ + onlined_pages += __online_pages_range(start_pfn, nr_pages); + } else { + /* + * We need to strip the vmemmap pages here, + * as we do not want to send them to the buddy allocator. + */ + unsigned long sections = nr_pages / PAGES_PER_SECTION; + unsigned long sect_nr = 0; + + for (; sect_nr < sections; sect_nr++) { + unsigned pfn_end_section; + unsigned long memmap_pages = 0; + + pfn = start_pfn + (PAGES_PER_SECTION * sect_nr); + pfn_end_section = pfn + PAGES_PER_SECTION; + + while (pfn < pfn_end_section) { + struct page *p = pfn_to_page(pfn); + + if (PageVmemmap(p)) + memmap_pages++; + pfn++; + } + pfn = start_pfn + (PAGES_PER_SECTION * sect_nr); + if (!memmap_pages) { + onlined_pages += __online_pages_range(pfn, PAGES_PER_SECTION); + } else if (memmap_pages && memmap_pages < PAGES_PER_SECTION) { + pfn += memmap_pages; + onlined_pages += __online_pages_range(pfn, PAGES_PER_SECTION - memmap_pages); + } + } + } online_mem_sections(start_pfn, start_pfn + nr_pages); @@ -1125,7 +1195,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) new_node = ret; /* call arch's memory hotadd */ - restrictions.flags = MHP_MEMBLOCK_API; + restrictions.flags = MHP_MEMBLOCK_API|MHP_MEMMAP_FROM_RANGE; ret = arch_add_memory(nid, start, size, &restrictions); if (ret < 0) goto error; @@ -1374,6 +1444,9 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) continue; page = pfn_to_page(pfn); + if (PageVmemmap(page)) + continue; + if (PageHuge(page)) { struct page *head = compound_head(page); pfn = page_to_pfn(head) + (1<= limit) { + vmemmap_free(range_start, range_end, NULL); + range_end = range_start; + range_start -= align; + } +} + static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, struct vmem_altmap *altmap) { @@ -575,6 +601,18 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long start = (unsigned long)memmap; unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION); + if (PageVmemmap(memmap) && !current_vmemmap_page) + current_vmemmap_page = memmap; + + if (current_vmemmap_page) { + if (vmemmap_dec_and_test()) { + unsigned long start_vmemmap = (unsigned long)current_vmemmap_page; + free_vmemmap_range(start_vmemmap, start, end); + current_vmemmap_page = NULL; + } + return; + } + vmemmap_free(start, end, altmap); } #ifdef CONFIG_MEMORY_HOTREMOVE @@ -703,6 +741,14 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, */ page_init_poison(memmap, sizeof(struct page) * PAGES_PER_SECTION); + /* + * now that we have a valid vmemmap mapping we can use + * pfn_to_page and flush struct pages which back the + * memmap + */ + if (altmap && altmap->flush_alloc_pfns) + altmap->flush_alloc_pfns(altmap); + section_mark_present(ms); sparse_init_one_section(ms, section_nr, memmap, usemap); From patchwork Fri Nov 16 10:12:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10685841 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 9572214E2 for ; Fri, 16 Nov 2018 10:13:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83E122CDA3 for ; Fri, 16 Nov 2018 10:13:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75E762CDA9; Fri, 16 Nov 2018 10:13:20 +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 03C002CDA3 for ; Fri, 16 Nov 2018 10:13:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D95C96B08EE; Fri, 16 Nov 2018 05:13:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D255B6B08EF; Fri, 16 Nov 2018 05:13:16 -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 B2A8A6B08F0; Fri, 16 Nov 2018 05:13:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 5E9CC6B08EE for ; Fri, 16 Nov 2018 05:13:16 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id o9so15003556pgv.19 for ; Fri, 16 Nov 2018 02:13:16 -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=nnKpzYgW+mUuDIHSo/P3/ttMh4xsRWLqEz8xL4ND6XQ=; b=evvo4v/Rv/2Aom3w1YLiUe/yxhyZISDsQPGDIyQHaoLK6av7DDASiiCfKOIAL0RlQ6 Ie9K1ce/uGMRCc8zq/y5Y/tNzx7kL4XLR+bvZkZT0XxTi7AnRZcsKNurEM1JEvOA7aq2 nky7BLZI9lZlFcms8MnKldJQy2/S8rdtw5gOAIFDcQaU06joOAXxHuBdMOJWYqbNrlEA LQr68x8VQErgoola7p+AxhVkBHPIFajq8A840IlKJWCgi0G1ezEPtKOyfrA+ZIWsGeZH YMVhFTSr7N+Y7Zw1MLobvxcz58FJwA1+Tr6xV+TQVzRTWmgTm93OYilLL8hdFAuDZCH4 9qwQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com X-Gm-Message-State: AGRZ1gJxY8xwGz4u83NZWuzmJjiU2qlGASPjPnjSPuDwmL5CoNfHTjZe NRSL5+fqHPq10/055ZCun0IYQEFtuEIWzjbCNNg0l8cJ2O15i8ud2M4Qmxq6MkfX4yPzde1sWJL gxdjJmFsxSkazT9DH3hMCi9pDFIYAv9PKLRBOb6zJJRUQEyyHiQlpw80h5IKDYQcXdQ== X-Received: by 2002:a63:50b:: with SMTP id 11mr9118056pgf.411.1542363196046; Fri, 16 Nov 2018 02:13:16 -0800 (PST) X-Google-Smtp-Source: AJdET5fGOARy8UJ1rgY8N59rSrrcsWPgk76WVDkTMmRQ6JVfTIdRqZRH8BI7khv10A9eacAujhEw X-Received: by 2002:a63:50b:: with SMTP id 11mr9118004pgf.411.1542363194733; Fri, 16 Nov 2018 02:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542363194; cv=none; d=google.com; s=arc-20160816; b=sQ7AZWnH/f3qAEu41ac9VXGdO+sdxEiv/DWwyREgfcjmXGlQn1OmNYYKReV1CuIle4 SDh/BOqmTdIcPuzX1dJz2ZxCl/ns2PxvGXndJIpPdQemO0H40WySO0SDivAJmcLgDgba nLi3L/G4bxj28ay/dxwll/BFUVuoAsE4l9PDSm5NpzjchUvKLPfrtgMVvub5zKbVKnlz jgi5tXrWWyT3/jpfmGCpRDHRD5xbo05Zak7h3TQze1SiTrFBRJuoJo0PFx1u6nkb/E5t lCSLi2wRdt9foA27Nfk6PhSiRj6myZ4LcaxU2J5WVG7okXUQFelhtZkakh0SeTB6lCL8 3rcw== 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=nnKpzYgW+mUuDIHSo/P3/ttMh4xsRWLqEz8xL4ND6XQ=; b=Bejk8567f04gqtOUrpi+vFQs0ZmSYNwzU4h12mv9ViWUage0nZMWf2xQCirhOmdZj+ KQpnJtEEnbs7gzFI+U5GYqitLVtO/GwBdY2mn7c1+4I5leNBjwi2u1/5zVU056H85SjB 1bVfAS38UUH0t/fkCtGayFSZKZLKyoJFjrLGkYzdbcGyGs8+xXvpU/9HbxxxFekx+T15 2dyyPwE3m6rsGS3J5IBLrtrO7v3vWuAzwA0aYlCq3EqrVB7ueLrhsuxws8fXgqzkHf0E D8yANqmdp8ij+DEzAMY666qxfzHlGxZJAEZCfpcl0DPUAqSpuG5dermZf18XFHoPshO7 STYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id r3-v6si30123605pgr.252.2018.11.16.02.13.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 02:13:14 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.com 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.com designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.com Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 16 Nov 2018 11:13:12 +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); Fri, 16 Nov 2018 10:12:52 +0000 From: Oscar Salvador To: linux-mm@kvack.org Cc: mhocko@suse.com, david@redhat.com, rppt@linux.vnet.ibm.com, akpm@linux-foundation.org, arunks@codeaurora.org, bhe@redhat.com, dan.j.williams@intel.com, Pavel.Tatashin@microsoft.com, Jonathan.Cameron@huawei.com, jglisse@redhat.com, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 4/4] mm, sparse: rename kmalloc_section_memmap, __kfree_section_memmap Date: Fri, 16 Nov 2018 11:12:22 +0100 Message-Id: <20181116101222.16581-5-osalvador@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181116101222.16581-1-osalvador@suse.com> References: <20181116101222.16581-1-osalvador@suse.com> 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 Both functions will use altmap rather than kmalloc for sparsemem-vmemmap so rename them to alloc_section_memmap/free_section_memmap which better reflect the functionality. Signed-off-by: Michal Hocko Signed-off-by: Oscar Salvador --- mm/sparse.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 29cbaa0e46c3..719853ef2e55 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -589,13 +589,13 @@ static void free_vmemmap_range(unsigned long limit, unsigned long start, unsigne } } -static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, +static inline struct page *alloc_section_memmap(unsigned long pnum, int nid, struct vmem_altmap *altmap) { /* This will make the necessary allocations eventually. */ return sparse_mem_map_populate(pnum, nid, altmap); } -static void __kfree_section_memmap(struct page *memmap, +static void free_section_memmap(struct page *memmap, struct vmem_altmap *altmap) { unsigned long start = (unsigned long)memmap; @@ -646,13 +646,13 @@ static struct page *__kmalloc_section_memmap(void) return ret; } -static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, +static inline struct page *alloc_section_memmap(unsigned long pnum, int nid, struct vmem_altmap *altmap) { return __kmalloc_section_memmap(); } -static void __kfree_section_memmap(struct page *memmap, +static void free_section_memmap(struct page *memmap, struct vmem_altmap *altmap) { if (is_vmalloc_addr(memmap)) @@ -718,12 +718,12 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, if (ret < 0 && ret != -EEXIST) return ret; ret = 0; - memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, altmap); + memmap = alloc_section_memmap(section_nr, pgdat->node_id, altmap); if (!memmap) return -ENOMEM; usemap = __kmalloc_section_usemap(); if (!usemap) { - __kfree_section_memmap(memmap, altmap); + free_section_memmap(memmap, altmap); return -ENOMEM; } @@ -756,7 +756,7 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, pgdat_resize_unlock(pgdat, &flags); if (ret < 0) { kfree(usemap); - __kfree_section_memmap(memmap, altmap); + free_section_memmap(memmap, altmap); } return ret; } @@ -798,7 +798,7 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap, if (PageSlab(usemap_page) || PageCompound(usemap_page)) { kfree(usemap); if (memmap) - __kfree_section_memmap(memmap, altmap); + free_section_memmap(memmap, altmap); return; }