From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2004BC35274 for ; Tue, 19 Dec 2023 03:09:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 948E18D0005; Mon, 18 Dec 2023 22:09:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D1B98D0001; Mon, 18 Dec 2023 22:09:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74BCA8D0005; Mon, 18 Dec 2023 22:09:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5EF088D0001 for ; Mon, 18 Dec 2023 22:09:22 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38C24A1826 for ; Tue, 19 Dec 2023 03:09:22 +0000 (UTC) X-FDA: 81582086964.15.48E4842 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by imf27.hostedemail.com (Postfix) with ESMTP id 2AA6A40005 for ; Tue, 19 Dec 2023 03:09:18 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LxqE1wVq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.11 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702955359; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MXmjYD6k44ved5U4xKWsccDGtbaRzVjxY3LTUpSA8tU=; b=WFmHCQd5tA50+Hu85ElCIBZTDn+XQsktws/fGAcMu1QBDxdmy8bW/FJz9XE6QV2i/ov9jx sRGG0potgWScqUv6KJOnjBoNJhhhR0DVyEFGYqciPBaaEkW6zwyLbdRWqCNx3o2qkMOoP3 eca0NU6+U+KSglK1hFzoDdMLBNl8sO4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LxqE1wVq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.11 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702955359; a=rsa-sha256; cv=none; b=5kBZYUFdwaNTQWDNAhnL2MsLQe2DurVpBVw8ZsyZynGhrEwnDapX0i5DRnom3nCO978Ip1 gaoj45jRDdvLadJKdeT6TDAJUnzrfDSDIPJAmObFB+W8DWxthS++tITlJ/dMYhlyi1Sh3Q fceDLt65FAc+gvFF33vyiZCGYSZ6vDU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702955360; x=1734491360; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=AktSGCecR1q5QvnpMNfkj4bUsaYN+EPOsjyaNXsUfSE=; b=LxqE1wVq69/Pymy+jWrxtFx775z0lk2aBEGq6HFU4aapY872pgsf69lI n/ZT+qtLxSBtmqZJWkvYkOKBhtyMWETE/exItadqdCvRsZPw3rY6h7lnY KeK7yrXR8kZXGgCiKh6hynRxJzXoGUZp/Nqu+1vMnYi+9uge4KSySwxfe BJyA2qAF/87SFHXi2xv7pVqa5w4Jsqk0Xiqf0ga7NIRtjxCo/wOYQ4JJ9 Vyybb4/Am/HZeOZSYo1pn8tzX+0tk23zLrf4TRJdUrnrdfZqE5YQMg3Aq eDY8TZ/d8TAcsBP+cv378dz+bB8UN8NizWDj3Epom0x07h27eGySY7YH/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2433204" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2433204" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 19:09:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="1107194605" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="1107194605" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 19:09:10 -0800 From: "Huang, Ying" To: Gregory Price Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, akpm@linux-foundation.org, arnd@arndb.de, tglx@linutronix.de, luto@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mhocko@kernel.org, tj@kernel.org, gregory.price@memverge.com, corbet@lwn.net, rakie.kim@sk.com, hyeongtak.ji@sk.com, honggyu.kim@sk.com, vtavarespetr@micron.com, peterz@infradead.org, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com, seungjun.ha@samsung.com Subject: Re: [PATCH v4 11/11] mm/mempolicy: extend set_mempolicy2 and mbind2 to support weighted interleave In-Reply-To: <20231218194631.21667-12-gregory.price@memverge.com> (Gregory Price's message of "Mon, 18 Dec 2023 14:46:31 -0500") References: <20231218194631.21667-1-gregory.price@memverge.com> <20231218194631.21667-12-gregory.price@memverge.com> Date: Tue, 19 Dec 2023 11:07:10 +0800 Message-ID: <87sf3ynb4x.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2AA6A40005 X-Stat-Signature: f1u38eaze1x5z8wcfayrtb5wku3f878o X-HE-Tag: 1702955358-279735 X-HE-Meta: U2FsdGVkX18ce/ZOCPBnw+75Bi7dw8eShT07qg50ARvCR+iFj9KUjeDXNgi3/2eo4QJpDMNSvN44fIAC4tapUaS7sYHGcl6GWOfEeDMQrUjgRXdJc8OUnJ7W73FgBRltKtR7Eh4vK6ovy1AD+ODzn0JfXEBLAF/iz8zTvIwr0oMHVcsrFReVEiegxbXFgwf7qU0ruH4OmFxUXlGH+6ynPFOKSzPxKcwJlS99ivR/ARiSmIOlyAaBDYnwdAM7eC2si4yhhsfHaF0/Bs5cmWmUSsIpKS2SJwP7Wogep+DW83r6naoR1GGNI5vAmFSrsqYQjGB0+R6VaJNbqmPBzbtBNpMKYkiIJkvA9b9M4CqyYa21PwkgKDysYq8bga1zigseL67u98sK4KH5kPou3CllnD3vQvo5cXt/fTnpVnglDl11tR02f7LKeuNatoW+778aY7FHazPF7kj6KyPjx7MxiwVqdeGE39lKnUyzo6WOC+BTRjUyGIlLmKgKSthG6f1BNF+QgRywxP8BpeeTK6Y7lcm4DXjd/Dn1LpYPM1XewcOjyIiB4bwB/LJ3dnrJ6APdHRrGxmV54bXjaM1wRsal5guSEbqCiE2oxMO7JYUEzokdaZx5zXFLZmnjTUWQ9yWSh/0p8MJCOrYPvXzhFGql9WuBdeS3Tn+0hekpFAQI61ZOIMn7CbP45XJAAHvZgat2YRmFSNcZ364TRcbwYPHCA5rj3neh9KxFGLk5TzBISyvyewhvVokFXM5cf9/st9QtGD5Nzfz+van7nw5/2WQxNFmaaVthG48vG6wYHCWLz5+fMF1vGmhe9TrHT0jWt3ixksd5CPZCTPRFh6ggV3EmbBV78GA87RMoUcdzdDdKnD+lbXBWdQ++0i1yN38UkxE+u+1Zx0xhndc9hjmLFIYOpaq7Qdldg3RGQJCSAW/ddVRD4LZiY+BMuWp/fIyyiJUV1vfjziqyIqbzD7llnih rK+BWMLE 4sLNQtOsUITSKDtBLpPpQCoxSSZfJ13K4XpWTcAbofXEPqFHIHyae9kBQHvEjGI1Vp9G0wIDzmJl8xcg6iQrWm0cU/CmdjlW7iQYVDYkGnUWol3D2D+/p2iWBmKI4/6KgrrkjWTKGEMQdjhuq1RIyx44XPS+wgVcd1LmG3iqeuHhJFk4IJrcHg8Dzd10kuH/aRKxKfUuXivyjC+/M75u6pOfmP7oB0AQy/O7VsXyzbF/C0XIC7QcylWah22yWjc+U/sg4D3PrO9X6hy8AOcBlvygrdNi4YR/Zh9ni3AO7jWYUfTcHklAjyguytOJCl+cnFJY0QS8I9sfpd2yZ8h5VYC4XykD5ab7IEKD+vwT6LOKElwvb3s+JOATJeIBp5kdDbTPqQVz9JCbNi/BjXmMoUehfxzfoRUcbAvxlucBJ9mA0TCb6Il/FylWdS3O4L1wTuiMmqskiZkyawz+374tK/FHUiQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gregory Price writes: > Extend set_mempolicy2 and mbind2 to support weighted interleave, and > demonstrate the extensibility of the mpol_args structure. > > To support weighted interleave we add interleave weight fields to the > following structures: > > Kernel Internal: (include/linux/mempolicy.h) > struct mempolicy { > /* task-local weights to apply to weighted interleave */ > unsigned char weights[MAX_NUMNODES]; > } > struct mempolicy_args { > /* Optional: interleave weights for MPOL_WEIGHTED_INTERLEAVE */ > unsigned char *il_weights; /* of size MAX_NUMNODES */ > } > > UAPI: (/include/uapi/linux/mempolicy.h) > struct mpol_args { > /* Optional: interleave weights for MPOL_WEIGHTED_INTERLEAVE */ > unsigned char *il_weights; /* of size pol_max_nodes */ > } > > The task-local weights are a single, one-dimensional array of weights > that apply to all possible nodes on the system. If a node is set in > the mempolicy nodemask, the weight in `il_weights` must be >= 1, > otherwise set_mempolicy2() will return -EINVAL. If a node is not > set in pol_nodemask, the weight will default to `1` in the task policy. > > The default value of `1` is required to handle the situation where a > task migrates to a set of nodes for which weights were not set (up to > and including the local numa node). For example, a migrated task whose > nodemask changes entirely will have all its weights defaulted back > to `1`, or if the nodemask changes to include a mix of nodes that > were not previously accounted for - the weighted interleave may be > suboptimal. > > If migrations are expected, a task should prefer not to use task-local > interleave weights, and instead utilize the global settings for natural > re-weighting on migration. > > To support global vs local weighting, we add the kernel-internal flag: > MPOL_F_GWEIGHT (1 << 5) /* Utilize global weights */ > > This flag is set when il_weights is omitted by set_mempolicy2(), or > when MPOL_WEIGHTED_INTERLEAVE is set by set_mempolicy(). This internal > mode_flag dictates whether global weights or task-local weights are > utilized by the the various weighted interleave functions: > > * weighted_interleave_nodes > * weighted_interleave_nid > * alloc_pages_bulk_array_weighted_interleave > > if (pol->flags & MPOL_F_GWEIGHT) > pol_weights = iw_table; > else > pol_weights = pol->wil.weights; > > To simplify creations and duplication of mempolicies, the weights are > added as a structure directly within mempolicy. This allows the > existing logic in __mpol_dup to copy the weights without additional > allocations: > > if (old == current->mempolicy) { > task_lock(current); > *new = *old; > task_unlock(current); > } else > *new = *old > > Suggested-by: Rakie Kim > Suggested-by: Hyeongtak Ji > Suggested-by: Honggyu Kim > Suggested-by: Vinicius Tavares Petrucci > Signed-off-by: Gregory Price > Co-developed-by: Rakie Kim > Signed-off-by: Rakie Kim > Co-developed-by: Hyeongtak Ji > Signed-off-by: Hyeongtak Ji > Co-developed-by: Honggyu Kim > Signed-off-by: Honggyu Kim > Co-developed-by: Vinicius Tavares Petrucci > Signed-off-by: Vinicius Tavares Petrucci > --- > .../admin-guide/mm/numa_memory_policy.rst | 10 ++ > include/linux/mempolicy.h | 2 + > include/uapi/linux/mempolicy.h | 2 + > mm/mempolicy.c | 129 +++++++++++++++++- > 4 files changed, 139 insertions(+), 4 deletions(-) > > diff --git a/Documentation/admin-guide/mm/numa_memory_policy.rst b/Documentation/admin-guide/mm/numa_memory_policy.rst > index 99e1f732cade..0e91efe9e769 100644 > --- a/Documentation/admin-guide/mm/numa_memory_policy.rst > +++ b/Documentation/admin-guide/mm/numa_memory_policy.rst > @@ -254,6 +254,8 @@ MPOL_WEIGHTED_INTERLEAVE > This mode operates the same as MPOL_INTERLEAVE, except that > interleaving behavior is executed based on weights set in > /sys/kernel/mm/mempolicy/weighted_interleave/ > + when configured to utilize global weights, or based on task-local > + weights configured with set_mempolicy2(2) or mbind2(2). > > Weighted interleave allocations pages on nodes according to > their weight. For example if nodes [0,1] are weighted [5,2] > @@ -261,6 +263,13 @@ MPOL_WEIGHTED_INTERLEAVE > 2 pages allocated on node1. This can better distribute data > according to bandwidth on heterogeneous memory systems. > > + When utilizing task-local weights, weights are not rebalanced > + in the event of a task migration. If a weight has not been > + explicitly set for a node set in the new nodemask, the > + value of that weight defaults to "1". For this reason, if > + migrations are expected or possible, users should consider > + utilizing global interleave weights. > + > NUMA memory policy supports the following optional mode flags: > > MPOL_F_STATIC_NODES > @@ -514,6 +523,7 @@ Extended Mempolicy Arguments:: > __u16 mode_flags; > __s32 home_node; /* mbind2: policy home node */ > __aligned_u64 pol_nodes; /* nodemask pointer */ > + __aligned_u64 il_weights; /* u8 buf of size pol_maxnodes */ > __u64 pol_maxnodes; > __s32 policy_node; /* get_mempolicy2: policy node information */ > }; > diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h > index aeac19dfc2b6..387c5c418a66 100644 > --- a/include/linux/mempolicy.h > +++ b/include/linux/mempolicy.h > @@ -58,6 +58,7 @@ struct mempolicy { > /* Weighted interleave settings */ > struct { > unsigned char cur_weight; > + unsigned char weights[MAX_NUMNODES]; > } wil; > }; > > @@ -70,6 +71,7 @@ struct mempolicy_args { > unsigned short mode_flags; /* policy mode flags */ > int home_node; /* mbind: use MPOL_MF_HOME_NODE */ > nodemask_t *policy_nodes; /* get/set/mbind */ > + unsigned char *il_weights; /* for mode MPOL_WEIGHTED_INTERLEAVE */ > int policy_node; /* get: policy node information */ > }; > > diff --git a/include/uapi/linux/mempolicy.h b/include/uapi/linux/mempolicy.h > index ec1402dae35b..16fedf966166 100644 > --- a/include/uapi/linux/mempolicy.h > +++ b/include/uapi/linux/mempolicy.h > @@ -33,6 +33,7 @@ struct mpol_args { > __u16 mode_flags; > __s32 home_node; /* mbind2: policy home node */ > __aligned_u64 pol_nodes; > + __aligned_u64 il_weights; /* size: pol_maxnodes * sizeof(char) */ > __u64 pol_maxnodes; > __s32 policy_node; /* get_mempolicy: policy node info */ > }; You break the ABI you introduced earlier in the patchset. Although they are done within a patchset, I don't think that it's a good idea. I suggest to finalize the ABI in the first place. Otherwise, people check git log will be confused by ABI broken. This makes it easier to be reviewed too. > @@ -75,6 +76,7 @@ struct mpol_args { > #define MPOL_F_SHARED (1 << 0) /* identify shared policies */ > #define MPOL_F_MOF (1 << 3) /* this policy wants migrate on fault */ > #define MPOL_F_MORON (1 << 4) /* Migrate On protnone Reference On Node */ > +#define MPOL_F_GWEIGHT (1 << 5) /* Utilize global weights */ > > /* > * These bit locations are exposed in the vm.zone_reclaim_mode sysctl -- Best Regards, Huang, Ying [snip]