Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp276559pxb; Fri, 16 Apr 2021 05:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOALgcYTHdqfT0ZQFjYH39K2pWpB5ge33YMhbdiT6S/9TDI8seaM82B30E0XADss9qxPAD X-Received: by 2002:a50:fa84:: with SMTP id w4mr9623123edr.28.1618576344160; Fri, 16 Apr 2021 05:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618576344; cv=none; d=google.com; s=arc-20160816; b=GTW3sBNzHgcG5kouEEkdpHm2tSEFGZrDjBhbPkgxN6aaV4d3v9gqzLaRayLFHdezSb nBXjlgp1TE3ioWQtg9OXhPCqTd8qcTZ6I+61137c72Xyn4T4AvUEKWM5jIgaFfNek9iF 13omiy0mcxm3gQIlB+8MLJhdR8+DT6HpcUew19r3YQabbDnd3YVemtXDsp8XLZCsLnn3 HB5lxWYoETb6bZnRMrFIvocAk+035izgqKkk1yX02lFtSgn/4+K83IXIakcT9WxeIEKt 0x6lsvNCSPZf8QY2ensj5eXOkL34rNkQ4KX+sctOxMkHIwRgCjHz5a1NtPq30gi/esJD mCjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=du0/S/QWxHZ574ZcQJ9QJmy22/V/CqePUrzWN6krgLs=; b=PyOyzoZ1wyCeAXg7BEFqPh2TCcFWTb9KNq4RiBGMUDJR+db1vcMjEFlxr+yhtKyNWt Edwe67nMOSwnLUj/hYO54jgZ4cWKaNjqAMsZIKHw72UMRrfgQDHPVxJgiRs/Pqjtefpb ehyCvmVrF2r361avWfbZsAOfLIa1bXP1Fgqr96MsXH6NBjIVKR2ZXH9r2kbsMD02KvLg cImDIOWGVS+68RZ5FMiZyCCCZNtOnyQNYSHvQ8LgrqN83vLENvfqBjSJ7H/LldqJMKYJ O+VKfQgEjJpy3ZcyJcyIQyWWuwE45YydanEJeWHEk1KRwKGRFDj8N4N/6dPyrzlvDBHa g2/Q== 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 u26si5114405edo.278.2021.04.16.05.32.01; Fri, 16 Apr 2021 05:32:24 -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 S235514AbhDPLYt (ORCPT + 99 others); Fri, 16 Apr 2021 07:24:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:48572 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235011AbhDPLYr (ORCPT ); Fri, 16 Apr 2021 07:24:47 -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 C59AEB01F; Fri, 16 Apr 2021 11:24:21 +0000 (UTC) From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Anshuman Khandual , Pavel Tatashin , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v9 1/8] drivers/base/memory: Introduce memory_block_{online,offline} Date: Fri, 16 Apr 2021 13:24:04 +0200 Message-Id: <20210416112411.9826-2-osalvador@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210416112411.9826-1-osalvador@suse.de> References: <20210416112411.9826-1-osalvador@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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