From patchwork Sat Jan 5 00:19:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10749013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D69EE14E5 for ; Sat, 5 Jan 2019 00:21:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C69F6287EF for ; Sat, 5 Jan 2019 00:21:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAFE0287FD; Sat, 5 Jan 2019 00:21:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4723C287EF for ; Sat, 5 Jan 2019 00:21:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56D988E0111; Fri, 4 Jan 2019 19:21:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F6188E00F9; Fri, 4 Jan 2019 19:21:11 -0500 (EST) 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 398698E0111; Fri, 4 Jan 2019 19:21:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id E70A68E00F9 for ; Fri, 4 Jan 2019 19:21:10 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id ay11so28095314plb.20 for ; Fri, 04 Jan 2019 16:21:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=dW7lWc9crn2H8wXW3I/dbbtBQcc06wSqi1SfSudgQuY=; b=RlFX03siPBAfROt+qrs8U/odmTGtczIjjqo3zjRCewqfZfClagenbzMrJPGbts/Qmc j5fzBO1k1TmJwtTheHk1iZ28qDiXk7FlJI6ApJnKt2uDMGmhA3K6eED/IO48HoFO/mN4 +6zs/Vi1DafkP+ah5AEIMUsB4Raj/hpRmtsbIq3KnHKyBZWudMyJMzwAUj1ryHe23nAs kYUZMm8SPaDFyMtaoEnhKg3avJ5zL81CCOU3bE5/AZctAguZ6rMrZkk14DTPDag0JzzT uCq+CyvRrCgZdAqmA/q/nCzjzie/zU48Rvi71hl+nok31MYkUSS1N5rOXBYTjchg9Gtu 7mLg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AJcUuke2XBKWB8+J2x+/U1c/NScKv2d5mAYto3SGcwuXjn7SKaV5V28o R++YsAw2qjkVzATOzwOnQGz+mTR9s60gK6qQQB3DYrUdhqCO+UyJqFI1w4RMRmmZ5Ve5nV24lCc 1/ngCmx3FMTwS/kSfeKVftmIu3a93kTXRMb1eEL7VUqaBS0KwoRghQD8ktJC6SXF7/Q== X-Received: by 2002:a63:ac46:: with SMTP id z6mr3357901pgn.162.1546647670583; Fri, 04 Jan 2019 16:21:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN59gXNMYi+9HVxMw3AgoVh9PlXm5JT4Tg0TWeZL11rw11+amko8TQikx1qUGv++AHkoHa6t X-Received: by 2002:a63:ac46:: with SMTP id z6mr3357873pgn.162.1546647669800; Fri, 04 Jan 2019 16:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546647669; cv=none; d=google.com; s=arc-20160816; b=wsQOvtBq9GvPGZgnms9zs7VVWnJ67Y8zCwAyH//mjHfcIp5wqT+vQle+rxFTxohvL3 p3jE47YiUM1DzzNfFlRbH1RF7EYZkIvtBr14nJAI7nbR1DpFLjMjHWRlvdb3ujrl+L4D MSYhrqOK1+oJzoQX7/yjl/7UxtkRiRXPoAOZ8Pr25uJuksxphXHNPkEu6+JUhkc92OLW Rtp6X3qLo/6ixj85/IoNmPvYQm7i8d5aBvkPyCCDNqX4CKTNIrdLTaSyHv4QtV8Fiib2 mKiQtgXDROjo5P7d1bg6Xtsj3aI1fhhKKGQvnYAyJ7eag1VfHdED4MI5Fss44NitLr+q sS5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=dW7lWc9crn2H8wXW3I/dbbtBQcc06wSqi1SfSudgQuY=; b=VqmGaVsPYGHXj7sUtXgOQiHlnUGC31s2SpdBGvAHkrufMXHvEJqBLEZQ9mzO3pQcYu 5yqqRhVlXjHqOH0GjB8+AxnKqGk0i5JNUi2DRRSyWGAAmhvDMXf24cr5jYcfA0fu5Nqn rSu/ufjAQJz5hZ7SrFPTVAyM71q5M0ZSXjzokd8PeyImpirm/ixTl4J73s09/qeOC3ql bivWMYkVzcf3NuiELOVD5zBZR0pTZzrfx5EHsVrszUZSj4QAgQWahJ6mda1/b42fgItH ad6Cunvu3FFnz0StQlosl6IzA1ID+b/haP7IPanzT5XsREKAvLIGcmp0hemt9FU5e1V/ xrZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com. [115.124.30.132]) by mx.google.com with ESMTPS id j132si4261668pfc.84.2019.01.04.16.21.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 16:21:09 -0800 (PST) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 as permitted sender) client-ip=115.124.30.132; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R431e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0THYi1he_1546647563; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0THYi1he_1546647563) by smtp.aliyun-inc.com(127.0.0.1); Sat, 05 Jan 2019 08:19:31 +0800 From: Yang Shi To: mhocko@suse.com, hannes@cmpxchg.org, shakeelb@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 4/5] mm: memcontrol: bring force_empty into default hierarchy Date: Sat, 5 Jan 2019 08:19:19 +0800 Message-Id: <1546647560-40026-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546647560-40026-1-git-send-email-yang.shi@linux.alibaba.com> References: <1546647560-40026-1-git-send-email-yang.shi@linux.alibaba.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP The default hierarchy doesn't support force_empty, but there are some usecases which create and remove memcgs very frequently, and the tasks in the memcg may just access the files which are unlikely accessed by anyone else. So, we prefer force_empty the memcg before rmdir'ing it to reclaim the page cache so that they don't get accumulated to incur unnecessary memory pressure. Since the memory pressure may incur direct reclaim to harm some latency sensitive applications. There is another patch which introduces asynchronous memory reclaim when offlining, but the behavior of force_empty is still needed by some usecases which want to get the memory reclaimed immediately. So, bring force_empty interface in default hierarchy too. Cc: Michal Hocko Cc: Johannes Weiner Signed-off-by: Yang Shi --- Documentation/admin-guide/cgroup-v2.rst | 14 ++++++++++++++ mm/memcontrol.c | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 7bf3f12..0290c65 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1289,6 +1289,20 @@ PAGE_SIZE multiple when read back. Shows pressure stall information for memory. See Documentation/accounting/psi.txt for details. + memory.force_empty + This interface is provided to make cgroup's memory usage empty. + When writing anything to this + + # echo 0 > memory.force_empty + + the cgroup will be reclaimed and as many pages reclaimed as possible. + + The typical use case for this interface is before calling rmdir(). + Though rmdir() offlines memcg, but the memcg may still stay there due to + charged file caches. Some out-of-use page caches may keep charged until + memory pressure happens. If you want to avoid that, force_empty will be + useful. + Usage Guidelines ~~~~~~~~~~~~~~~~ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5a13c6b..c4a7dc7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5743,6 +5743,10 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, .seq_show = wipe_on_offline_show, .write_u64 = wipe_on_offline_write, }, + { + .name = "force_empty", + .write = mem_cgroup_force_empty_write, + }, { } /* terminate */ };