From patchwork Sun Dec 15 07:34:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13908676 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 A89ABE77183 for ; Sun, 15 Dec 2024 07:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01B2C6B0083; Sun, 15 Dec 2024 02:34:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE7836B0085; Sun, 15 Dec 2024 02:34:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D38016B0088; Sun, 15 Dec 2024 02:34:44 -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 B41916B0083 for ; Sun, 15 Dec 2024 02:34:44 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 551821231E5 for ; Sun, 15 Dec 2024 07:34:44 +0000 (UTC) X-FDA: 82896380658.05.0BFAF80 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf05.hostedemail.com (Postfix) with ESMTP id 70BE310000D for ; Sun, 15 Dec 2024 07:33:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c1UDzj8G; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734248056; a=rsa-sha256; cv=none; b=Y+Wcz7gvhgR/m643Z0iAzk0SBRdfmc77poBsX859O/bUZAsPCsKpbJluNVzzBxO7/u/9hP a3xaViMfdYbMhY3pG9n/Ps51+ylj6Q20EF50KyNxU2d2vVrOKbNxOUfseuiqQl8e0h4tvj 86EYSP+GIB+9DqpFJ3Ec8R//sPVmaow= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c1UDzj8G; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734248056; 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=5izpCFB/DQQuqGn/lH/5kc7CzPxoesROrtgbeHZpfCA=; b=Gk9sFe+aMBxoC9oXyToYiW2qy/bVmaHKJGbaB3/+LlXIy/MYO1HMiwthQwuSLcSL/rj85l IETgaekqn035kkr0cQK1ULzET2dnWSoppPaAO1bU09aBT4WDIry+5VLhQDkvV9ZsS4519a nWLYYcQURzeUuu/7FvYIxJS0Aqn/SNs= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2162c0f6a39so37000645ad.0 for ; Sat, 14 Dec 2024 23:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734248081; x=1734852881; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5izpCFB/DQQuqGn/lH/5kc7CzPxoesROrtgbeHZpfCA=; b=c1UDzj8GkEAabscDe7R6D4yi/e+OvAHdEcDRHG1+UBCwXbAa3IJSAkc5LHL3D1KWlg 5wI+k0I4hrrngYmZsjtYa630ieloeVBrDIyzDNAhUwjsRIeTIFIYVvICoRHjbHgytpLL Jf9iKsKy2bDE7dsKEvjnpsrt54Wp8/w10Aca6Y97shQ7RuGbR57S27vEmYUOMMVlYfj7 506FNupEbAsMPgRIm9wu8SByL+BJNUqHTgFaN48BTJKwlqVx6jpK4+6Kpup+SMeKnm07 Y9YKuDCKbeezF/Kl87ALG6IZbyqRnhsOOmS0mKspKCOIB5oMtj7gZbi5V5Bej9XhXiW0 JyJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734248081; x=1734852881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5izpCFB/DQQuqGn/lH/5kc7CzPxoesROrtgbeHZpfCA=; b=Tr0XCMTuWZu/bed1vQdjVXVmFzbZlSEDJ2h/PMSOAWu5DFa6mRo0NCIPF01UPdKg2j MEj3ESPrsQyAjSkQREEW4WwSF/06leOVEwSNWzTVw1Ljfa3wbx+JLWq5Nk7/GH7NFoj6 ODPCK0uAGrST8DK0T9Sd0FSIBcUkx4/Icv8KR8t+wMfEi1GX5r+pZX45ypCCH6WEsOC3 gcQ8j9zOmVumjSgJc6g6KRGaI6cwgp4QdCea8ppHdGS4q6gqzJggQBS4tY5RKIBzvN4B qvg8Sn8cac/Kd5/hskSYFDzOXSEQtCU2i0kl5vxNLVt+6NhdEgzJOSOx9ae6E2tP+bQl 6AHQ== X-Gm-Message-State: AOJu0Yx8tyrlQ30wq+E6WbgzS5Uxce3Uper65OD1vjANovjyXJoJbyIe zlTVzScHSCgVQLuitIk9iwe9EJel4SRO89XMffL0WaOVKe3QLUsW X-Gm-Gg: ASbGncsozFXHxNUgQ2W/MpstJDcGy8gLx9y1gCAIsOGSE+T0/nG6QcJehM4yKAZv3M0 dYONA/jNOhEYPOLfRqNy0HuKfBOJZm2XyWc/cEAv0+vCiMXsMcIz2abjoWett/UPGlnSUtTkmU3 tkayfa93tcNMV3QsDJ0fTuvWs3Zl7kPSjUbm6OG2NPu/TYvHre5tBdmP3kMwKdLDdLx9SXuI0Ar 1CpzfUQecsw3gy7fkJggi6wvTMAJYFZ8gTr8P8flhSJIwO/dNSWJQNyGZsRG9CUC0Cdo0mLVE76 nYqoCBU= X-Google-Smtp-Source: AGHT+IHpaKSS02eU+xreRneW7ljwrrb63fnky/lauVjTvv+O46wMn+qpnFNF0X85jYodME5ub6T+ug== X-Received: by 2002:a17:902:db02:b0:216:3440:3d21 with SMTP id d9443c01a7336-2178c874e19mr192018695ad.26.1734248081423; Sat, 14 Dec 2024 23:34:41 -0800 (PST) Received: from localhost.localdomain ([180.159.118.224]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142daea5esm5933149a91.17.2024.12.14.23.34.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 14 Dec 2024 23:34:41 -0800 (PST) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [RFC PATCH 1/2] mm/memcontrol: add a new cgroup file memory.nomlock Date: Sun, 15 Dec 2024 15:34:14 +0800 Message-Id: <20241215073415.88961-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20241215073415.88961-1-laoar.shao@gmail.com> References: <20241215073415.88961-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 70BE310000D X-Stat-Signature: 5qd4fekfxukmdcffqpfr8id4feam3h47 X-Rspam-User: X-HE-Tag: 1734248029-15572 X-HE-Meta: U2FsdGVkX1+exHKC5suZugLq5rqDkX2iQCqJaoVkZP40YdV2gFDG9N92gVRc5dl08EDALBpwJeKg7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EtoV7gmakTrgZ3HdlkAiPaycsCRNx460ihkgSLJbgpZla0bFY9o083nFiPK7XXYzyHw5aPm3bIh7q7hESrc0DHVJV15L//aLZz0AyK3Zu12qvENumQtOKn0NjY/oVlxBna0Hi8PoQyRuzEpdDl/HHmqKnjZio/TA+oDys1vEgeZ6IGmI0ZHrXyQLVOG4/G4OPjdLbvKvvk0je6ney/Gkpp+A8Y08yYcLw86/+5bReKsI9/vcxskgXcR2fnX0XvsuHdWelOeu/55OL51U44YAN5mJftsBVVWkrK0V X-Bogosity: Ham, tests=bogofilter, spamicity=0.000008, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a new cgroup file memory.nomlock to control the behavior of mlock. This is a preparation of the followup patch. 0: Disable nomlock 1: Enable nomlock Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 3 +++ mm/memcontrol.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index b28180269e75..b3a4e28ae0f9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -220,6 +220,9 @@ struct mem_cgroup { */ bool oom_group; + /* Folios won't be mlocked in this memcg. */ + bool nomlock; + int swappiness; /* memory.events and memory.events.local */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7b3503d12aaf..08bb65c1612f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4374,6 +4374,35 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, return nbytes; } +static int memory_nomlock_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_seq(m); + + seq_printf(m, "%d\n", READ_ONCE(memcg->nomlock)); + return 0; +} + +static ssize_t memory_nomlock_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + int ret, nomlock; + + buf = strstrip(buf); + if (!buf) + return -EINVAL; + + ret = kstrtoint(buf, 0, &nomlock); + if (ret) + return ret; + + if (nomlock != 0 && nomlock != 1) + return -EINVAL; + + WRITE_ONCE(memcg->nomlock, nomlock); + return nbytes; +} + static struct cftype memory_files[] = { { .name = "current", @@ -4445,6 +4474,12 @@ static struct cftype memory_files[] = { .flags = CFTYPE_NS_DELEGATABLE, .write = memory_reclaim, }, + { + .name = "nomlock", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = memory_nomlock_show, + .write = memory_nomlock_write, + }, { } /* terminate */ };