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))