Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1189603rdb; Tue, 30 Jan 2024 10:21:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbLt6gNb0NlSJ7nJuMrSv2dDbQr3f5AILjZxeVwuAwSAjczjJzpDArXe3u3fbvRm7YecU3 X-Received: by 2002:a17:903:2985:b0:1d8:e2af:f7a3 with SMTP id lm5-20020a170903298500b001d8e2aff7a3mr369604plb.60.1706638902228; Tue, 30 Jan 2024 10:21:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706638902; cv=pass; d=google.com; s=arc-20160816; b=StzNcYxRtJgNhyjYd4S6buD3UWTmUQqYgfkaORRg/skm0PoT0iNJegV5luvMmhMkx7 cilC02UZzb+SbB20gNkWtsdpU4knToGVpSZ76iTd1fXOUAcjmfm/6et3BARyBUrwSQb3 zqAW/ayszGneWLZG8A+fDc09dZ5chR20a2unCydvZ+jRR6BrfPsHyg+9ocEW+RaJpaX0 WMlSra/i9aPFXYaXkyTlkpKu/1M0puQGyvCV+r1287An7ttchyGEJNAzrg0VvUaseeWC jaXdszq/re7+jqXUq0aYVml22rAQQgjLNzHVIZ+LqvOwijmEc3BjGvs8P0qAgca6Yp44 FT8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=P3SsBm0r3LDCnRLkAzwTVLxQ2sFbW5+S1JsSVpdLy4I=; fh=jfmqTHqFQzpdh4kD6rYLjrIdoHJ9f5ZahPzXH+S6pZM=; b=lRduAYPU8TZH528AHtCM9vaa/CzU+Sv7OmXAYu3K+LAL1JiJw6Oz+o+LMuYCyCZcxj TbHkDuqV6gg0V/JiXUAl5PrTwhJMQmMynjKFpt2T34eZkQEtfVLQPdkrJ1koc8PhN7PD rdTEbVeg7GmQbljDcfCPzrNDo6FKCNizZpTCUo3pouq5UUWjYC4rKmz5Yi0Sg/b2ma0s c7htUKtbd2zitHcJcMzYqOp0kbPX5dhSN8sVDeoj2mLPcZz65bwXCgDXVShA+jD5824F RhsQtjkczbg2x5V9c9FvJmMwjhDibZMJkkD2SJ7VxtqMYVaTAUmu6qVTaQoWxZpMiem6 5J/Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g1zF+b0T; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45091-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45091-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t9-20020a17090340c900b001d7601fb7b7si8106777pld.396.2024.01.30.10.21.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 10:21:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45091-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g1zF+b0T; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45091-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45091-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DE05628AF81 for ; Tue, 30 Jan 2024 18:21:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6962157039; Tue, 30 Jan 2024 18:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g1zF+b0T" Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A339D1586CB; Tue, 30 Jan 2024 18:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706638862; cv=none; b=udlgQV+BfFmuy3zroq0pOfpXZ6Qyg23x5MxD9tROl+VWsU0CBQZPk/iUFU01DY2yQCguwOlm7eRJC+AGAc9/fKpDbueyYl6cU3eykAqqWVTQLCmpyDspvl1bzO1VnWspXzI6JrZtReNzhXcjwkpIgzNfU0gSsVBB+qU3nyyzbT0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706638862; c=relaxed/simple; bh=Nc/Qletu6+zJXp1xkdWFc63PgpuhGv7hKfN5LGc1nlg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ar9B9aRc+pft/GNrStqMNxmdaFoTUPxsV3ZsxyKkxX12EqUvwiS1va0c5H3SenQ8VgwuDfR9k74wPTLvfvyTySyl1O8/AYz7qoHGff7GsPyUyuuGsQaboylID3oH+YgtB/Ih32UauSQrTmruI3c6ooou84IXXHkAkUHGySf20qo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g1zF+b0T; arc=none smtp.client-ip=209.85.210.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-6daf694b439so2012626b3a.1; Tue, 30 Jan 2024 10:21:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706638860; x=1707243660; 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=P3SsBm0r3LDCnRLkAzwTVLxQ2sFbW5+S1JsSVpdLy4I=; b=g1zF+b0TITRwXCU92BFOlxezeR9vbjej4YWUJpOnb1jzeUZVkj3m1YQQcpJoQ1QVTH eGgkD2RBKAxwmbDhtxpZmDRmb4OiuOHRKVmCMBEKZ5I3sM9YL10vDkF5EIb3OnE+hslh 2TjbIeHDMh/KKMzwdPfGqbp3nMkKx6gfqFoz650NrY6649mh7tU7xnkFIhEqy5OHGM1h auwC8GZZTVEkDtgsheFCaC4V0r3MU/A5OsRGSUNKylZD7LPKVA6EipC6Mh+itIxwBb/Z /PwXlKu0G34g9Q6BemhWY+zRgD66/MQGh6uAlfkmpcjHabyZPvONuh1f67mgZ3vIr7Oh jE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706638860; x=1707243660; 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=P3SsBm0r3LDCnRLkAzwTVLxQ2sFbW5+S1JsSVpdLy4I=; b=StqWSVz4fVJjnZUS9nTJSJO3hR6ViBLZ+oDbQrWjyxOtNxLXJa4t4jUcuzGAIsfpBS aM9Zj69y6AK91nGHutwQ3sfY+S1iUkvT+gUgB3jZVvstbd3TgbeD43jdNdT3hd+50xWW LERpFB8ZCppone9+w7dIvrwDD5UuECEXXt4ZOuVD2b30wihXnabPXy9djbIZWHr5eEWf GHhoG++QLE4bBXP9kyTHy0hjRMjNEwQ4g/cB4Of0+DRhmW7yE5qvlQO1BQFGyX7znXcq 6uQzcvtKG9X/fPV07Y4kK0u78WyMiJbgII5120a0iveFtUVreIdMgVqSOcGnYpb5BcGG TsmA== X-Gm-Message-State: AOJu0YwvWa+h2e0HO9PjVd/68YnQ4g3EIAr1I0/Y4t6Lp7kBmBM7HZRW /twHZuBHl8g1pW0TUoV8BkjqX+lfjRNS/xUEyaIkBmWiTKz5Kt0= X-Received: by 2002:a05:6a00:9390:b0:6db:de9f:5f10 with SMTP id ka16-20020a056a00939000b006dbde9f5f10mr5976134pfb.15.1706638859932; Tue, 30 Jan 2024 10:20:59 -0800 (PST) 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 o64-20020a62cd43000000b006d9ce7d3258sm8460143pfg.204.2024.01.30.10.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 10:20:59 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, corbet@lwn.net, akpm@linux-foundation.org, gregory.price@memverge.com, honggyu.kim@sk.com, rakie.kim@sk.com, hyeongtak.ji@sk.com, mhocko@kernel.org, ying.huang@intel.com, vtavarespetr@micron.com, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com, seungjun.ha@samsung.com, hannes@cmpxchg.org, dan.j.williams@intel.com Subject: [PATCH v4 2/3] mm/mempolicy: refactor a read-once mechanism into a function for re-use Date: Tue, 30 Jan 2024 13:20:45 -0500 Message-Id: <20240130182046.74278-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240130182046.74278-1-gregory.price@memverge.com> References: <20240130182046.74278-1-gregory.price@memverge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit move the use of barrier() to force policy->nodemask onto the stack into a function `read_once_policy_nodemask` so that it may be re-used. Suggested-by: Huang Ying Signed-off-by: Gregory Price --- mm/mempolicy.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 440128a398ef..3bdfaf03b660 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1909,6 +1909,20 @@ unsigned int mempolicy_slab_node(void) } } +static unsigned int read_once_policy_nodemask(struct mempolicy *pol, + nodemask_t *mask) +{ + /* + * barrier stabilizes the nodemask locally so that it can be iterated + * over safely without concern for changes. Allocators validate node + * selection does not violate mems_allowed, so this is safe. + */ + barrier(); + memcpy(mask, &pol->nodes, sizeof(nodemask_t)); + barrier(); + return nodes_weight(*mask); +} + /* * Do static interleaving for interleave index @ilx. Returns the ilx'th * node in pol->nodes (starting from ilx=0), wrapping around if ilx @@ -1916,20 +1930,12 @@ unsigned int mempolicy_slab_node(void) */ static unsigned int interleave_nid(struct mempolicy *pol, pgoff_t ilx) { - nodemask_t nodemask = pol->nodes; + nodemask_t nodemask; unsigned int target, nnodes; int i; int nid; - /* - * The barrier will stabilize the nodemask in a register or on - * the stack so that it will stop changing under the code. - * - * Between first_node() and next_node(), pol->nodes could be changed - * by other threads. So we put pol->nodes in a local stack. - */ - barrier(); - nnodes = nodes_weight(nodemask); + nnodes = read_once_policy_nodemask(pol, &nodemask); if (!nnodes) return numa_node_id(); target = ilx % nnodes; -- 2.39.1