Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp510163ybh; Wed, 11 Mar 2020 05:32:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvRnaPr8YD4oVnfrXhoJ6aJkvA6Ib0SwANWoXuYH13rvfXwQogusl1v20lkgrd8PFErNdDF X-Received: by 2002:a9d:67d9:: with SMTP id c25mr2108971otn.358.1583929971035; Wed, 11 Mar 2020 05:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583929971; cv=none; d=google.com; s=arc-20160816; b=WAr2vPvf6MjhzhOyWwXBv6w9ZmcBs7nT+zC7v/YsTXoTYCWWsijSUVgC+/BReatmhk UDg3ATXKQEMmqNW0lVtHL0KNVyXZQL+lEFVSVAfacXbamyfagN40w/V36JkoTptO4YLY EumRGy4OKX2DY/eG9W8cwQfnPYaVpbhjnc+iH8rwWNkklQbQZCqkxrr8wva0MmR+ASO2 AHjIXez81/NcT73XshUp+oK6zgQ6BstHxsc9hf7OyLfWVjJlbSup7PmANRaucquoS1Vq T0Kpl0QaPqHniAAfasz7eHaO7I3oDoTjqkGYW61NYLVj8hxip+Yo8iBYqSc/Cf7b6tYS Zkcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/sbomtSLrHdGOruJ2tgfKohuV+eWUZQ6CK4TodM1MVc=; b=UrCTZPDw8DsxMJqaW/4ybAI7fMyM/O8ogLJ3w6Bc5JlgYjRsvTl3UGC9pHODMr6mN/ 6qZaWQUFI4RkEWwANvb5EUJtzucyiPEkLAUOsahMAPYHgfAI84RHhvtLNMrfJsXcG6zV V/Y8J/+w92SLkHyfl76zmKG1mYwTsixw+MmphJJxtk+qerETDk9hQcyJ9PQxyAeeGA89 +UWpTDM/aBnnSPN6dYHmrTLrAh7gyH9T0+0aw+l+UNQuKCPTV8n5gnSLkegl+xTp4wfy 5PS5Pkr1yTHylR+n0L9TE4hnMFCMxA1cbO5eM+mKqr7ttzw9HW9oFAXvYdx0uqsnti0N xWYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=STC5jLeH; 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=pass (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 i15si1075571ots.121.2020.03.11.05.32.39; Wed, 11 Mar 2020 05:32:51 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=STC5jLeH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729411AbgCKMbF (ORCPT + 99 others); Wed, 11 Mar 2020 08:31:05 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:25620 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729395AbgCKMbE (ORCPT ); Wed, 11 Mar 2020 08:31:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583929863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/sbomtSLrHdGOruJ2tgfKohuV+eWUZQ6CK4TodM1MVc=; b=STC5jLeHV9F4WtrqjEZC2ycbbcD4zT57tkRKa875veFqojGxavYXiOWRkbkWalv+C1Y4CE x8QvZzd1VTG5Rm7kHVZbVhxMA/YzSzto0nCsAMLWK4TznS/a/YtzUc9ltSUqv6urpKmamc P/0lw2Nh9UHkzf4tqhJ99mvTHdiWVf0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-23-qxhbtyNkOxiHCZULO3cxRA-1; Wed, 11 Mar 2020 08:31:01 -0400 X-MC-Unique: qxhbtyNkOxiHCZULO3cxRA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D47CBDBA7; Wed, 11 Mar 2020 12:30:59 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.36.118.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id C017D5C1D4; Wed, 11 Mar 2020 12:30:55 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, David Hildenbrand , Greg Kroah-Hartman , Andrew Morton , Michal Hocko , Oscar Salvador , "Rafael J. Wysocki" , Baoquan He , Wei Yang Subject: [PATCH v1 5/5] mm/memory_hotplug: allow to specify a default online_type Date: Wed, 11 Mar 2020 13:30:26 +0100 Message-Id: <20200311123026.16071-6-david@redhat.com> In-Reply-To: <20200311123026.16071-1-david@redhat.com> References: <20200311123026.16071-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For now, distributions implement advanced udev rules to essentially - Don't online any hotplugged memory (s390x) - Online all memory to ZONE_NORMAL (e.g., most virt environments like hyperv) - Online all memory to ZONE_MOVABLE in case the zone imbalance is taken care of (e.g., bare metal, special virt environments) In summary: All memory is usually onlined the same way, however, the kernel always has to ask userspace to come up with the same answer. E.g., HyperV always waits for a memory block to get onlined before continuing, otherwise it might end up adding memory faster than hotplugging it, which can result in strange OOM situations. Let's allow to specify a default online_type, not just "online" and "offline". This allows distributions to configure the default online_type when booting up and be done with it. We can now specify "offline", "online", "online_movable" and "online_kernel" via - "memhp_default_state=3D" on the kernel cmdline - /sys/devices/systemn/memory/auto_online_blocks just like we are able to specify for a single memory block via /sys/devices/systemn/memory/memoryX/state Cc: Greg Kroah-Hartman Cc: Andrew Morton Cc: Michal Hocko Cc: Oscar Salvador Cc: "Rafael J. Wysocki" Cc: Baoquan He Cc: Wei Yang Signed-off-by: David Hildenbrand --- drivers/base/memory.c | 11 +++++------ include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 8d3e16dab69f..2b09b68b9f78 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -35,7 +35,7 @@ static const char *const online_type_to_str[] =3D { [MMOP_ONLINE_MOVABLE] =3D "online_movable", }; =20 -static int memhp_online_type_from_str(const char *str) +int memhp_online_type_from_str(const char *str) { int i; =20 @@ -394,13 +394,12 @@ static ssize_t auto_online_blocks_store(struct devi= ce *dev, struct device_attribute *attr, const char *buf, size_t count) { - if (sysfs_streq(buf, "online")) - memhp_default_online_type =3D MMOP_ONLINE; - else if (sysfs_streq(buf, "offline")) - memhp_default_online_type =3D MMOP_OFFLINE; - else + const int online_type =3D memhp_online_type_from_str(buf); + + if (online_type < 0) return -EINVAL; =20 + memhp_default_online_type =3D online_type; return count; } =20 diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplu= g.h index c6e090b34c4b..ef55115320fb 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -117,6 +117,8 @@ extern int arch_add_memory(int nid, u64 start, u64 si= ze, struct mhp_restrictions *restrictions); extern u64 max_mem_size; =20 +extern int memhp_online_type_from_str(const char *str); + /* Default online_type (MMOP_*) when new memory blocks are added. */ extern int memhp_default_online_type; /* If movable_node boot option specified */ diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 01443c70aa27..4a96273eafa7 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -75,10 +75,10 @@ EXPORT_SYMBOL_GPL(memhp_default_online_type); =20 static int __init setup_memhp_default_state(char *str) { - if (!strcmp(str, "online")) - memhp_default_online_type =3D MMOP_ONLINE; - else if (!strcmp(str, "offline")) - memhp_default_online_type =3D MMOP_OFFLINE; + const int online_type =3D memhp_online_type_from_str(str); + + if (online_type >=3D 0) + memhp_default_online_type =3D online_type; =20 return 1; } --=20 2.24.1