From patchwork Mon Sep 21 08:02:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunxin Zang X-Patchwork-Id: 11788761 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60316618 for ; Mon, 21 Sep 2020 08:03:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E63C1214F1 for ; Mon, 21 Sep 2020 08:03:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="v4QQxqar" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E63C1214F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E6913900036; Mon, 21 Sep 2020 04:03:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E18C9900029; Mon, 21 Sep 2020 04:03:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D07FF900036; Mon, 21 Sep 2020 04:03:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id B7E7D900029 for ; Mon, 21 Sep 2020 04:03:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 776CD3628 for ; Mon, 21 Sep 2020 08:03:09 +0000 (UTC) X-FDA: 77286328098.05.chain05_330c08e27143 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 5E82E1801DBD9 for ; Mon, 21 Sep 2020 08:03:09 +0000 (UTC) X-Spam-Summary: 1,0,0,95f50c8bbdc9823c,d41d8cd98f00b204,zangchunxin@bytedance.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1437:1500:1515:1535:1541:1711:1730:1747:1777:1792:1801:2194:2199:2393:2553:2559:2562:2692:2693:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:4321:4605:5007:6119:6261:6653:6742:7576:8531:10004:11026:11232:11473:11658:11914:12043:12048:12297:12438:12517:12519:12555:12679:12895:12986:13069:13161:13229:13311:13357:13894:14181:14384:14394:14581:14721:21080:21444:21451:21627:21987:21990:30029:30054:30090,0,RBL:209.85.216.65:@bytedance.com:.lbl8.mailshell.net-62.14.0.100 66.201.201.201;04yr5oonxei1smrd94huawqtr9j84op147h8ytdshabhnj8p8q7jkt9dmnxsicw.a3whe5fz5q1g5h3koad1w1hnxdfr9anrupi8xojxggysnu5957xk8g8ysg7rmas.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: chain05_330c08e27143 X-Filterd-Recvd-Size: 5161 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 08:03:08 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id q4so7023087pjh.5 for ; Mon, 21 Sep 2020 01:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MQ9zzgzZmaH7SVE72fu66K8V5NhJkHfIKNhfWRZkT70=; b=v4QQxqar9/gUAXuiOZ1QrCEiXJN++eMu4eslr0jnEjDgUQudhSX7PzLs1mguRYwEpD 6nkSdkiD7br/G4EQ6WhJUlm1untmUXqZKp7Z+IW4wA4DcjThUG6nDSGQW5GCYsOKpdM6 nyMrYP/Bmmcbm8dKzQ5Tdhf0HBdA+ZAG3QzTyMwSAttZZPkei/hd+/dqxACc4zUrAhUt 1m1tdlhySvfBll7Cm8W0n1sayUPNVPERUYYlH+phSYii1EBT3u+mmQPonDxSC23sML3t DpuBxNMDBx0DT4Bdheea6pVTfRYo0Y9XBuid0omy8AHz2W/Pi9KrumKsLcVedd9Kl484 m0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MQ9zzgzZmaH7SVE72fu66K8V5NhJkHfIKNhfWRZkT70=; b=FbMdDD0MbyrroZ4aRfHleBKuDf44pqScOnIWu56uj0N3yqpzZSOEiHv9LcGkRVh3wl T313KzUwdkCq5iYCQUEqQuuv4jPz83wwKV+o0mnu4IkTdUkU0WWNKiPypX97FDpWfPAt 4L5dKC3w43GPYiNe05vZEla4/qQ5ig7MPRD7ZADlDyONHzIKXpWdEVwRfyEt4Kz4m/ya hM8HtkQBOZmU6rNcOzFplKYHFCAVwNemU4W538gO4cP1pSH/YpDtyKAveobUdyezPdxH Chf4QYFQKzam6FETo1sP9TgdMFozW5ulbryOFQL10lBrnhAP6lYvF4Lof0FW7lJtq9OT +daw== X-Gm-Message-State: AOAM531P0XVSpGnJ0hQZbx8PjmRUVTmBHepnXneSj0JflXGoFPH4aw1n laQw5NIv64lSbK8yNXeeD2X0ZQ== X-Google-Smtp-Source: ABdhPJykdY9XaYIuHd3HipxwMdwfsSeHmOqtcFUJirp24BFcbIXt+ifViiOUeeAn3CsKn35Wjkb3Ug== X-Received: by 2002:a17:90a:d152:: with SMTP id t18mr22628479pjw.27.1600675387607; Mon, 21 Sep 2020 01:03:07 -0700 (PDT) Received: from Zs-MacBook-Pro.local.net ([103.136.221.70]) by smtp.gmail.com with ESMTPSA id s24sm9741972pjp.53.2020.09.21.01.02.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Sep 2020 01:03:06 -0700 (PDT) From: zangchunxin@bytedance.com To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, tj@kernel.org, lizefan@huawei.com, corbet@lwn.net Cc: ast@kernel.org, daniel@iogearbox.net, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, john.fastabend@gmail.com, kpsingh@chromium.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Chunxin Zang Subject: [PATCH] mm/memcontrol: Add the drop_cache interface for cgroup v2 Date: Mon, 21 Sep 2020 16:02:55 +0800 Message-Id: <20200921080255.15505-1-zangchunxin@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 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: From: Chunxin Zang In the cgroup v1, we have 'force_mepty' interface. This is very useful for userspace to actively release memory. But the cgroup v2 does not. This patch reuse cgroup v1's function, but have a new name for the interface. Because I think 'drop_cache' may be is easier to understand :) Signed-off-by: Chunxin Zang --- Documentation/admin-guide/cgroup-v2.rst | 11 +++++++++++ mm/memcontrol.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index ce3e05e41724..fbff959c8116 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1181,6 +1181,17 @@ PAGE_SIZE multiple when read back. high limit is used and monitored properly, this limit's utility is limited to providing the final safety net. + memory.drop_cache + A write-only single value file which exists on non-root + cgroups. + + Provide a mechanism for users to actively trigger memory + reclaim. The cgroup will be reclaimed and as many pages + reclaimed as possible. + + It will broke low boundary. Because it tries to reclaim the + memory many times, until the memory drops to a certain level. + memory.oom.group A read-write single value file which exists on non-root cgroups. The default value is "0". diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 0b38b6ad547d..98646484efff 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6226,6 +6226,11 @@ static struct cftype memory_files[] = { .write = memory_max_write, }, { + .name = "drop_cache", + .flags = CFTYPE_NOT_ON_ROOT, + .write = mem_cgroup_force_empty_write, + }, + { .name = "events", .flags = CFTYPE_NOT_ON_ROOT, .file_offset = offsetof(struct mem_cgroup, events_file),