From patchwork Sat Nov 20 04:50:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 12630063 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 08554C433F5 for ; Sat, 20 Nov 2021 04:52:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5AB06B0074; Fri, 19 Nov 2021 23:50:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE36C6B0075; Fri, 19 Nov 2021 23:50:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5C6F6B0078; Fri, 19 Nov 2021 23:50:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 968B66B0074 for ; Fri, 19 Nov 2021 23:50:36 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6474D89B25 for ; Sat, 20 Nov 2021 04:50:26 +0000 (UTC) X-FDA: 78828082452.22.2E8935E Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf22.hostedemail.com (Postfix) with ESMTP id 943FC192D for ; Sat, 20 Nov 2021 04:50:25 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id t1-20020a6564c1000000b002e7f31cf59fso5030940pgv.14 for ; Fri, 19 Nov 2021 20:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Iq24JeebEl5J+lwUGxaMYnGaB9XaVCl6Xy4iwtIyjvA=; b=chHgb4puhIWCbXYE8Sfesk3NR0JUQxPlsgsGXteWK/zzn4p5veG4SJor/gZuL7JgX3 rTpfhIB3TB148ACfiYmshuzDlk8La2eFK38A6waYF1P8TDVR9KDtqC5wgu6d4MhZGzn9 AU/xppkCdNdEA6B7QqNnDCas+iwtGzetJMukBnFtJdRdTqKvTWX7FAcUwxCo6r8I32sf bBCWBPZBvHHjBAZX3j8SS2dTcb80lzU4+UCk6gX7wrhiM6xAKdh05qROmWp4Y+SiE12o V0NAZSvNAXayIFigemF54IXXzW9KOuEVLOEBm4hrqi2dGz99WYHyQdUR37wEDeW9fchV D+/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Iq24JeebEl5J+lwUGxaMYnGaB9XaVCl6Xy4iwtIyjvA=; b=GeLGFtrF5t8NQ2m7Zc4B8hMis2CE++d/2o1/A5cOy882SdUotOXOH9DTKWq9Nlamaz BCo5lSi6h7cqV5tcq3yg5OjhmA/7rwTjqhpAdU5J3S6CdRLv9Khc2hLvaxT1rnG3IGiG 7XdNRqUnNHCZfdDdAN1G9vWRGi2WVTEL4rhRdkV85dY0zkpbPOaU0eIpUZHrYU0ab5vS jRO6Amreps5fmia/ADg8Qxoras4qx1IGMU9qNC96JCkXSV/agGmpwHSTgUibqFwTyY0r p7jAKGmKVC/MJiyCsW2cUjIJx2vX6Nd7ZYc3jWc4S31bS6WPOXRKpq5UqMRBTS8QP4M9 6w4A== X-Gm-Message-State: AOAM530ms3C1QqrggLhZxoSgUqRiu2y1afSqQCm83yB15g3su5G8XTdv SFZums1DI0JtWKahs/3iHF5jc8lh+W1OnHIsXA== X-Google-Smtp-Source: ABdhPJw2LtgTcmkkzLu7IfsO7oStiwjz2hQIMktMWyDyw5d5CngJQrpTot1D+094Y6eOR3p65b1F4UncxKHZugK7JQ== X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2cd:202:fa91:560a:d7b4:93]) (user=almasrymina job=sendgmr) by 2002:a17:90b:4c8b:: with SMTP id my11mr6839565pjb.96.1637383825076; Fri, 19 Nov 2021 20:50:25 -0800 (PST) Date: Fri, 19 Nov 2021 20:50:09 -0800 In-Reply-To: <20211120045011.3074840-1-almasrymina@google.com> Message-Id: <20211120045011.3074840-4-almasrymina@google.com> Mime-Version: 1.0 References: <20211120045011.3074840-1-almasrymina@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v4 3/4] mm, shmem: add filesystem memcg= option documentation From: Mina Almasry To: Jonathan Corbet Cc: Mina Almasry , Alexander Viro , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Hugh Dickins , Shuah Khan , Shakeel Butt , Greg Thelen , Dave Chinner , Matthew Wilcox , Roman Gushchin , "Theodore Ts'o" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org X-Stat-Signature: 7uf8xa43j5x9wk653nuo8o94qzfs3h1c X-Rspamd-Queue-Id: 943FC192D X-Rspamd-Server: rspam07 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=chHgb4pu; spf=pass (imf22.hostedemail.com: domain of 3kX6YYQsKCAQepqewv2qmreksskpi.gsqpmry1-qqozego.svk@flex--almasrymina.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3kX6YYQsKCAQepqewv2qmreksskpi.gsqpmry1-qqozego.svk@flex--almasrymina.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1637383825-996809 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: Document the usage of the memcg= mount option, as well as permission restrictions of its use and caveats with remote charging. Signed-off-by: Mina Almasry --- Changes in v4: - Added more info about the permissions to mount with memcg=, and the importance of restricting write access to the mount point. - Changed documentation to describe the ENOSPC/SIGBUS behavior rather than the ENOMEM behavior implemented in earlier patches. - I did not find a good place to put this documentation after making the mount option generic. Please let me know if there is a good place to add this, and if not I can add a new file. Thanks! --- Documentation/filesystems/tmpfs.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) -- 2.34.0.rc2.393.gf8c9666880-goog diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 0408c245785e3..dc1f46e16eaf4 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -137,6 +137,34 @@ mount options. It can be added later, when the tmpfs is already mounted on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'. +If CONFIG_MEMCG is enabled, filesystems (including tmpfs) has a mount option to +specify the memory cgroup to be charged for page allocations. + +memcg=/sys/fs/cgroup/unified/test/: data page allocations are charged to +cgroup /sys/fs/cgroup/unified/test/. + +Only processes that have write access to +/sys/fs/cgroup/unified/test/cgroup.procs can mount a tmpfs with +memcg=/sys/fs/cgroup/unified/test. Thus, a process is able to charge memory to a +cgroup only if it itself is able to enter that cgroup and allocate memory +there. This is to prevent random processes from mounting filesystems in user +namespaces and intentionally DoSing random cgroups running on the system. + +Once a mount point is created with memcg=, any process that has write access to +this mount point is able to use this mount point and direct charges to the +cgroup provided. Thus, it is important to limit write access to the mount point +to the intended users if untrusted code is running on the machine. This is +generally required regardless of whether the mount is done with memcg= or not. + +When charging memory to the remote memcg (memcg specified with memcg=) and +hitting that memcg's limit, the oom-killer will be invoked (if enabled) and will +attempt to kill a process in the remote memcg. If no killable processes are +found, the remote charging process gets an ENOSPC error. If the remote charging +process is in the pagefault path, it gets a SIGBUS signal. It's recommended +that processes executing remote charges are able to handle a SIGBUS signal or +ENOSPC error that may arise during executing the remote charges. + + To specify the initial root directory you can use the following mount options: