From patchwork Fri Jul 5 14:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13725212 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 15288C30658 for ; Fri, 5 Jul 2024 14:32:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C2606B009B; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A4396B00A2; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 611966B00A2; Fri, 5 Jul 2024 10:32:28 -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 413F36B009B for ; Fri, 5 Jul 2024 10:32:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9325FC0198 for ; Fri, 5 Jul 2024 14:32:27 +0000 (UTC) X-FDA: 82305939534.24.D5C7C3A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf13.hostedemail.com (Postfix) with ESMTP id 856B120006 for ; Fri, 5 Jul 2024 14:32:24 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=b3GATmHf; spf=pass (imf13.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=1720189932; 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=X9c/u6IuXuq2ptbPAeOOtmwLogxWpVC5JfaFfXThbYE=; b=MOE9Y9sZixJ/mqImme7e2Z6xJxUNInZ5QVcRoUTxrFSRT4m6DOef8P+/vuiUcdZhFjw+z7 AK4lvh+O+wTNvCgu/01La9whaQ3jPMwGnMZfl3G5gKmtbnSAQKMI6fr7JWmivjKtVIR/fR trTZ9Sn+0eMSzxfwfNZxmoGFULbXTZU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=b3GATmHf; spf=pass (imf13.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=1720189932; a=rsa-sha256; cv=none; b=ZmIbPnRNZ82QK7cCOlreg/vSUe7FSI/7yuLZPHmLSVh7KjQsU716VNFhWmJ2541Lnfof9z 6yM/yMFJU6PQx86yEt8/CeUibhTLn/BIbHdGPTsTeU/j7XGkVu4ZkeC8afwXOwYr+lCN5t CdemmBqUfWYrr58f14pjlCimRtAZYBg= 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> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 856B120006 X-Stat-Signature: awwfareabeog1pkghapxfmi3gyxc4a63 X-HE-Tag: 1720189944-19482 X-HE-Meta: U2FsdGVkX1/y0znOVyAy59gkkVnXF7A0fEkpaqO5kXWHr9n1BmPtE9LeEYoo/WW0z7YUhuy6yAtJ3SiUL22MQWolpH/zUevifzbyQb11Pzis9yZSGjAI7gImWgpsk46C8OUC4EswTUiITgLQTjzv54FtkUKQFyHoh4CA26OULL/PhXwRNJGkX1D8XanD8QqV/mzpsvHD9DB6LxDdOXCE/YtuyYwY/rJgU+Z7CjRA6EoEJFXayWvEpPLu/+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wWPouiGEFvrj2nSxpROGa8RGgV+Hf5jhmV7nbkIcXhigtjVUGQ33 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 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=[=][:nodelist] Multiple flags are added in a list separated by vertical bars, such as: mpol=[=[|]...][:nodelist] For example: $ mount none -t tmpfs mnt -o mpol=bind=balancing:2,0 $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=bind=balancing:0,2) Or: $ mount none mnt -t tmpfs -o "mpol=bind=balancing|static:1,0" $ mount | grep mpol none on ... type tmpfs (rw,relatime,mpol=bind=balancing|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[] = { }; #ifdef CONFIG_TMPFS +static int mpol_lookup_flag(char *str) +{ + int i; + + for (i = 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 = buf; + for (;;) { + opt = strsep(&str, "|"); + + if (!opt) + break; + else if (*opt == '\0') + continue; + + flag = mpol_lookup_flag(opt); + if (flag < 0) + return false; + *flags |= flag; + } + + *mode |= *flags; + + return sanitize_mpol_flags(mode, flags) == 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 **mpol) } mode_flags = 0; - if (flags) { - /* - * Currently, we only support two mutually exclusive - * mode flags. - */ - if (!strcmp(flags, "static")) - mode_flags |= MPOL_F_STATIC_NODES; - else if (!strcmp(flags, "relative")) - mode_flags |= MPOL_F_RELATIVE_NODES; - else - goto out; - } + if (flags && !mpol_parse_flags(flags, &mode, &mode_flags)) + goto out; new = mpol_new(mode, mode_flags, &nodes); if (IS_ERR(new))