From nobody Sat Feb 7 07:10:12 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 D378616B39C; Fri, 5 Jul 2024 14:32:34 +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=1720189958; cv=none; b=DEcdRi0oxksMCPtaYFtSq42WsIMYoMcONsn+6euvfb4azxww+n5NNz6JR7p/vJubLi2CkTyB8ut8Rkm0wekWOD6jj7GZMA4CFP+kIkXTLvk3kMeL/EeAqhebsU4PyWxyqvc44Uj+2JCyP8ibFS0liZuSMWSkwqWdM0AVYhV1+jY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720189958; c=relaxed/simple; bh=dMEv2jfhQay1PRP0F8D7K+qHB8tPJsk6OTg6yexz3CE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=us+gauA6OQuiVz1N92h6t4A28lgLqeND/BNTon+UV9i2KOUu7by5pIx4/RL1lbAADPlWMl+/qQ7FIa+qeetP6f90klN1GXYjAnebQg9ww7Zo1zTMIF9TahFT6HE9876cuXXVuYt3JRQoQfBExJ5PMo04t30lYxxg97zAi7MitzQ= 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=SSD/AEN2; 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="SSD/AEN2" 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> 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: 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=3Dbalancing:0-1,3 file=3D... 555585800000 bind=3Dbalancing|static:0,2 file=3D... 555635240000 prefer=3Drelative:0 file=3D 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_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 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 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) { @@ -3303,7 +3304,10 @@ void mpol_to_str(char *buffer, int maxlen, struct me= mpolicy *pol) unsigned short mode =3D MPOL_DEFAULT; unsigned short flags =3D 0; =20 - if (pol && pol !=3D &default_policy && !(pol->flags & MPOL_F_MORON)) { + if (pol && + pol !=3D &default_policy && + !(pol >=3D &preferred_node_policy[0] && + pol <=3D &preferred_node_policy[MAX_NUMNODES - 1])) { mode =3D pol->mode; flags =3D pol->flags; } @@ -3331,12 +3335,18 @@ void mpol_to_str(char *buffer, int maxlen, struct m= empolicy *pol) p +=3D snprintf(p, buffer + maxlen - p, "=3D"); =20 /* - * Currently, the only defined flags are mutually exclusive + * Static and relative 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"); + + if (flags & MPOL_F_NUMA_BALANCING) { + if (hweight16(flags & MPOL_MODE_FLAGS) > 1) + p +=3D snprintf(p, buffer + maxlen - p, "|"); + p +=3D snprintf(p, buffer + maxlen - p, "balancing"); + } } =20 if (!nodes_empty(nodes)) --=20 2.44.0 From nobody Sat Feb 7 07:10:12 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 4C7B3146A8A for ; Fri, 5 Jul 2024 14:32:29 +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=1720189953; cv=none; b=Te9AGCErodt5RU0XzrpejMZA3kZBec+B49/i+p/FManP6mGn0HU2/gdAVDbxvw7LSb9nMz7Y46FVEYtcl24jcUMw+df1LsTnYEVyUFAXGUgXwO2mrAGQGCKTTFG1zWZpcHjMiEsaeAIDFFf14ds+sqPEDmpxv2dxRlfYkoUHrgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720189953; c=relaxed/simple; bh=9H/O2JY4DV6l2HQGm8/l2N3lTP0ROhBdceH6cdS5zsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s4Ol+aWYpxj92Hioqwchm44lslE9941oEXNaFxbCFTHnizNmr1NUNa4ldyagoz/9+P2MgIotfLOu552jI/5tISFk7gMoTGIcBKfUfDV3s3PIHfCdJkrtDtK/h4LxvT5etdeDp/hxQaLhpLcnT4V8C6uqUvoHTwIAHPq3kG6j6sY= 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=ibShQAqn; 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="ibShQAqn" 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> 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 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[] =3D [MPOL_PREFERRED_MANY] =3D "prefer (many)", }; =20 +/* + * Lookup array containing only uapi flags where the lowest user flag star= ts at + * array index zero. + */ +#define MPOL_FLAG_STR_INDEX(f) (ilog2(f) - __builtin_ffs(MPOL_MODE_FLAGS) = + 1) +static const char * const policy_flags[] =3D { + [MPOL_FLAG_STR_INDEX(MPOL_F_STATIC_NODES)] =3D "static", + [MPOL_FLAG_STR_INDEX(MPOL_F_RELATIVE_NODES)] =3D "relative", + [MPOL_FLAG_STR_INDEX(MPOL_F_NUMA_BALANCING)] =3D "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 m= empolicy *pol) char *p =3D buffer; nodemask_t nodes =3D NODE_MASK_NONE; unsigned short mode =3D MPOL_DEFAULT; - unsigned short flags =3D 0; + unsigned int bit, cnt; + unsigned long flags =3D 0; + int res; =20 if (pol && pol !=3D &default_policy && !(pol >=3D &preferred_node_policy[0] && pol <=3D &preferred_node_policy[MAX_NUMNODES - 1])) { mode =3D pol->mode; - flags =3D pol->flags; + /* + * Filter out internal flags and also move user flags to lsb for + * easy lookup, matching the policy_flags[] indices. + */ + flags =3D (pol->flags & MPOL_MODE_FLAGS) >> + __ffs(MPOL_MODE_FLAGS); } =20 switch (mode) { @@ -3329,29 +3347,31 @@ void mpol_to_str(char *buffer, int maxlen, struct m= empolicy *pol) return; } =20 - p +=3D snprintf(p, maxlen, "%s", policy_modes[mode]); + res =3D scnprintf(p, maxlen, "%s", policy_modes[mode]); + p +=3D res; + maxlen -=3D res; =20 - if (flags & MPOL_MODE_FLAGS) { - p +=3D snprintf(p, buffer + maxlen - p, "=3D"); + cnt =3D 0; + for_each_set_bit(bit, &flags, + __fls(MPOL_MODE_FLAGS) - __ffs(MPOL_MODE_FLAGS) + 1) { + char prefix; =20 - /* - * Static and relative 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"); + if (WARN_ON_ONCE(bit >=3D ARRAY_SIZE(policy_flags) || + !policy_flags[bit])) + continue; =20 - if (flags & MPOL_F_NUMA_BALANCING) { - if (hweight16(flags & MPOL_MODE_FLAGS) > 1) - p +=3D snprintf(p, buffer + maxlen - p, "|"); - p +=3D snprintf(p, buffer + maxlen - p, "balancing"); - } + if (cnt++ =3D=3D 0) + prefix =3D '=3D'; + else + prefix =3D '|'; + + res =3D scnprintf(p, maxlen, "%c%s", prefix, policy_flags[bit]); + p +=3D res; + maxlen -=3D res; } =20 if (!nodes_empty(nodes)) - p +=3D scnprintf(p, buffer + maxlen - p, ":%*pbl", - nodemask_pr_args(&nodes)); + scnprintf(p, maxlen, ":%*pbl", nodemask_pr_args(&nodes)); } =20 #ifdef CONFIG_SYSFS --=20 2.44.0 From nobody Sat Feb 7 07:10:12 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 D90D514EC59 for ; Fri, 5 Jul 2024 14:32:30 +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=1720189955; cv=none; b=YDjawBANhviIoIa5W2smhWiQ16t8pcdjqRZI8k2rhiEq858R6k1tW40+sXikVSjq/WmpgSGB5rNdhayj/y9/wQS+jWP/8aj7fixYn1kr/AICRYW4NOALfhydS0qBrx6ng8aWUfY4KaaZGoXl4e+T+JxmQXY3KUL8voHcXE4MS9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720189955; c=relaxed/simple; bh=nRT+7uGsgvVH044fBhhlruyNOC/hoIX0xrUTGlz2j2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mAdQsU5LeAvSFHOBj5badI0/rGVTJH5OkF3sJo78J/rjOnHD+bZeQBBvG/4Id0mvdBekq2HCCU1MW1MIVW43bVYtRNEHA885ndOtVJ9wPs8bj/d9vT35qRSsF4TXs6pNyIXrBsFvJhfQZH0aqKqdXOUSuMlCc4MKAdtARFJU2sU= 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=b3GATmHf; 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="b3GATmHf" 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> 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 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=3D[=3D][:nodelist] Multiple flags are added in a list separated by vertical bars, such as: mpol=3D[=3D[|]...][:nodelist] For example: $ mount none -t tmpfs mnt -o mpol=3Dbind=3Dbalancing:2,0 $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=3Dbind=3Dbalancing:0,2) Or: $ mount none mnt -t tmpfs -o "mpol=3Dbind=3Dbalancing|static:1,0" $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=3Dbind=3Dbalancing|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[] =3D { }; =20 #ifdef CONFIG_TMPFS +static int mpol_lookup_flag(char *str) +{ + int i; + + for (i =3D 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 =3D buf; + for (;;) { + opt =3D strsep(&str, "|"); + + if (!opt) + break; + else if (*opt =3D=3D '\0') + continue; + + flag =3D mpol_lookup_flag(opt); + if (flag < 0) + return false; + *flags |=3D flag; + } + + *mode |=3D *flags; + + return sanitize_mpol_flags(mode, flags) =3D=3D 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 **mpo= l) } =20 mode_flags =3D 0; - if (flags) { - /* - * Currently, we only support two mutually exclusive - * mode flags. - */ - if (!strcmp(flags, "static")) - mode_flags |=3D MPOL_F_STATIC_NODES; - else if (!strcmp(flags, "relative")) - mode_flags |=3D MPOL_F_RELATIVE_NODES; - else - goto out; - } + if (flags && !mpol_parse_flags(flags, &mode, &mode_flags)) + goto out; =20 new =3D mpol_new(mode, mode_flags, &nodes); if (IS_ERR(new)) --=20 2.44.0