From patchwork Tue Jul 2 15:00:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13719887 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 5EEBAC3064D for ; Tue, 2 Jul 2024 15:00:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E70EB6B0095; Tue, 2 Jul 2024 11:00:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E20466B0096; Tue, 2 Jul 2024 11:00:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE7AD6B0098; Tue, 2 Jul 2024 11:00:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B03156B0095 for ; Tue, 2 Jul 2024 11:00:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 206F51C0F48 for ; Tue, 2 Jul 2024 15:00:22 +0000 (UTC) X-FDA: 82295123484.10.8230273 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf06.hostedemail.com (Postfix) with ESMTP id B5B6F180024 for ; Tue, 2 Jul 2024 15:00:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=LMnmq1BZ; spf=pass (imf06.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=1719932395; 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=HT85tArOXtaRnXCBCgyxPKfbL7lM00ED4dcauG6uHIY=; b=eh6sEyJeTUtc76LzuqooBAunBeA4gpucrbGAvO3aZ29DsLY0aWREHuGJIqqzB484C2vv1o 3N1aj/YbFx8hN7fwTnmVo/yUXg+OYNxXH8bfFhL39EENG5ClZry3+pnCV8xF6WL2j552/j w1/sdPr1LivlXlpVoy8K5fA2t0Bk7Bk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719932395; a=rsa-sha256; cv=none; b=JD14JGY+bMHQsHfqKepXaOqy679FCm1zEK1maTY65EPj1c1H/mtYwOkcB2s2KwgDwtLwuY QKuOC3WDP3N9Uld1ilGJOzMYUSKevFIoZbMLABRcTPKBgZXOtWe6lGFfeHdZgNbiIQ3lVd 5zTCixwqy7WLevXWKKU6B+rpyl2E93o= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=LMnmq1BZ; spf=pass (imf06.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: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=HT85tArOXtaRnXCBCgyxPKfbL7lM00ED4dcauG6uHIY=; b=LMnmq1BZVOa77QmHew6rpAVYEu Q4GD/NW7P3+7lUcRArQlyUyXVz66S7FyR/FD2I2PGrfhz1aGuHe8/hab+1PbACAkDUYxrQxabBJ6W zid7QGYrQcmqeBuCMcNc6wj7XTV90V5FFZvQ7Al4l/5mFDgzIOnm4xioYuXnMPZX4AOkTECHAWLtm VhmrxzHptzlxRfrDXyMxIW3Sqqbuj55Ga1sHVH3+ZVeReyHIcMrdZAfO3jSeDBfD7DjzIj2uBz/0p en8gxSGMeG3SV1du9ItZrO5IjAD1HZGnktzRAId+KRfCFgYzp20LSdOD/omgYlacffTFXYAOir5Pe 2V60JcAg==; 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 1sOezJ-00ALZH-6S; Tue, 02 Jul 2024 17:00:09 +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 Subject: [PATCH v2] mm/numa_balancing: Teach mpol_to_str about the balancing mode Date: Tue, 2 Jul 2024 16:00:06 +0100 Message-ID: <20240702150006.35206-1-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B5B6F180024 X-Stat-Signature: fosmpnraqxuh3h5ibdsszm5xbujioic3 X-HE-Tag: 1719932417-706960 X-HE-Meta: U2FsdGVkX1/vW0vrSymrI5sX2hMPQcQZPooQvxEWpOExMpJdtT8oCQvuRqrieYFLX0xSu99jQ/qczsG2szhIIx7HXBsrHq1c+i5bZ0PrTsep6oL7Ka7nkSvE3rRsqByT+WPxws5AMJ8LvaSyX8zrkh3CDpPEygGtzbfqKPLAkebmnpg5TrMwjKSBmpLTeZYngUAJGsrIncsnZn3Wwf80OQSRiQ+E5HlER3Px0bc0xPcFiSB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ii6wwAVz7ZXVUxcbZw8CTnNZIUvk+EYZb6Meg3oM1tCEt4hkeGiHEVTzU2zxch9NyxNulb3R7rcb5F5uhLCa/dpDBF6HjKzLkzBf4u9qltr5JFJQRlCnr5wNwHx8ZSJoGGJRq/tQqzD3Tg5CzLkwtzXLnH/GuFqnmU0jW9iFp/SzrirXhHQREHJbbeYzPvPa+DJ9Gveaz1XTTHsTDtw4myUWtD37zrCpZ+D9qUoO/i/fQxxHPyKrbolQZtWKHUkBE8UyKrIHgz3MtRLWoXYQ= 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: First we introduce a new internal flag MPOL_F_KERNEL and with it mark the kernel's internal default and fallback policies (for tasks and/or VMAs with no explicit policy set). By doing this we generalise the current special casing and replace the incorrect 'default' with the correct 'bind'. Secondly, we add a string representation and corresponding handling for MPOL_F_NUMA_BALANCING. We do this by adding a sparse mapping array of flags to names. With the sparseness being the downside, but with the advantage of generalising and removing the "policy" from flags display. End result: $ numactl -b -m 0-1,3 cat /proc/self/numa_maps 555559580000 bind=balancing:0-1,3 file=/usr/bin/cat mapped=3 active=0 N0=3 kernelpagesize_kB=16 ... v2: * Fully fix by introducing MPOL_F_KERNEL. 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 --- include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 44 ++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/uapi/linux/mempolicy.h b/include/uapi/linux/mempolicy.h index 1f9bb10d1a47..bcf56ce9603b 100644 --- a/include/uapi/linux/mempolicy.h +++ b/include/uapi/linux/mempolicy.h @@ -64,6 +64,7 @@ enum { #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_KERNEL (1 << 5) /* Kernel's internal policy */ /* * These bit locations are exposed in the vm.zone_reclaim_mode sysctl diff --git a/mm/mempolicy.c b/mm/mempolicy.c index aec756ae5637..8ecc6d9f100a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -134,6 +134,7 @@ enum zone_type policy_zone = 0; static struct mempolicy default_policy = { .refcnt = ATOMIC_INIT(1), /* never free it */ .mode = MPOL_LOCAL, + .flags = MPOL_F_KERNEL, }; static struct mempolicy preferred_node_policy[MAX_NUMNODES]; @@ -3095,7 +3096,7 @@ void __init numa_policy_init(void) preferred_node_policy[nid] = (struct mempolicy) { .refcnt = ATOMIC_INIT(1), .mode = MPOL_PREFERRED, - .flags = MPOL_F_MOF | MPOL_F_MORON, + .flags = MPOL_F_MOF | MPOL_F_MORON | MPOL_F_KERNEL, .nodes = nodemask_of_node(nid), }; } @@ -3150,6 +3151,12 @@ static const char * const policy_modes[] = [MPOL_PREFERRED_MANY] = "prefer (many)", }; +static const char * const policy_flags[] = { + [ilog2(MPOL_F_STATIC_NODES)] = "static", + [ilog2(MPOL_F_RELATIVE_NODES)] = "relative", + [ilog2(MPOL_F_NUMA_BALANCING)] = "balancing", +}; + #ifdef CONFIG_TMPFS /** * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option. @@ -3293,17 +3300,18 @@ 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) { char *p = buffer; nodemask_t nodes = NODE_MASK_NONE; unsigned short mode = MPOL_DEFAULT; - unsigned short flags = 0; + unsigned long flags = 0; - if (pol && pol != &default_policy && !(pol->flags & MPOL_F_MORON)) { + if (!(pol->flags & MPOL_F_KERNEL)) { mode = pol->mode; flags = pol->flags; } @@ -3328,15 +3336,25 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) p += snprintf(p, maxlen, "%s", policy_modes[mode]); if (flags & MPOL_MODE_FLAGS) { - p += snprintf(p, buffer + maxlen - p, "="); + unsigned int bit, cnt = 0; - /* - * Currently, the only defined flags 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"); + for_each_set_bit(bit, &flags, ARRAY_SIZE(policy_flags)) { + if (bit <= ilog2(MPOL_F_KERNEL)) + continue; + + if (cnt == 0) + p += snprintf(p, buffer + maxlen - p, "="); + else + p += snprintf(p, buffer + maxlen - p, ","); + + if (WARN_ON_ONCE(!policy_flags[bit])) + p += snprintf(p, buffer + maxlen - p, "bit%u", + bit); + else + p += snprintf(p, buffer + maxlen - p, + policy_flags[bit]); + cnt++; + } } if (!nodes_empty(nodes))