Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1075098rdg; Wed, 11 Oct 2023 13:44:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFJtkCSf5ZjbKI1yk6dKtPvVBYrbIotF/yYX0R2cbYf9aeorKsXg8auPwyXUZEIMkgmzWj X-Received: by 2002:a05:6a20:7d9d:b0:15d:4cf1:212e with SMTP id v29-20020a056a207d9d00b0015d4cf1212emr27625484pzj.4.1697057073777; Wed, 11 Oct 2023 13:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697057073; cv=none; d=google.com; s=arc-20160816; b=bkfXC2kT1IjVcLZ7AwWlHqE2ktvmFaB+CDbAfvDCza1EscDxCzmpC9H/0XtzRRr1fL 6SJuvmUUE4oYGZHLTHZKf5dEJx49y9/Tk6es9sfeOoAT+vNMsF1UsYCO8+B6lCwfI8uf AbRxZLrNpcFS+/woFJ1WjY1tEN51AWaaun19C3VOlsNl/HZGuyaC2XURJJzISVGA31iI wXxmj6kIMCF8PKePHYuh2aAfdkkJ3O/+DZAugqqKjKg1kgTSrmTJ+FZ92rA8jR4dU8BH DIOZgmQio3e59dMp9uOFPHI3yYq+ZjIoTGtiEKrwRUlxhHIKvE+s8bxe17mIs3vgX62p S3SA== 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 :dkim-signature; bh=/AKsmkTQtU/rhqiAGHEzho0MRurJuhinBZFCGxQETC4=; fh=M3K0WzkORRBdZ/xk6xwnHKhzjYMM49BerW1eVjFc/9Y=; b=W4b0+9bArUhh6eGioMhUiLcnFpiyOlnUVbyShThmRKNBqp3mpxsIMRFeu35ibq1Aon PQuOtQs5D0SCRwYcXozlZ/srpgUL26LiT+O1e1eJ7S1ChN7lMjwnUx8IS3QyE0H0N+pB Fv30Q9IA8crG5Ss5PU1wQUuykVuz7mPZKp1Q+R1dErlxAezslLvrPEUstJeF4XeJdU7L aYu8xWcIjblIA0eK7j9IDqlZ4dvTkFwG27MUQfojL85lRw9Hn4YWgx5BxyGRE3sx91k0 pPQT8AKa2ecdcl4C48zJTMFBatyDrvFI1+hbpOtrTR4Tnk/5dk/q51Fxr3ujg8y3AKLS wAXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=A9RblMU5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a22-20020a631a56000000b0056fbf327dd5si567274pgm.131.2023.10.11.13.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=A9RblMU5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1907980B81F7; Wed, 11 Oct 2023 13:44:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233481AbjJKUoH (ORCPT + 99 others); Wed, 11 Oct 2023 16:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbjJKUoG (ORCPT ); Wed, 11 Oct 2023 16:44:06 -0400 Received: from mail-yw1-x1141.google.com (mail-yw1-x1141.google.com [IPv6:2607:f8b0:4864:20::1141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E46589E; Wed, 11 Oct 2023 13:44:04 -0700 (PDT) Received: by mail-yw1-x1141.google.com with SMTP id 00721157ae682-59f6492b415so2124367b3.0; Wed, 11 Oct 2023 13:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697057044; x=1697661844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/AKsmkTQtU/rhqiAGHEzho0MRurJuhinBZFCGxQETC4=; b=A9RblMU5uCCTQamjKzeenzEYrFcmuZxsY9CE2iMOFAVSrrbqO7NifM+bxmT1m66VIr IFNdIFuEZroj46RJTxB6lQDKbTpoKKeGMNLf+3Su0Poa/dIV2mU7f67WmgBSbmc/w7nL /VcyNMFgdDfOe8dGeOAaITOins4pVEd+k5uUhw4aEAXjixvxjS01QLwXcL+EitmBesR3 d5fxSVkqU5IWB7n6mgP3qXAkWGZvM/k4MkuCe4uWwhbEKWCcBXIyjuueJwwlZ+rGl346 l6g0dmrPjv+etqRsw3qYFdMiRW6874xl8gqjvgwtfisUI6y9eGu1gbVDWpw6fiYyQvkS PP0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697057044; x=1697661844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/AKsmkTQtU/rhqiAGHEzho0MRurJuhinBZFCGxQETC4=; b=ephZp6ITKzF7VB2glbLO/0oMJXi+ENQWZOiRkrgpbdjKzFqJpb92RgrVQZD/ijcuKX uhyh2yN+Hv4CpaKNHXGHMONosPvqO7g02CzZIAdTIH6AVx7S/5M0FJvHHEW6jaw+Gz5f pFN4jNRNVsRDqcsW7gCEY3kzFEEhF6pwhyjRx4epjr3JzNql/OGWvh9Zo06wV1Z5oiHP v8yZWmOismoP7utc4yvb6nR8wA6Fzy5ThWbbI+pbK/+ATG0QsapCSZOGqcpex/oVkUly SExegugTe6fp5ZfNbrbOhiRwqxxmPI6/l6MtPbL94AhcORLJRuaS4m6vOzltbla/vs7y 8Vng== X-Gm-Message-State: AOJu0YyX/i3CGSKN045lMu/NuidQzbJ1tNO+nJQebNR3ACckIsFQ7jMu Fm9FBtIxzKzAWgrtixA3+Q== X-Received: by 2002:a81:528b:0:b0:5a5:575:e944 with SMTP id g133-20020a81528b000000b005a50575e944mr11929290ywb.4.1697057044087; Wed, 11 Oct 2023 13:44:04 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id q2-20020a819902000000b0059bc0d766f8sm1844588ywg.34.2023.10.11.13.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:44:03 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, akpm@linux-foundation.org, sthanneeru@micron.com, ying.huang@intel.com, gregory.price@memverge.com Subject: [RFC PATCH v2 1/3] mm/memory-tiers: change mutex to rw semaphore Date: Mon, 9 Oct 2023 16:42:57 -0400 Message-Id: <20231009204259.875232-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231009204259.875232-1-gregory.price@memverge.com> References: <20231009204259.875232-1-gregory.price@memverge.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 13:44:26 -0700 (PDT) X-Spam-Level: ** Tiers will have externally readable information, such as weights, which may change at runtime. This information is expected to be used by task threads during memory allocation so it cannot be protected by hard mutual exclusion. To support this, change the tiering mutex to a rw semaphore. Signed-off-by: Gregory Price --- mm/memory-tiers.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 37a4f59d9585..0a3241a2cadc 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "internal.h" @@ -33,7 +34,7 @@ struct node_memory_type_map { int map_count; }; -static DEFINE_MUTEX(memory_tier_lock); +static DECLARE_RWSEM(memory_tier_sem); static LIST_HEAD(memory_tiers); static struct node_memory_type_map node_memory_types[MAX_NUMNODES]; static struct memory_dev_type *default_dram_type; @@ -137,10 +138,10 @@ static ssize_t nodelist_show(struct device *dev, int ret; nodemask_t nmask; - mutex_lock(&memory_tier_lock); + down_read(&memory_tier_sem); nmask = get_memtier_nodemask(to_memory_tier(dev)); ret = sysfs_emit(buf, "%*pbl\n", nodemask_pr_args(&nmask)); - mutex_unlock(&memory_tier_lock); + up_read(&memory_tier_sem); return ret; } static DEVICE_ATTR_RO(nodelist); @@ -167,7 +168,7 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty int adistance = memtype->adistance; unsigned int memtier_adistance_chunk_size = MEMTIER_CHUNK_SIZE; - lockdep_assert_held_once(&memory_tier_lock); + lockdep_assert_held_write(&memory_tier_sem); adistance = round_down(adistance, memtier_adistance_chunk_size); /* @@ -230,12 +231,12 @@ static struct memory_tier *__node_get_memory_tier(int node) if (!pgdat) return NULL; /* - * Since we hold memory_tier_lock, we can avoid + * Since we hold memory_tier_sem, we can avoid * RCU read locks when accessing the details. No * parallel updates are possible here. */ return rcu_dereference_check(pgdat->memtier, - lockdep_is_held(&memory_tier_lock)); + lockdep_is_held(&memory_tier_sem)); } #ifdef CONFIG_MIGRATION @@ -335,7 +336,7 @@ static void disable_all_demotion_targets(void) for_each_node_state(node, N_MEMORY) { node_demotion[node].preferred = NODE_MASK_NONE; /* - * We are holding memory_tier_lock, it is safe + * We are holding memory_tier_sem, it is safe * to access pgda->memtier. */ memtier = __node_get_memory_tier(node); @@ -364,7 +365,7 @@ static void establish_demotion_targets(void) int distance, best_distance; nodemask_t tier_nodes, lower_tier; - lockdep_assert_held_once(&memory_tier_lock); + lockdep_assert_held_write(&memory_tier_sem); if (!node_demotion) return; @@ -479,7 +480,7 @@ static struct memory_tier *set_node_memory_tier(int node) pg_data_t *pgdat = NODE_DATA(node); - lockdep_assert_held_once(&memory_tier_lock); + lockdep_assert_held_write(&memory_tier_sem); if (!node_state(node, N_MEMORY)) return ERR_PTR(-EINVAL); @@ -569,15 +570,15 @@ EXPORT_SYMBOL_GPL(put_memory_type); void init_node_memory_type(int node, struct memory_dev_type *memtype) { - mutex_lock(&memory_tier_lock); + down_write(&memory_tier_sem); __init_node_memory_type(node, memtype); - mutex_unlock(&memory_tier_lock); + up_write(&memory_tier_sem); } EXPORT_SYMBOL_GPL(init_node_memory_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype) { - mutex_lock(&memory_tier_lock); + down_write(&memory_tier_sem); if (node_memory_types[node].memtype == memtype) node_memory_types[node].map_count--; /* @@ -588,7 +589,7 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) node_memory_types[node].memtype = NULL; put_memory_type(memtype); } - mutex_unlock(&memory_tier_lock); + up_write(&memory_tier_sem); } EXPORT_SYMBOL_GPL(clear_node_memory_type); @@ -607,17 +608,17 @@ static int __meminit memtier_hotplug_callback(struct notifier_block *self, switch (action) { case MEM_OFFLINE: - mutex_lock(&memory_tier_lock); + down_write(&memory_tier_sem); if (clear_node_memory_tier(arg->status_change_nid)) establish_demotion_targets(); - mutex_unlock(&memory_tier_lock); + up_write(&memory_tier_sem); break; case MEM_ONLINE: - mutex_lock(&memory_tier_lock); + down_write(&memory_tier_sem); memtier = set_node_memory_tier(arg->status_change_nid); if (!IS_ERR(memtier)) establish_demotion_targets(); - mutex_unlock(&memory_tier_lock); + up_write(&memory_tier_sem); break; } @@ -638,7 +639,7 @@ static int __init memory_tier_init(void) GFP_KERNEL); WARN_ON(!node_demotion); #endif - mutex_lock(&memory_tier_lock); + down_write(&memory_tier_sem); /* * For now we can have 4 faster memory tiers with smaller adistance * than default DRAM tier. @@ -661,7 +662,7 @@ static int __init memory_tier_init(void) break; } establish_demotion_targets(); - mutex_unlock(&memory_tier_lock); + up_write(&memory_tier_sem); hotplug_memory_notifier(memtier_hotplug_callback, MEMTIER_HOTPLUG_PRI); return 0; -- 2.39.1