Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1343121ybj; Fri, 20 Sep 2019 08:58:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKjc+KzJIkJSKFZhsb/S/vHZqDQcofy7jX8tC+Gbvrb4iNp+XVh0ON18T2Ic5TU1g7X2yJ X-Received: by 2002:a17:906:5fc4:: with SMTP id k4mr20091065ejv.300.1568995131412; Fri, 20 Sep 2019 08:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568995131; cv=none; d=google.com; s=arc-20160816; b=jirl7S2pk33f3y5M+vfcKr3g+4JOM5wqcFemVvlH9Q1+fBgNMGQ9D2S8gI0bO1Di5k U22q2ow2WYdeCBiuhuYuy/EWat0t3/dHv+C/TGp5/HAANGkjXI0e66lT8iJ8NIham1I3 ZdIe3oSBN1pLn9hhnR+ei0E7+HuHunVtjktz8/PFSNPD99P+4bN+xbo5RDOl+BivzCxK YZrXRSvuggouFfZthKeK6s5Hgx/zvv3Jh52woRYJNPcsxma/ukx8q6wiyzbDxb4NQmYA Wj5FWGLmOi36JuDnGl1HDHNnWFlZMSCxVgWZ3Smj0JymBbvLm1ExjrvMUQM8kd41nk+h hkIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=1fNH/t1YSSHvbg8a3MxctDUNrINVVwuSB3u0kWY+VvE=; b=jPoF7yQ9H4ZY/3iN22jOvLZxlcHserDSvvmhYSNjbclKDMkGOUT6t71StC/fU6TShe jLY0UCDzaC+NfALLs8UNnloiql5D6IGD7Z7lnwGe0ocWEzmDikE4Aip5IwM8nj21lSuT xTBRcYKRaKiK8F3zPqXKRtpnCJky18DIwTEGUQxpsvKwrZPGjfdfkPAB0E1zSTWajBid UWVlo1/yNPxXzXMCMBK59nu4ErJIpWAKRjDgbN/btf3D7Z9fX8dqihMLkTwAT4mewqq2 CgKcrvhIJ+WdJkMuHJk3wmgYb9y/BW+XnyumvQ5V5zd9V8Km8jqBAAC3ePfaGISerflG gPDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=okXtjjMu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l19si1518968eds.389.2019.09.20.08.58.26; Fri, 20 Sep 2019 08:58:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=okXtjjMu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436525AbfISWYr (ORCPT + 99 others); Thu, 19 Sep 2019 18:24:47 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:42338 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436515AbfISWYp (ORCPT ); Thu, 19 Sep 2019 18:24:45 -0400 Received: by mail-pl1-f202.google.com with SMTP id d1so3084360plj.9 for ; Thu, 19 Sep 2019 15:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1fNH/t1YSSHvbg8a3MxctDUNrINVVwuSB3u0kWY+VvE=; b=okXtjjMugI2zY2ntgsy9f5ADQvXd32G/3xinqf6Q6DtZsN1MbYoRsonm/03yjd0/P+ MiIUVJ/TIT5XH2YKjfw0FvrBtAZwd5DM78evZ6y1x0tflJV48NyGtbgy/MY/hxd5k/Zc 3V9HjeyAmSr1BHpbXPnNTRrEmOoGHsqAiX3Ck/V8YaFH2UmsyObqtnMlM/LEM2sh6P3q W0JqVYCmFHAWrwSTvjAAudRcEl5fiiFK2qODUwZWWBFv1tb1baNfEY5piUNaqnQJoX4r sYGU1nFjv3MHx7pUHQxtV3lOoSFYliguYZydg0YOWMR0IC9U4uIEB4rXq6tv6XXwZu+0 5zNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1fNH/t1YSSHvbg8a3MxctDUNrINVVwuSB3u0kWY+VvE=; b=spzadmBo8KK7Gs2pnRPWIHiLD1d2jjjQgvVnJdyGEhmS74EgN1B4A/2zHdA8J3V2jk QyOrhee/65f9hrRPXzQwjSu5V2HmdqfKfEMco/nXr/UxnnNYFQPn8WjY/UWtdFbpwPC9 iX6To3BaUWbNkkxeKOmKMk3YfVam0/TEoapR9XjvWvZyQAU2vOFO1TybJgjr00Bc2qVN jmyfl63TVlmymYR15Vxbi3Cheyx4YcvF1aw9CeWUVXve2KkIiQfgWL90PYrlsIqP7FNK ph9BDCF8KpkPzhUbXziZ35Kf0lyuSO2Bu7iuGdCfUV48elArwE2wTWrgLsHpiHcWuj0r YJUw== X-Gm-Message-State: APjAAAXKvUImAodaIJ6CrmzH/oyQDJdIIAGyVVMHA2XiVrWwu3/JS7HD N9S57qmJUYo3PJEYWAqGqsXEIFckpQ96R9rO3A== X-Received: by 2002:a63:4451:: with SMTP id t17mr11796300pgk.128.1568931883911; Thu, 19 Sep 2019 15:24:43 -0700 (PDT) Date: Thu, 19 Sep 2019 15:24:21 -0700 In-Reply-To: <20190919222421.27408-1-almasrymina@google.com> Message-Id: <20190919222421.27408-8-almasrymina@google.com> Mime-Version: 1.0 References: <20190919222421.27408-1-almasrymina@google.com> X-Mailer: git-send-email 2.23.0.351.gc4317032e6-goog Subject: [PATCH v5 7/7] hugetlb_cgroup: Add hugetlb_cgroup reservation docs From: Mina Almasry To: mike.kravetz@oracle.com Cc: shuah@kernel.org, almasrymina@google.com, rientjes@google.com, shakeelb@google.com, gthelen@google.com, akpm@linux-foundation.org, khalid.aziz@oracle.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, cgroups@vger.kernel.org, aneesh.kumar@linux.vnet.ibm.com, mkoutny@suse.com, Hillf Danton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add docs for how to use hugetlb_cgroup reservations, and their behavior. Signed-off-by: Mina Almasry Acked-by: Hillf Danton --- .../admin-guide/cgroup-v1/hugetlb.rst | 85 ++++++++++++++++--- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v1/hugetlb.rst b/Documentation/admin-guide/cgroup-v1/hugetlb.rst index a3902aa253a9..70c10bd9a0b7 100644 --- a/Documentation/admin-guide/cgroup-v1/hugetlb.rst +++ b/Documentation/admin-guide/cgroup-v1/hugetlb.rst @@ -2,13 +2,6 @@ HugeTLB Controller ================== -The HugeTLB controller allows to limit the HugeTLB usage per control group and -enforces the controller limit during page fault. Since HugeTLB doesn't -support page reclaim, enforcing the limit at page fault time implies that, -the application will get SIGBUS signal if it tries to access HugeTLB pages -beyond its limit. This requires the application to know beforehand how much -HugeTLB pages it would require for its use. - HugeTLB controller can be created by first mounting the cgroup filesystem. # mount -t cgroup -o hugetlb none /sys/fs/cgroup @@ -28,10 +21,14 @@ process (bash) into it. Brief summary of control files:: - hugetlb..limit_in_bytes # set/show limit of "hugepagesize" hugetlb usage - hugetlb..max_usage_in_bytes # show max "hugepagesize" hugetlb usage recorded - hugetlb..usage_in_bytes # show current usage for "hugepagesize" hugetlb - hugetlb..failcnt # show the number of allocation failure due to HugeTLB limit + hugetlb..reservation_limit_in_bytes # set/show limit of "hugepagesize" hugetlb reservations + hugetlb..reservation_max_usage_in_bytes # show max "hugepagesize" hugetlb reservations recorded + hugetlb..reservation_usage_in_bytes # show current reservations for "hugepagesize" hugetlb + hugetlb..reservation_failcnt # show the number of allocation failure due to HugeTLB reservation limit + hugetlb..limit_in_bytes # set/show limit of "hugepagesize" hugetlb faults + hugetlb..max_usage_in_bytes # show max "hugepagesize" hugetlb usage recorded + hugetlb..usage_in_bytes # show current usage for "hugepagesize" hugetlb + hugetlb..failcnt # show the number of allocation failure due to HugeTLB usage limit For a system supporting three hugepage sizes (64k, 32M and 1G), the control files include:: @@ -40,11 +37,77 @@ files include:: hugetlb.1GB.max_usage_in_bytes hugetlb.1GB.usage_in_bytes hugetlb.1GB.failcnt + hugetlb.1GB.reservation_limit_in_bytes + hugetlb.1GB.reservation_max_usage_in_bytes + hugetlb.1GB.reservation_usage_in_bytes + hugetlb.1GB.reservation_failcnt hugetlb.64KB.limit_in_bytes hugetlb.64KB.max_usage_in_bytes hugetlb.64KB.usage_in_bytes hugetlb.64KB.failcnt + hugetlb.64KB.reservation_limit_in_bytes + hugetlb.64KB.reservation_max_usage_in_bytes + hugetlb.64KB.reservation_usage_in_bytes + hugetlb.64KB.reservation_failcnt hugetlb.32MB.limit_in_bytes hugetlb.32MB.max_usage_in_bytes hugetlb.32MB.usage_in_bytes hugetlb.32MB.failcnt + hugetlb.32MB.reservation_limit_in_bytes + hugetlb.32MB.reservation_max_usage_in_bytes + hugetlb.32MB.reservation_usage_in_bytes + hugetlb.32MB.reservation_failcnt + + +1. Reservation limits + +The HugeTLB controller allows to limit the HugeTLB reservations per control +group and enforces the controller limit at reservation time. Reservation limits +are superior to Page fault limits (see section 2), since Reservation limits are +enforced at reservation time, and never causes the application to get SIGBUS +signal. Instead, if the application is violating its limits, then it gets an +error on reservation time, i.e. the mmap or shmget return an error. + + +2. Page fault limits + +The HugeTLB controller allows to limit the HugeTLB usage (page fault) per +control group and enforces the controller limit during page fault. Since HugeTLB +doesn't support page reclaim, enforcing the limit at page fault time implies +that, the application will get SIGBUS signal if it tries to access HugeTLB +pages beyond its limit. This requires the application to know beforehand how +much HugeTLB pages it would require for its use. + + +3. Caveats with shared memory + +a. Charging and uncharging: + +For shared hugetlb memory, both hugetlb reservation and usage (page faults) are +charged to the first task that causes the memory to be reserved or faulted, +and all subsequent uses of this reserved or faulted memory is done without +charging. + +Shared hugetlb memory is only uncharged when it is unreserved or deallocated. +This is usually when the hugetlbfs file is deleted, and not when the task that +caused the reservation or fault has exited. + +b. Interaction between reservation limit and fault limit. + +Generally, it's not recommended to set both of the reservation limit and fault +limit in a cgroup. For private memory, the fault usage cannot exceed the +reservation usage, so if you set both, one of those limits will be useless. +Still, there is no kernel enforcement on setting both at the same time. + +For shared memory, a cgroup's fault usage may be greater than its reservation +usage, so some care needs to be taken. Consider this example: + +- Task A reserves 4 pages in a shared hugetlbfs file. Cgroup A will get + 4 reservations charged to it and no faults charged to it. +- Task B reserves and faults the same 4 pages as Task A. Cgroup B will get no + reservation charge, but will get charged 4 faulted pages. If Cgroup B's limit + is less than 4, then Task B will get a SIGBUS. + +For the above scenario, it's not recommended for the userspace to set both +reservation limits and fault limits, but it is still allowed to in case it sees +some use for it, such as safe gradual transitioning from one to the other. -- 2.23.0.351.gc4317032e6-goog