From patchwork Mon Jul 8 07:56:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13726263 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 1D6FCC3DA42 for ; Mon, 8 Jul 2024 07:56:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90E586B009B; Mon, 8 Jul 2024 03:56:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BDCA6B009C; Mon, 8 Jul 2024 03:56:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7868A6B009D; Mon, 8 Jul 2024 03:56:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5B0406B009B for ; Mon, 8 Jul 2024 03:56:45 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F2B87A418A for ; Mon, 8 Jul 2024 07:56:44 +0000 (UTC) X-FDA: 82315828728.06.A6CDC8F Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf02.hostedemail.com (Postfix) with ESMTP id 2835480003 for ; Mon, 8 Jul 2024 07:56:42 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=nlspGfP4; spf=pass (imf02.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=1720425388; a=rsa-sha256; cv=none; b=qyFNLqPxprMqXFtHf5ljAk+swA6ZyzUMMbKICgTketSQ65MyYDEDF6xXrKVPB8O48b3UQN e4YpbPpPOwqqecDsecY2nRcxJ8msq9cfBpxD9J2D+CECbewg90uevBV+/3Lm/Kz25HQzTm YpQrEVF8fp20hxg/sCQfWNGFjJXMgS8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=nlspGfP4; spf=pass (imf02.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=1720425388; 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:references:dkim-signature; bh=o1jN8VRyIcfHumRP1KvLwsjLLnt/lHRWuKN52gcpPx4=; b=RXuhkfjEBeUMC3hq+oI6jfZtDqhnnVz2MJS7tkiCcUKTKaYCTEXKcjD/KF6XCgLA3fAKro iw4lnSEE6J+VtY+76GBePH/mvirJKHuFCJ9Sa9C/K9ag1FH3pw5RWLaLGguqy/Nu7mgTXP dh1g/OcjBXw968IGsQHoXvkpgiZEMYw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=o1jN8VRyIcfHumRP1KvLwsjLLnt/lHRWuKN52gcpPx4=; b=nlspGfP4A0tMOtPh4zYnRtT+SI Aj+aSVhrWD2EsHdlmEcTf56+gI+RHP1Pw7kPB/9wGSxS8GBF8rIhDogIfYBnCrB/MSplddEdMSZwK Afmw4YGMHEQ+x4e/Ywx6fPYkn+Rc2vqludS+1MKVYX8U3vkG07sZMNhq/ZBvZUsC7aBFezu821AT2 5Xo75ff7lUw71Bj31K64ognlgrY6qBjjidvVRcNt8Iiu/PpUCaNPWPwDqrqx9IYKTsU40fPVQbtFw Z6mrjJD75z/wUyn90OF2X9J/90XFbcDT1Z3ZiPWTN6bh4ZiPgG0gz4SMrbq9JUZIeSC8Jfrb2yK67 5PcGrOWw==; 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 1sQjEi-00CNGq-2K; Mon, 08 Jul 2024 09:56:36 +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 v4] mm/numa_balancing: Teach mpol_to_str about the balancing mode Date: Mon, 8 Jul 2024 08:56:32 +0100 Message-ID: <20240708075632.95857-1-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Stat-Signature: bzkkwtxqjn7747sjq9y3xj51dgeeokx3 X-Rspamd-Queue-Id: 2835480003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720425402-616844 X-HE-Meta: U2FsdGVkX1/r1/uTH6i+k/q7ipgUeEf5WyPkj5dhO0RHgQCXX16DnPVlKWYjg8DjiCwiGIHzEPoW8QU+fbmD3Xa1r21Zw5Wro7zBtcSka3/RG9Svp63FJgChJ0LlGTu4Of1UdAC4wEI8muy0CMaRQ8hTr7zQ9t9Ezh6cX+5TECC5/exTZ6aDnYpq15RcCeqA17WRROfI64T37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m6eEIwEIBL6KYnSMMO+ISm/1DuBvnJWX2yXdQM/v88PnSq5dCmpePkp9mbgC9GsfcO0bcYhNwSVSZ++H1uA+Lr9escbnay0UDgY8RwDSon2qzKU34upOURhlRHs/GbV4kdqpcq6bOnJ/ef1dWt4Ct4kXNJsgtnV8rcgQSTjHv5J8sajWzD4UhXuD74G8EiLemNaVz8eMgk1mhKV6plsTfldsJQ36TJHz26izRxdnYrg/DcVQrOW9tnX7gCrBkm1khglaagfdtZ67UbTvgE6ZNx1CbuWFsYneeGIiYYnGOyEpzUspDLm02erqu9+XNdLQN22SPP7Tmq0eP2YSN7/2xdc= 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. v4: * Use is_power_of_2. * Use ARRAY_SIZE and update recommended buffer size for two flags. 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+ Reviewed-by: "Huang, Ying" --- mm/mempolicy.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index aec756ae5637..a1bf9aa15c33 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 51 for the longest mode, "weighted + * interleave", plus the longest flag flags, "relative|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[ARRAY_SIZE(preferred_node_policy) - 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 (!is_power_of_2(flags & MPOL_MODE_FLAGS)) + p += snprintf(p, buffer + maxlen - p, "|"); + p += snprintf(p, buffer + maxlen - p, "balancing"); + } } if (!nodes_empty(nodes))