From mboxrd@z Thu Jan 1 00:00:00 1970 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 9F122C27C40 for ; Wed, 22 Nov 2023 21:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00F316B061E; Wed, 22 Nov 2023 16:12:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F00B66B0632; Wed, 22 Nov 2023 16:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA1AE6B0633; Wed, 22 Nov 2023 16:12:08 -0500 (EST) 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 CB9646B061E for ; Wed, 22 Nov 2023 16:12:08 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B17B40A90 for ; Wed, 22 Nov 2023 21:12:08 +0000 (UTC) X-FDA: 81486837936.26.C8D5A72 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf08.hostedemail.com (Postfix) with ESMTP id AC524160020 for ; Wed, 22 Nov 2023 21:12:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KWOro+W0; spf=pass (imf08.hostedemail.com: domain of gourry.memverge@gmail.com designates 209.85.210.193 as permitted sender) smtp.mailfrom=gourry.memverge@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700687526; 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=ndk4aGNdhF9GXKkpyyjsozTJ5amtXqJPp+cG2mKjtD0=; b=HQY15YZOGn08j13iHu+h76vZkqvau7dlnQLTCP35UlwZt944ITOqcidch3U7/B2BNy5v/W WTDmnBTjzEsUjmnyHF3PmT8O7utQF8Rr8x4+QnGF5KDCwjnJ7mQEjl//vjEjuszFifYp+D 5bLLeETcimK+jUapXMniV3eo/+Wkdeo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700687526; a=rsa-sha256; cv=none; b=IvbRj1Wx20swcUO40F8/j7nRdcN1vY/LA5/jIb+ok2MLUzWclDeMEhNHDUIlGsmfoa7RyW iTVcdpGGvZWEyMBcm49+LnYOLaKqpRCLBwQgOOicvJU3DnI0pvJ6maecC68xQZEL+LLdj6 7ZVUDrt9vKePHbJPWUrAD/FC4qAEtqQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KWOro+W0; spf=pass (imf08.hostedemail.com: domain of gourry.memverge@gmail.com designates 209.85.210.193 as permitted sender) smtp.mailfrom=gourry.memverge@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-6c33ab26dddso245727b3a.0 for ; Wed, 22 Nov 2023 13:12:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700687525; x=1701292325; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ndk4aGNdhF9GXKkpyyjsozTJ5amtXqJPp+cG2mKjtD0=; b=KWOro+W0SoIAS6DJy7moNIsoGq8/jr5akKfMuV8zcoHg4nXIlTEP4ZMGwvyEJeTxZs XKjSC6zmkFOt7XPrndX7z171W3xlm+E/Z4EgtBi8crdXSxeO8Agr+Yzz2ISyjHyeu2b5 IXDS/bmjImM8s2rANLpLbB6RwUWQ+GQMFUbRynp25VfLyeM4m7YXO6S/WoXdfMu653pu 0q0TABUTKtzfgU737D73tYbh3e7zd35QNRwJTt/A3T9AxxY9tRWM6lc6opB/i0L9kNwN kuBGM5EDXsJpkWkmcU1WinsahU5XB8NJ41N3xTUYC9A5ZJcWUMD4SYpjBqkhUuULCfF/ zb3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700687525; x=1701292325; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ndk4aGNdhF9GXKkpyyjsozTJ5amtXqJPp+cG2mKjtD0=; b=TJKiOkyxUi4Jxl2MKVdoD3RL+P+B9QfVr5maoz2mUpKaGBHixjWFQPbrcPccSQdI0c euhr1jUreMPQcaYs5qFUlJ8MxHZBsPNKhOQkku24FeKdP6FRNCHpAEWYbkxaWLQipK10 RHTDc/z22KWqhz8g1Zk8IIIeOyB9ZVYOsghXwuuiIai18X7JMWZR/4f4lLGaEVxcSKtI aJa+rXz6xetchXzRpqw9A2pv8FY6znLuYyXpdvX1V1EAGvaCCEd09nJQqkyDOtUbSIf2 hHGIbQ1wOjRZdxvodGm1WEBzFzcxrYYSCLt+hK42PaTXDcYdiEeGbUTBV/GB2R16ylkd sbgg== X-Gm-Message-State: AOJu0YzkmP6FKqzr3SutOXQSIVfeLiMar6rZIresViEnaC6TAaTQXgPJ NpjbA2SnkingkBZjV3+bZ+hEVaQ50eom X-Google-Smtp-Source: AGHT+IHtVS6qiXCVuICpjIo9v1ArG+K49q8MxhuOD/We1+xNdIENUBBwie8jAWodVY5lm/jNcHZQ+w== X-Received: by 2002:a05:6a20:12cd:b0:189:3748:f060 with SMTP id v13-20020a056a2012cd00b001893748f060mr3765980pzg.26.1700687525147; Wed, 22 Nov 2023 13:12:05 -0800 (PST) Received: from fedora.mshome.net ([75.167.214.230]) by smtp.gmail.com with ESMTPSA id j18-20020a635512000000b005bdbce6818esm132136pgb.30.2023.11.22.13.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 13:12:04 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-mm@kvack.org Cc: linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, arnd@arndb.de, tglx@linutronix.de, luto@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, mhocko@kernel.org, tj@kernel.org, ying.huang@intel.com, Gregory Price Subject: [RFC PATCH 00/11] mm/mempolicy: Make task->mempolicy externally modifiable via syscall and procfs Date: Wed, 22 Nov 2023 16:11:49 -0500 Message-Id: <20231122211200.31620-1-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AC524160020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mx38eqxkqqe4ss49j37tpe7yoqhtb7x9 X-HE-Tag: 1700687526-44330 X-HE-Meta: U2FsdGVkX19DQhNYuT2EP3vWf38zzhnVSD2y7IHiDAhN78risXeP4K1obvqWZ7EDW81mY0DyoPqiC2kXt44or0FJi25lrg1EkEpt/i731P8ol4SJgKye85GTPK/nL4UAuacKu9wFLn070+gXAOKHnxybpZueftCR51OvbqlZ83LcCH0jYPhHtU1W1te7A1ovE+QfKNgkY/KO/8yNgo+5uKNUNQNhZJq0osemWuOWFxb6lTonp4Txd5lsakVm04GeRNKV2dp661QtlNVI27HFw8VIpksHiRgIo33JsNxIUpx5aOp52wdSTsUelEFFbTiucJyy98MIgVPeqRU86Lv/+RGg4OOKT5RPA0ZP+xd8dlWjADuoYqTm/WEXlMPNhSx6yISHW7twhtT+efwtaL/NB2sxCh2PC4JZ12BOqw/EKKN0AKw7QCr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=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The patch set changes task->mempolicy to be modifiable by tasks other than just current. The ultimate goal is to make mempolicy more flexible and extensible, such as adding interleave weights (which may need to change at runtime due to hotplug events). Making mempolicy externally modifiable allows for userland daemons to make runtime performance adjustments to running tasks without that software needing to be made numa-aware. This initial RFC involves 3 major updates the mempolicy. 1. Refactor modifying interfaces to accept a task as an argument, and change existing callers to send `current` in to retain the existing behavior. 2. Change locking behaviors to ensure task->mpol is referenced safely by acquiring the task_lock where required. Since allocators take the alloc lock (task lock), this successfully prevents changes from being made during allocations. 3. Add external interfaces which allow for a task mempolicy to be modified by another task. This is implemented in 4 syscalls and a procfs interface: sys_set_task_mempolicy sys_get_task_mempolicy sys_set_task_mempolicy_home_node sys_task_mbind /proc/[pid]/mempolicy The new syscalls are the same as their current-task counterparts, except that they take a pid as an argument. The exception is task_mbind, which required a new struct due to the number of args. The /proc/pid/mempolicy re-uses the interface mpol_parse_str format to enable get/set of mempolicy via procsfs. mpol_parse_str format: [=][:] Example usage: echo "default" > /proc/pid/mempolicy echo "prefer=relative:0" > /proc/pid/mempolicy echo "interleave:0-3" > /proc/pid/mempolicy Changing the mempolicy does not induce memory migrations via the procfs interface (which is the exact same behavior as set_mempolicy). Signed-off-by: Gregory Price Gregory Price (11): mm/mempolicy: refactor do_set_mempolicy for code re-use mm/mempolicy: swap cond reference counting logic in do_get_mempolicy mm/mempolicy: refactor set_mempolicy stack to take a task argument mm/mempolicy: modify get_mempolicy call stack to take a task argument mm/mempolicy: modify set_mempolicy_home_node to take a task argument mm/mempolicy: modify do_mbind to operate on task argument instead of current mm/mempolicy: add task mempolicy syscall variants mm/mempolicy: export replace_mempolicy for use by procfs mm/mempolicy: build mpol_parse_str unconditionally mm/mempolicy: mpol_parse_str should ignore trailing characters in nodelist fs/proc: Add mempolicy attribute to allow read/write of task mempolicy arch/x86/entry/syscalls/syscall_32.tbl | 4 + arch/x86/entry/syscalls/syscall_64.tbl | 4 + fs/proc/Makefile | 1 + fs/proc/base.c | 1 + fs/proc/internal.h | 1 + fs/proc/mempolicy.c | 117 +++++++ include/linux/mempolicy.h | 13 +- include/linux/syscalls.h | 14 + include/uapi/asm-generic/unistd.h | 10 +- include/uapi/linux/mempolicy.h | 10 + mm/mempolicy.c | 432 +++++++++++++++++++------ 11 files changed, 502 insertions(+), 105 deletions(-) create mode 100644 fs/proc/mempolicy.c -- 2.39.1