From patchwork Wed Jan 9 19:14:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10754847 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 07DD714E5 for ; Wed, 9 Jan 2019 19:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E874929058 for ; Wed, 9 Jan 2019 19:20:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9B7D2900C; Wed, 9 Jan 2019 19:20:14 +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 BDF012900C for ; Wed, 9 Jan 2019 19:20:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E42438E009F; Wed, 9 Jan 2019 14:20:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E16F68E0038; Wed, 9 Jan 2019 14:20:04 -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 D2F2A8E009F; Wed, 9 Jan 2019 14:20:04 -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 92E028E0038 for ; Wed, 9 Jan 2019 14:20:04 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 4so4722287plc.5 for ; Wed, 09 Jan 2019 11:20:04 -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=6Y4P+RH7kDCKB72PEaSDSCp4FAo31tuO+VrSZguuKT0=; b=HuWKuFvvMOu4d3+Qi5cUe7qpY6ciwM0nHKtehcwFDJkund1y+FuGCSFDIVNLwar6+u yQnPH2O5WHfDJm1M2yJQS4iriYcHIZKZqPChWaxhhJhoXpKbHnjjsshF07R//aJ7RWuL htzUMUzg8ya+AynmQoQ0NRg47PTI7A/ENcSMfKILVNIFnoo3q82xA64f8oZJHDBtNA1A NDJlRnw+eKPHbmpaaWp6ekQltfUOcCq1OT3ePUsB2FgTVLQRmT0bd/jnKRcASflpiZNc lvWBEoy8PuQMxjaOWj8/pRmYszl75F5tDJevlzz5/nE3jFZzLbqjQdmYtwfA0yfSa6aE AMNQ== 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: AJcUukfJFnd4pjNcH0+EwNAeNIJEAtSX1+lJ1ND/T8IFtA2TPNWDrXT+ lVTDhHfAmRJ69tAlfZg2ya96TWfklG1Z/ViAQNBaW3tlJGkSB1YWkk0kHYLQ5BMrO7LkoVByJfP SXb1TDCpxmYh14xI1SRt0Yl2xVlbwXWccr8FVMTiqFTTHbc5J0/u3Sh/SUTYZZvkXsg== X-Received: by 2002:a63:1d59:: with SMTP id d25mr6681366pgm.180.1547061604264; Wed, 09 Jan 2019 11:20:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN7ekJsAKldr1LEHiKI8YrfmohuZ3uz5y/gltUTFYG11L7YZU+QKl7k/gui1ZTbaKFuXPTXl X-Received: by 2002:a63:1d59:: with SMTP id d25mr6681303pgm.180.1547061602947; Wed, 09 Jan 2019 11:20:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547061602; cv=none; d=google.com; s=arc-20160816; b=ntnX0xf5Wgev7pGUHjwk5/SsohBRsMzHL5fmN5yjTAkz2WxtRxbu1dETeXFcFgsPVw yeNPHEf4KrZN7in4S78ZcME8/hDR0j+j7oeTlnK8lmpYb28/erADweq10lQDC7WNsmtn qp2DaRnMWjuu3N3GYMRSLbbxI0jIVkpFTTdXE7TwWOY0g4M225Z1ouCZsHuJ73R7vTqC GZX2PHFUfTDsUb/a0yPX5o6T8AGnXGMX+v/F6l0HWhlrBren6LkI05Qyt5gvUCD+PB3i GomMLbwROuAkh+tImSV2I5t5B4V7ZiFcUxYwYHJ5U6oBtLORwqcJvkgoLXM4ZSIXP6xU FGSw== 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=6Y4P+RH7kDCKB72PEaSDSCp4FAo31tuO+VrSZguuKT0=; b=gEOqlKnQHJwUiAHnElj8xiGKB20S14ic1RXce4PYQe9M+ihz4YX3oGVb8uGGrdpMfF o2f8fbjE0V4WyiPJ5sSibO7q/BOUzscocwDdN40ArNwY185zG9Cmd8QvyW0IJXOXd8xx 8ylG8k/rONGektvE4mo2A3kr8oOqTz5a7+ZAoI0uRp7W1tOu8qi0LKDEPWM/Ti/VfaRl u6L8SCLOc8yjT/xmFuFU+KEdh37USYN4P1q7EsNVMy5WnRnpO3w/zUkdF4ELLfVYIl62 W68/i0UXRqmzkycOVnzHe1I8vBlc8/t+fx8EA1MEMRCc0RB4s+bd1B74yyGAf+NwhOwO Xj0A== 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 x5si7000951pga.440.2019.01.09.11.20.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 11:20:02 -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=01201311R171e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0THtvvDg_1547061291; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0THtvvDg_1547061291) by smtp.aliyun-inc.com(127.0.0.1); Thu, 10 Jan 2019 03:14:59 +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: [v3 PATCH 4/5] mm: memcontrol: bring force_empty into default hierarchy Date: Thu, 10 Jan 2019 03:14:44 +0800 Message-Id: <1547061285-100329-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1547061285-100329-1-git-send-email-yang.shi@linux.alibaba.com> References: <1547061285-100329-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 Cc: Shakeel Butt 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 ff50810..5d42a19 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 */ };