Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp305852pxy; Wed, 21 Apr 2021 03:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2jGeruRM0MKM5tTcXQtJpSToBTncVfFtNkWcgJ5wQVPkmmyXqkxx4zw7wwsKZU5cswSYr X-Received: by 2002:a05:6402:5255:: with SMTP id t21mr38120179edd.91.1619001221935; Wed, 21 Apr 2021 03:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619001221; cv=none; d=google.com; s=arc-20160816; b=MQJUHkbvP3XhUsmDYkLMmtFQ1t2KW5YGYDp2AdYpstKaUDDaI5OMok+rM0AFceDeGQ ns3xYdBakjk1VhOhuVTHiSNNvZksaPhVCuYijhi7Ng1mh+iujmnxw3dTOD+7K2Xlyt8X x7c7A+fcjpZb5fbDyXKPtRaK1L0tlLvyHWgaFAJxgX5B1xlsFsRw/oWUR3myu5l27wPH 3TkXrovfjA1GHIuDMzt3AKcO37Cc3vaFHF69kjN17xJ2s4UUxlIVDff0LAB6qFjZf1Pe NohVjx3NEOq5k9H2g0SUgDuxLTVPSmSrQBPVCcrr9/b3ykrjkU+WwQ4CAhKByhEl4QWZ v5UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=AUmho6cvMvZ9ZV1DHKYN36h/odJkdnV2kEdcQeg1W/4=; b=ni/aLFG+8AnvNxu7I1jbPqXD388C5+Q2m5LT80S9DmLqFEXzYVrBizayo5KB69wqrY saQFXd6r+SxG99/E/ZLbEslX++J3OQeL5mIgRldsUG+MZ10tG1WPG2/6P/8mpMOkCNk0 g0Q/jtu3NiXjj4WvvSDZIbQ9Ke5tXlzdb+++J/RnX+B7VMzo/ALFkT57ybJvbFPNqMlu BlSdssLF/IJsvlg13H1mjDwFIQtJ8Wba19+zGvjxgk5hrLFSSn0tQ9Vt92kF4rRVhdUt jfCrCoOjg14ImE1j/+ZLuJlZNos8kQYI5W8Am2/56S4YAmIbufFhuBdGhZ9sYAF2SqpP zSpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si1442945ejj.528.2021.04.21.03.33.18; Wed, 21 Apr 2021 03:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239350AbhDUK1s (ORCPT + 99 others); Wed, 21 Apr 2021 06:27:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:38050 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238301AbhDUK1j (ORCPT ); Wed, 21 Apr 2021 06:27:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 33A68AEE7; Wed, 21 Apr 2021 10:27:06 +0000 (UTC) From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Anshuman Khandual , Vlastimil Babka , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v10 1/8] drivers/base/memory: Introduce memory_block_{online,offline} Date: Wed, 21 Apr 2021 12:26:54 +0200 Message-Id: <20210421102701.25051-2-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20210421102701.25051-1-osalvador@suse.de> References: <20210421102701.25051-1-osalvador@suse.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparatory patch that introduces two new functions: memory_block_online() and memory_block_offline(). For now, these functions will only call online_pages() and offline_pages() respectively, but they will be later in charge of preparing the vmemmap pages, carrying out the initialization and proper accounting of such pages. Since memory_block struct contains all the information, pass this struct down the chain till the end functions. Signed-off-by: Oscar Salvador Reviewed-by: David Hildenbrand Acked-by: Michal Hocko --- drivers/base/memory.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index f35298425575..f209925a5d4e 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -169,30 +169,41 @@ int memory_notify(unsigned long val, void *v) return blocking_notifier_call_chain(&memory_chain, val, v); } +static int memory_block_online(struct memory_block *mem) +{ + unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); + unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; + + return online_pages(start_pfn, nr_pages, mem->online_type, mem->nid); +} + +static int memory_block_offline(struct memory_block *mem) +{ + unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); + unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; + + return offline_pages(start_pfn, nr_pages); +} + /* * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is * OK to have direct references to sparsemem variables in here. */ static int -memory_block_action(unsigned long start_section_nr, unsigned long action, - int online_type, int nid) +memory_block_action(struct memory_block *mem, unsigned long action) { - unsigned long start_pfn; - unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; int ret; - start_pfn = section_nr_to_pfn(start_section_nr); - switch (action) { case MEM_ONLINE: - ret = online_pages(start_pfn, nr_pages, online_type, nid); + ret = memory_block_online(mem); break; case MEM_OFFLINE: - ret = offline_pages(start_pfn, nr_pages); + ret = memory_block_offline(mem); break; default: WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " - "%ld\n", __func__, start_section_nr, action, action); + "%ld\n", __func__, mem->start_section_nr, action, action); ret = -EINVAL; } @@ -210,9 +221,7 @@ static int memory_block_change_state(struct memory_block *mem, if (to_state == MEM_OFFLINE) mem->state = MEM_GOING_OFFLINE; - ret = memory_block_action(mem->start_section_nr, to_state, - mem->online_type, mem->nid); - + ret = memory_block_action(mem, to_state); mem->state = ret ? from_state_req : to_state; return ret; -- 2.16.3