From nobody Fri Feb 13 02:48:34 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC1B71BBBDD for ; Tue, 2 Jul 2024 15:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719932430; cv=none; b=ObCbr8daD1iN/5rfnqOw+ppERsAUjbYfjnMqsR9VL1sizuIvz0Tb8KPVVDx7wkH7mKlHv4y3U822djPJNTVhnQUHjvzI6xIw80IWbtr+C7s/8R+NqakJOhP465eqSMsN5b7Ad/T1hQSoP5Jjfo+KdWMdZe9aHiAYKSWxjCvcQ6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719932430; c=relaxed/simple; bh=onnPUMSPdcMeb2P+LxVLpLHZYrff8ueM75bmNfHuAFA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rZqCJD91ni8DeM8UzBzKMRT1CtBG5TgqGokD7raPm7ucQoTOhq5xPZbHfnoG2/MUi+mi91BabVeqPUISLj8m44cbr05yyvgdS6GfU2MxTgZvC30W9mm0Wj/43s8NcIODdXSjXsDGtypN0N7Az53L1icqTMv8oOae3nqplL4A5KU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=LMnmq1BZ; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="LMnmq1BZ" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3Dbalancing:0-1,3 file=3D/usr/bin/cat mapped=3D3 active= =3D0 N0=3D3 kernelpagesize_kB=3D16 ... 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_m= aps") 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 */ =20 /* * 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 =3D 0; static struct mempolicy default_policy =3D { .refcnt =3D ATOMIC_INIT(1), /* never free it */ .mode =3D MPOL_LOCAL, + .flags =3D MPOL_F_KERNEL, }; =20 static struct mempolicy preferred_node_policy[MAX_NUMNODES]; @@ -3095,7 +3096,7 @@ void __init numa_policy_init(void) preferred_node_policy[nid] =3D (struct mempolicy) { .refcnt =3D ATOMIC_INIT(1), .mode =3D MPOL_PREFERRED, - .flags =3D MPOL_F_MOF | MPOL_F_MORON, + .flags =3D MPOL_F_MOF | MPOL_F_MORON | MPOL_F_KERNEL, .nodes =3D nodemask_of_node(nid), }; } @@ -3150,6 +3151,12 @@ static const char * const policy_modes[] =3D [MPOL_PREFERRED_MANY] =3D "prefer (many)", }; =20 +static const char * const policy_flags[] =3D { + [ilog2(MPOL_F_STATIC_NODES)] =3D "static", + [ilog2(MPOL_F_RELATIVE_NODES)] =3D "relative", + [ilog2(MPOL_F_NUMA_BALANCING)] =3D "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 **mp= ol) * @pol: pointer to mempolicy to be formatted * * Convert @pol into a string. If @buffer is too short, truncate the stri= ng. - * 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 f= ew + * node ids. */ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) { char *p =3D buffer; nodemask_t nodes =3D NODE_MASK_NONE; unsigned short mode =3D MPOL_DEFAULT; - unsigned short flags =3D 0; + unsigned long flags =3D 0; =20 - if (pol && pol !=3D &default_policy && !(pol->flags & MPOL_F_MORON)) { + if (!(pol->flags & MPOL_F_KERNEL)) { mode =3D pol->mode; flags =3D pol->flags; } @@ -3328,15 +3336,25 @@ void mpol_to_str(char *buffer, int maxlen, struct m= empolicy *pol) p +=3D snprintf(p, maxlen, "%s", policy_modes[mode]); =20 if (flags & MPOL_MODE_FLAGS) { - p +=3D snprintf(p, buffer + maxlen - p, "=3D"); + unsigned int bit, cnt =3D 0; =20 - /* - * Currently, the only defined flags are mutually exclusive - */ - if (flags & MPOL_F_STATIC_NODES) - p +=3D snprintf(p, buffer + maxlen - p, "static"); - else if (flags & MPOL_F_RELATIVE_NODES) - p +=3D snprintf(p, buffer + maxlen - p, "relative"); + for_each_set_bit(bit, &flags, ARRAY_SIZE(policy_flags)) { + if (bit <=3D ilog2(MPOL_F_KERNEL)) + continue; + + if (cnt =3D=3D 0) + p +=3D snprintf(p, buffer + maxlen - p, "=3D"); + else + p +=3D snprintf(p, buffer + maxlen - p, ","); + + if (WARN_ON_ONCE(!policy_flags[bit])) + p +=3D snprintf(p, buffer + maxlen - p, "bit%u", + bit); + else + p +=3D snprintf(p, buffer + maxlen - p, + policy_flags[bit]); + cnt++; + } } =20 if (!nodes_empty(nodes)) --=20 2.44.0