From patchwork Fri Jul 5 14:32:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13725215 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 A43A7C38150 for ; Fri, 5 Jul 2024 14:32:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 022106B00A3; Fri, 5 Jul 2024 10:32:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F162D6B00A4; Fri, 5 Jul 2024 10:32:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8DE56B00A5; Fri, 5 Jul 2024 10:32:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B731F6B00A3 for ; Fri, 5 Jul 2024 10:32:30 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7E54B4019A for ; Fri, 5 Jul 2024 14:32:30 +0000 (UTC) X-FDA: 82305939660.06.7D46800 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf26.hostedemail.com (Postfix) with ESMTP id CF276140024 for ; Fri, 5 Jul 2024 14:32:28 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="SSD/AEN2"; spf=pass (imf26.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720189922; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=opyGsOS5gTWbtKMXLvZ+LW0gPGKD6PmlB4hhJBfIAk8=; b=ZYy/o/EZvVNgh0fls+Ylq+kmh/0HSJ/fD12g4tUWruqU9inLut1pgvBBrVyjsWpJHBuG5y 9he99FExJleI85Hq0B7BGXlc8wcEyFNg3ZXf6KOnAnjxEko+aFyFmwu6FoLJRgQB4G/HCM eYn7GPYu9LNhy8AaXQSthaSeg9KxU4c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720189922; a=rsa-sha256; cv=none; b=eFeR8uF2xR7S1BOyG9XjTsAX1rtFMfgwncxuaaHqO7vX0UCypskYwK/MMHVvmxlI/dbaR5 YJcpVmPd8W3Ot2uvjeyed+/VM0AvagTSPEoBgRWNyewfveywmFJ91+z7hKUEvj5kXEEJbC zyop0nvbF0lVxg0TZ4n2FX/uGIoiRy4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="SSD/AEN2"; spf=pass (imf26.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=opyGsOS5gTWbtKMXLvZ+LW0gPGKD6PmlB4hhJBfIAk8=; b=SSD/AEN2jADr4l9v9RZlVYHvjp A3x45ohowbXs9oFZU/yhviOVuj82gRBjK7bwhk7iCTDR8xiwWXnKQ/eQt7Olz9W38xbiDHyydOxZW gZjuz1slPup83FMr2+8hY6TuqKUPJQYE/Jv7jNzEwzJshwb+/kI/kSb8VPVJqFcMCdGTIQTbphq+C OuQgMuVQvW7S+Nkb/u3eZR+3UCBRfB3y4B2hXr+XVonVsAJTtvgKVawrpJUKBJm2/VGsCSdPVjnPd vi0lMy62mUO9TA2VPdAsQvlrPBW2QssgnqizoscBO/WW2JcM16rU1lBJ5CsYeucffcjnu0Vsr3G8H 28qSEsUg==; Received: from [84.69.19.168] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sPjz3-00BSm3-9U; Fri, 05 Jul 2024 16:32:21 +0200 From: Tvrtko Ursulin To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Tvrtko Ursulin , Huang Ying , Mel Gorman , Peter Zijlstra , Ingo Molnar , Rik van Riel , Johannes Weiner , "Matthew Wilcox (Oracle)" , Dave Hansen , Andi Kleen , Michal Hocko , David Rientjes , stable@vger.kernel.org Subject: [PATCH 1/3] mm/numa_balancing: Teach mpol_to_str about the balancing mode Date: Fri, 5 Jul 2024 15:32:16 +0100 Message-ID: <20240705143218.21258-2-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240705143218.21258-1-tursulin@igalia.com> References: <20240705143218.21258-1-tursulin@igalia.com> MIME-Version: 1.0 X-Stat-Signature: qacprfjgy5ek51b6ibr8hki58wfqkrg8 X-Rspamd-Queue-Id: CF276140024 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720189948-78853 X-HE-Meta: U2FsdGVkX18iIPrgbyLnlorhEINvidJHd1pVu72vvYE2EDo0UTxJpzOSCyhhk1Az1UaUFLp9zv7cJMX96wgkw7v0RRfKec5jAbvcGt3fPPoYJ1ezwQ4h+/vxN2j7tCuSM8KF6C9GnBRlFW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JDgzJIaGyTp5eQscxEhtHxPUC7w0jmTNF/Mcxty1/csEjXJlIzY/M6PU166Q7UKatmxDlsPEQtxCV2jsz23BCrO9W6dKFKJhX0zTf27kOKz6T8KO/hKFpIBCQmdrduBStDz7paGa6xme/Q6jEPA4ALxpRwMApkhK1SpFG+OOCOTF0ulzD2CHp+f5CICBBzDOVEBM6rRt0suypxLpbwwEZdWNc3GxfOCCbymr7GZdmjO4Q1VnKnRfIADc7uOrdur75OaD487o0jKpizr3fNXSsfve+9DQEvNRYVTce/esViq0TO4TYDZ38HRQvVwuC23wC1ghOSqd5XTktYOTJl4thOOcIwUye4IkCuxTYFsw9hONI4XbPjRhkzx26Si1zrkxPOwKJBFjasGy5f8VV84lCojcArxc8bErkNHc= 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: From: Tvrtko Ursulin Since balancing mode was added in bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes"), it was possible to set this mode but it wouldn't be shown in /proc//numa_maps since there was no support for it in the mpol_to_str() helper. Furthermore, because the balancing mode sets the MPOL_F_MORON flag, it would be displayed as 'default' due a workaround introduced a few years earlier in 8790c71a18e5 ("mm/mempolicy.c: fix mempolicy printing in numa_maps"). To tidy this up we implement two changes: Replace the MPOL_F_MORON check by pointer comparison against the preferred_node_policy array. By doing this we generalise the current special casing and replace the incorrect 'default' with the correct 'bind' for the mode. Secondly, we add a string representation and corresponding handling for the MPOL_F_NUMA_BALANCING flag. With the two changes together we start showing the balancing flag when it is set and therefore complete the fix. Representation format chosen is to separate multiple flags with vertical bars, following what existed long time ago in kernel 2.6.25. But as between then and now there wasn't a way to display multiple flags, this patch does not change the format in practice. Some /proc//numa_maps output examples: 555559580000 bind=balancing:0-1,3 file=... 555585800000 bind=balancing|static:0,2 file=... 555635240000 prefer=relative:0 file= v2: * Fully fix by introducing MPOL_F_KERNEL. v3: * Abandoned the MPOL_F_KERNEL approach in favour of pointer comparisons. * Removed lookup generalisation for easier backporting. * Replaced commas as separator with vertical bars. * Added a few more words about the string format in the commit message. Signed-off-by: Tvrtko Ursulin Fixes: bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes") References: 8790c71a18e5 ("mm/mempolicy.c: fix mempolicy printing in numa_maps") Cc: Huang Ying Cc: Mel Gorman Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rik van Riel Cc: Johannes Weiner Cc: "Matthew Wilcox (Oracle)" Cc: Dave Hansen Cc: Andi Kleen Cc: Michal Hocko Cc: David Rientjes Cc: # v5.12+ --- mm/mempolicy.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index aec756ae5637..1bfb6c73a39c 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -3293,8 +3293,9 @@ int mpol_parse_str(char *str, struct mempolicy **mpol) * @pol: pointer to mempolicy to be formatted * * Convert @pol into a string. If @buffer is too short, truncate the string. - * Recommend a @maxlen of at least 32 for the longest mode, "interleave", the - * longest flag, "relative", and to display at least a few node ids. + * Recommend a @maxlen of at least 42 for the longest mode, "weighted + * interleave", the longest flag, "balancing", and to display at least a few + * node ids. */ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) { @@ -3303,7 +3304,10 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) unsigned short mode = MPOL_DEFAULT; unsigned short flags = 0; - if (pol && pol != &default_policy && !(pol->flags & MPOL_F_MORON)) { + if (pol && + pol != &default_policy && + !(pol >= &preferred_node_policy[0] && + pol <= &preferred_node_policy[MAX_NUMNODES - 1])) { mode = pol->mode; flags = pol->flags; } @@ -3331,12 +3335,18 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) p += snprintf(p, buffer + maxlen - p, "="); /* - * Currently, the only defined flags are mutually exclusive + * Static and relative are mutually exclusive. */ if (flags & MPOL_F_STATIC_NODES) p += snprintf(p, buffer + maxlen - p, "static"); else if (flags & MPOL_F_RELATIVE_NODES) p += snprintf(p, buffer + maxlen - p, "relative"); + + if (flags & MPOL_F_NUMA_BALANCING) { + if (hweight16(flags & MPOL_MODE_FLAGS) > 1) + p += snprintf(p, buffer + maxlen - p, "|"); + p += snprintf(p, buffer + maxlen - p, "balancing"); + } } if (!nodes_empty(nodes)) From patchwork Fri Jul 5 14:32:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13725213 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 50E9FC3271E for ; Fri, 5 Jul 2024 14:32:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C06F26B00A1; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB6FF6B00A2; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E6D96B00A4; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 73BC06B00A1 for ; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F61D4018D for ; Fri, 5 Jul 2024 14:32:28 +0000 (UTC) X-FDA: 82305939576.13.C16F886 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf28.hostedemail.com (Postfix) with ESMTP id 7AA58C0006 for ; Fri, 5 Jul 2024 14:32:25 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=ibShQAqn; spf=pass (imf28.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720189910; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vlhZyqR/0gBL25Tskih19pvHfLCMomlyzy7IQpXMJFc=; b=kfpTfkcodgKVYySIM2Tyom6jqJcuOSSTqvyGYJ38l0lfgDR3O3RcDdhtU5HCZtOXd/q13F cxOUOzRLUeZ50xV5ML13N1IbGooueBoG7ogVH1satkvhQ/CXkjvOahP0Ncw/lnmWzdUepP wh50oHIg67d8Inlif/W1CAbJ8X3pwes= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=ibShQAqn; spf=pass (imf28.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720189910; a=rsa-sha256; cv=none; b=IQYQJbI6xGDSsHE5DtSMYC3qxjbL+oZgOB3vXyS3ZBhaN9/I1xYA0SrdHrB3KKYmjIpg7U CG3UtDUPzAaicpAl0MEfvopcyZ2NtuKrmvcaB463H1BDCnVnOLLUtHEHA0j2eCgiJqjHZL UhecqEByUnKCzIcLwtv8KajkUjTEVEU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=vlhZyqR/0gBL25Tskih19pvHfLCMomlyzy7IQpXMJFc=; b=ibShQAqn8rMZi0rHJYdxrpgBNp Dc/vBE6tzbu6t4UzIrLp8uxUpBrXsI1TJ5rP3mHPdrkRqlyEjzZJDMLD8MI+ksgbHtJFGyHEK59uz KXSTe+/otO9hGmMmGeOUsn7oPBohNzo0V4oKl8kQUEXNad2LxB5RLpSax9EQEbaj0ochtT6SbhsAP 5RsJpwRKKqU6VsdJrqqyM6VdQyPovE/ZeqJd/Hs1f7cGRJ0CMZmykeTvmBR4SESy1RqHYzLFbi9eC mgWC6yOfjEzvFAKhwqpq5/frOIYED6RkUuFpDavhVXZ5+z6Z9Pl21sA3fuIdqXTeFiPmBSPjoIEuh t1F7weyA==; Received: from [84.69.19.168] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sPjz3-00BSmD-VJ; Fri, 05 Jul 2024 16:32:22 +0200 From: Tvrtko Ursulin To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Tvrtko Ursulin , Huang Ying , Andrew Morton Subject: [PATCH 2/3] mm/mempolicy: Use flags lookup array in mpol_to_str Date: Fri, 5 Jul 2024 15:32:17 +0100 Message-ID: <20240705143218.21258-3-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240705143218.21258-1-tursulin@igalia.com> References: <20240705143218.21258-1-tursulin@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7AA58C0006 X-Stat-Signature: zcr93mz19f7frnwhog8y1579wm85fxxp X-Rspam-User: X-HE-Tag: 1720189945-566978 X-HE-Meta: U2FsdGVkX19vv3ol0Sufaq9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2AJx2gtvp9BBTzXB5WBJU0Exx89C08S71npNvP1XksjjmR2mEOQdbDB7IOUh/2mr3QSZvj+LdgwjReXETTHb99bpmAfLaQ1evaT6RXXnQK7rgh894sERyy5RnoOcUayWfKdFl5SoAyB3iU6/+0CqFktp1dOB+yTTVckEBQQR9lzgE4InHDg5L4diCwNBasKwoyATKNdVZ2Ek7dnDPmHQP6W6zZdbToncGe19kyDR1 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: From: Tvrtko Ursulin Generalise displaying of flags in mpol_to_str() with the benefit of removing the knowledge of which flags are mutually exclusive and which are not. Also add a warning for unknown flags which slightly "hardens" against possible future omissions to add handling for new stuff, as had happened in bda420b98505. Simplify by switching to scnprintf while at it. Signed-off-by: Tvrtko Ursulin References: bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes") Cc: Huang Ying Cc: Andrew Morton --- mm/mempolicy.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 1bfb6c73a39c..77488878d8ca 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -3150,6 +3150,17 @@ static const char * const policy_modes[] = [MPOL_PREFERRED_MANY] = "prefer (many)", }; +/* + * Lookup array containing only uapi flags where the lowest user flag starts at + * array index zero. + */ +#define MPOL_FLAG_STR_INDEX(f) (ilog2(f) - __builtin_ffs(MPOL_MODE_FLAGS) + 1) +static const char * const policy_flags[] = { + [MPOL_FLAG_STR_INDEX(MPOL_F_STATIC_NODES)] = "static", + [MPOL_FLAG_STR_INDEX(MPOL_F_RELATIVE_NODES)] = "relative", + [MPOL_FLAG_STR_INDEX(MPOL_F_NUMA_BALANCING)] = "balancing", +}; + #ifdef CONFIG_TMPFS /** * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option. @@ -3302,14 +3313,21 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) char *p = buffer; nodemask_t nodes = NODE_MASK_NONE; unsigned short mode = MPOL_DEFAULT; - unsigned short flags = 0; + unsigned int bit, cnt; + unsigned long flags = 0; + int res; if (pol && pol != &default_policy && !(pol >= &preferred_node_policy[0] && pol <= &preferred_node_policy[MAX_NUMNODES - 1])) { mode = pol->mode; - flags = pol->flags; + /* + * Filter out internal flags and also move user flags to lsb for + * easy lookup, matching the policy_flags[] indices. + */ + flags = (pol->flags & MPOL_MODE_FLAGS) >> + __ffs(MPOL_MODE_FLAGS); } switch (mode) { @@ -3329,29 +3347,31 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) return; } - p += snprintf(p, maxlen, "%s", policy_modes[mode]); + res = scnprintf(p, maxlen, "%s", policy_modes[mode]); + p += res; + maxlen -= res; - if (flags & MPOL_MODE_FLAGS) { - p += snprintf(p, buffer + maxlen - p, "="); + cnt = 0; + for_each_set_bit(bit, &flags, + __fls(MPOL_MODE_FLAGS) - __ffs(MPOL_MODE_FLAGS) + 1) { + char prefix; - /* - * Static and relative are mutually exclusive. - */ - if (flags & MPOL_F_STATIC_NODES) - p += snprintf(p, buffer + maxlen - p, "static"); - else if (flags & MPOL_F_RELATIVE_NODES) - p += snprintf(p, buffer + maxlen - p, "relative"); + if (WARN_ON_ONCE(bit >= ARRAY_SIZE(policy_flags) || + !policy_flags[bit])) + continue; - if (flags & MPOL_F_NUMA_BALANCING) { - if (hweight16(flags & MPOL_MODE_FLAGS) > 1) - p += snprintf(p, buffer + maxlen - p, "|"); - p += snprintf(p, buffer + maxlen - p, "balancing"); - } + if (cnt++ == 0) + prefix = '='; + else + prefix = '|'; + + res = scnprintf(p, maxlen, "%c%s", prefix, policy_flags[bit]); + p += res; + maxlen -= res; } if (!nodes_empty(nodes)) - p += scnprintf(p, buffer + maxlen - p, ":%*pbl", - nodemask_pr_args(&nodes)); + scnprintf(p, maxlen, ":%*pbl", nodemask_pr_args(&nodes)); } #ifdef CONFIG_SYSFS From patchwork Fri Jul 5 14:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13725212 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 15288C30658 for ; Fri, 5 Jul 2024 14:32:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C2606B009B; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A4396B00A2; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 611966B00A2; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 413F36B009B for ; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9325FC0198 for ; Fri, 5 Jul 2024 14:32:27 +0000 (UTC) X-FDA: 82305939534.24.D5C7C3A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf13.hostedemail.com (Postfix) with ESMTP id 856B120006 for ; Fri, 5 Jul 2024 14:32:24 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=b3GATmHf; spf=pass (imf13.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720189932; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X9c/u6IuXuq2ptbPAeOOtmwLogxWpVC5JfaFfXThbYE=; b=MOE9Y9sZixJ/mqImme7e2Z6xJxUNInZ5QVcRoUTxrFSRT4m6DOef8P+/vuiUcdZhFjw+z7 AK4lvh+O+wTNvCgu/01La9whaQ3jPMwGnMZfl3G5gKmtbnSAQKMI6fr7JWmivjKtVIR/fR trTZ9Sn+0eMSzxfwfNZxmoGFULbXTZU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=b3GATmHf; spf=pass (imf13.hostedemail.com: domain of tursulin@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=tursulin@igalia.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720189932; a=rsa-sha256; cv=none; b=ZmIbPnRNZ82QK7cCOlreg/vSUe7FSI/7yuLZPHmLSVh7KjQsU716VNFhWmJ2541Lnfof9z 6yM/yMFJU6PQx86yEt8/CeUibhTLn/BIbHdGPTsTeU/j7XGkVu4ZkeC8afwXOwYr+lCN5t CdemmBqUfWYrr58f14pjlCimRtAZYBg= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=X9c/u6IuXuq2ptbPAeOOtmwLogxWpVC5JfaFfXThbYE=; b=b3GATmHfgG6uiSUsA/BE4oaTAc ocRd/ku6O1BJr3nnBdT4hcU7LTOId5yDdR8quv89XJuYtuk/RhaYVhxyZlCJUePqHHWIsL6nogU0q //UXJUizDKBktOW78ckQXBeHvDXF13kjrBRr57dlNq+rIzW34X7A/3SDdNzhEK9T+dk3Sj3ZI8QGb 4TdwwsrggRXgY4xmqwKm/5GPjboSfKt18S21gDeC6yDcutJJiG0QsVeent6LyKQ3VmJPgHvlIGo4t uNEfO8WCwyOo6qFdr3Rmnx7uCnrWRdrmhgen/Ywt0JrZN+ahZFuSExlpsNYvtMMZP6tl+i7Tk7nER 53YrOwxA==; Received: from [84.69.19.168] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sPjz4-00BSmO-LD; Fri, 05 Jul 2024 16:32:22 +0200 From: Tvrtko Ursulin To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Tvrtko Ursulin , Huang Ying , Hugh Dickins , Andrew Morton Subject: [PATCH 3/3] mm/numa_balancing: Allow setting numa balancing for tmpfs Date: Fri, 5 Jul 2024 15:32:18 +0100 Message-ID: <20240705143218.21258-4-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240705143218.21258-1-tursulin@igalia.com> References: <20240705143218.21258-1-tursulin@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 856B120006 X-Stat-Signature: awwfareabeog1pkghapxfmi3gyxc4a63 X-HE-Tag: 1720189944-19482 X-HE-Meta: U2FsdGVkX1/y0znOVyAy59gkkVnXF7A0fEkpaqO5kXWHr9n1BmPtE9LeEYoo/WW0z7YUhuy6yAtJ3SiUL22MQWolpH/zUevifzbyQb11Pzis9yZSGjAI7gImWgpsk46C8OUC4EswTUiITgLQTjzv54FtkUKQFyHoh4CA26OULL/PhXwRNJGkX1D8XanD8QqV/mzpsvHD9DB6LxDdOXCE/Yt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4GhijyMPIpZ2dPGBKy+DFF5TUQKD7pPwglWcpwWPouiGEFvrj2nSxpROGa8RGgV+Hf5jhmV7nbkIcXhigtjVUGQ33 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: From: Tvrtko Ursulin Since MPOL_F_NUMA_BALANCING was added some time ago, lets also recognise it as a valid tmpfs mount option. As an extension to the exiting format: mpol=[=][:nodelist] Multiple flags are added in a list separated by vertical bars, such as: mpol=[=[|]...][:nodelist] For example: $ mount none -t tmpfs mnt -o mpol=bind=balancing:2,0 $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=bind=balancing:0,2) Or: $ mount none mnt -t tmpfs -o "mpol=bind=balancing|static:1,0" $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=bind=balancing|static:0-1) I am not sure to be honest if this is useful for tmpfs, but is just an asymmetry I noticed while doing stuff in this area. Signed-off-by: Tvrtko Ursulin Cc: Huang Ying Cc: Hugh Dickins Cc: Andrew Morton --- mm/mempolicy.c | 55 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 77488878d8ca..c69bf5438731 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -3162,6 +3162,47 @@ static const char * const policy_flags[] = { }; #ifdef CONFIG_TMPFS +static int mpol_lookup_flag(char *str) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(policy_flags); i++) { + if (policy_flags[i] && !strcmp(str, policy_flags[i])) + return BIT(i + __ffs(MPOL_MODE_FLAGS)); + } + + return -1; +} + +static bool mpol_parse_flags(char *str, int *mode, unsigned short *flags) +{ + char buf[128], *opt; + int flag; + + /* Make a local copy since caller wants the original untouched. */ + if (WARN_ON_ONCE(strscpy(buf, str, sizeof(buf)) < 0)) + return false; + + str = buf; + for (;;) { + opt = strsep(&str, "|"); + + if (!opt) + break; + else if (*opt == '\0') + continue; + + flag = mpol_lookup_flag(opt); + if (flag < 0) + return false; + *flags |= flag; + } + + *mode |= *flags; + + return sanitize_mpol_flags(mode, flags) == 0; +} + /** * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option. * @str: string containing mempolicy to parse @@ -3247,18 +3288,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol) } mode_flags = 0; - if (flags) { - /* - * Currently, we only support two mutually exclusive - * mode flags. - */ - if (!strcmp(flags, "static")) - mode_flags |= MPOL_F_STATIC_NODES; - else if (!strcmp(flags, "relative")) - mode_flags |= MPOL_F_RELATIVE_NODES; - else - goto out; - } + if (flags && !mpol_parse_flags(flags, &mode, &mode_flags)) + goto out; new = mpol_new(mode, mode_flags, &nodes); if (IS_ERR(new))