From patchwork Wed May 23 18:50:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 10422047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3CAB96032A for ; Wed, 23 May 2018 18:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A58529199 for ; Wed, 23 May 2018 18:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25CAF291C4; Wed, 23 May 2018 18:50:51 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID 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 9CF98291B7 for ; Wed, 23 May 2018 18:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F1C66B0008; Wed, 23 May 2018 14:50:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A0466B000A; Wed, 23 May 2018 14:50:46 -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 7425B6B000C; Wed, 23 May 2018 14:50:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw0-f199.google.com (mail-yw0-f199.google.com [209.85.161.199]) by kanga.kvack.org (Postfix) with ESMTP id 3E2F36B0008 for ; Wed, 23 May 2018 14:50:46 -0400 (EDT) Received: by mail-yw0-f199.google.com with SMTP id m5-v6so876834ywc.11 for ; Wed, 23 May 2018 11:50:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=9U6A1Ro6rTIyzu6lM/AUu8I0xnd8/cO0kB0s+DrXUKg=; b=JdYx8C3vU2HfRnHp6CkxlQADVSWTBXBK+Bs9bqRlkL4+lULUkFcL9vZDyxpcf280hM kRVWpBuWeSXgyG482OA8iqCCDLttbSc1Z6cn23iS3I4dONNYm0mbgd2iO2+OxK2oQS1n eV4dsXYO30vFI9nQ1OCIhTEoRkSlV7eqTOqoHhpfu7i/2/p/VTvNrqKm7RXYV6G2nf/2 66uS/zfLQYOJNz5hNEIcrjvkeQQQ1dlLKJ3BeoR5+/yQZkxFuDrbvWQisy3135rjWLUa sPcXwufs5nEi4maIAXGRqVq5OH53BkpWbmI2pU13VQQARO4ne7eAHcckeBdHP/mGnLud 6Zhw== X-Gm-Message-State: ALKqPwf12n5npUucunb2Ji6nRfcSMEhqpE2r3c9LduooM1z/6tN/MKpr PWZOJT5Dd4Qe0x6dlitz+lFzxmeY6onHF48xD7kaq9Ygw6on2H/1ozqXPxKdP/AU64I8YBVu4Gl FR/p5jJb6Bw8nraeu3fOMzIa+m3WDGhOiVMIUSBognerSSBSnV4FF7vRxGs9SBTjW8L1QYH18xy tHHLIOb/GG7+x3Ydb3D+YA/xactxynqjXqhT6NHe9yTkz/NEGZGeKOzclGXAlEANgoCMZD86zb5 lZWs8PxozIT5VtRfexU9dNZuMehNwQQ++SJrwqr42BCViSaI6seQSoUCUARf81V3ZnPKPfAN1c+ Ci2Do09RZWrOIoZkezKd6NC2MdXDuHDxLyjYNgBLCWtsdzyvIL+F8QISZpGRTkZA6pl3nvCDyg= = X-Received: by 2002:a81:830e:: with SMTP id t14-v6mr2174778ywf.203.1527101445843; Wed, 23 May 2018 11:50:45 -0700 (PDT) X-Received: by 2002:a81:830e:: with SMTP id t14-v6mr2174759ywf.203.1527101445212; Wed, 23 May 2018 11:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527101445; cv=none; d=google.com; s=arc-20160816; b=McBhGsAvrH4NspmuhzfUNtF3WqtM++kyHNEG9KQZ9Nxw9YSEK4t21cUxYoku2MMV4F Oir+xKnpIH7XV+6b5C0aKnO/yxcANEpr6ugWESdUj0BzaNAC3jJsG52rV9/HlVhGs1aa 7OYKNGaahscAmQ8POszpc99FYq5pV3pmXI3syDUTXBSlJ52o1q6QdwfwR/ayi1MUdTuA 2Nb/zz9xC3qw9N16b3Ln1wLtmLsXM8zj2D2RHP5YjEyxS+tTxQHObgT2s845kjQAZDyE kiMUbJU49Dn/BHaVG5vH4IEmWWb5Zdoms4x8VdPYLNs0hSbqwft+gm3kozWyHJB/Zujo fZ9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:sender:dkim-signature:arc-authentication-results; bh=9U6A1Ro6rTIyzu6lM/AUu8I0xnd8/cO0kB0s+DrXUKg=; b=EnNu0U1iwuRnXg/faLnfB4wG8eUwfsXDf8vT1O+mEZx+Y68OXSpoJYeGUOia/9gr6Y 3LkfAUTIKRjarLu3xAblx9gOQNf7NbJwgeD6z9T88tUuBtAkVOP0jLQYs/DEpdyX/JaR N0pOH2NSvBFuUl0dsPU9pWk+q1Pi5MqEwA7LS7qW1nxTegWMXj3CoOdkMoU66j7N0hz/ XKD/9ex6Bis4cZUj8n2XlPWg1OJqi7ByGhuuX1oQ1T1je7/ybup1YGUp3yEdPAseW4xh jwpbyrg+NrRMmQ8V1Dup2DRlM3+l0hjmYidgqCC0ZGi5MUmvSmYf5YQdZ8gwimscq5la DzLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h3FNCqq5; spf=pass (google.com: domain of htejun@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 2-v6sor1558916ybm.141.2018.05.23.11.50.45 for (Google Transport Security); Wed, 23 May 2018 11:50:45 -0700 (PDT) Received-SPF: pass (google.com: domain of htejun@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h3FNCqq5; spf=pass (google.com: domain of htejun@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=9U6A1Ro6rTIyzu6lM/AUu8I0xnd8/cO0kB0s+DrXUKg=; b=h3FNCqq5NFelKs3/BUgkNQFJMZG/jrs8XdggvVjBeL5RE9iyEaqEjOY/PIq1umM+bZ Z0FK9UqQeUIaT/DJUcJAq3Iyd8VrviFod8yfhMVn9TadGXVjKtL87EZmyzcdNurBihg6 bRNr/sNGcRCrvnZFzcTcZo92eKX5J8jxLPQ3hTRjOYlOKBp7mZXbqbs4PWOAhAlUHjxs 6EDP2nCWpAAZbNb3qW32awm6JaXAIKpAt27QCEuc/YhvLLM3Nc27lEyJUB5PB8E2shqH HMKR6qnvZlKXkelZwhP7INnhHW1rlShw1LrN7hpif0SafzPPbml+SqB//+MuybfgEyp6 HYyA== X-Google-Smtp-Source: AB8JxZrmVNpBqGHUuaYy1b/BVgF50aYCbzoW9vARZml8VVpj+7S9mVhzjAjghqMoLlYbm4Ap9X0LBw== X-Received: by 2002:a25:1a04:: with SMTP id a4-v6mr2318933yba.53.1527101444821; Wed, 23 May 2018 11:50:44 -0700 (PDT) Received: from localhost ([2620:10d:c091:180::1:6407]) by smtp.gmail.com with ESMTPSA id n80-v6sm8916896ywn.17.2018.05.23.11.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 11:50:43 -0700 (PDT) Date: Wed, 23 May 2018 11:50:41 -0700 From: Tejun Heo To: Andrew Morton Cc: linux-mm@kvack.org, Johannes Weiner , linux-kernel@vger.kernel.org, kernel-team@fb.com, Michal Hocko , Shaohua Li , Rik van Riel , cgroups@vger.kernel.org Subject: [PATCH REPOST] mm: memcg: allow lowering memory.swap.max below the current usage Message-ID: <20180523185041.GR1718769@devbig577.frc2.facebook.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Currently an attempt to set swap.max into a value lower than the actual swap usage fails, which causes configuration problems as there's no way of lowering the configuration below the current usage short of turning off swap entirely. This makes swap.max difficult to use and allows delegatees to lock the delegator out of reducing swap allocation. This patch updates swap_max_write() so that the limit can be lowered below the current usage. It doesn't implement active reclaiming of swap entries for the following reasons. * mem_cgroup_swap_full() already tells the swap machinary to aggressively reclaim swap entries if the usage is above 50% of limit, so simply lowering the limit automatically triggers gradual reclaim. * Forcing back swapped out pages is likely to heavily impact the workload and mess up the working set. Given that swap usually is a lot less valuable and less scarce, letting the existing usage dissipate over time through the above gradual reclaim and as they're falted back in is likely the better behavior. Signed-off-by: Tejun Heo Acked-by: Roman Gushchin Acked-by: Rik van Riel Cc: Johannes Weiner Cc: Michal Hocko Cc: Shaohua Li Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: cgroups@vger.kernel.org Acked-by: Johannes Weiner --- Hello, Andrew. This was buried in the thread discussing Roman's original patch. The consensus seems to be that this simple approach is what we wanna do at least for now. Can you please pick it up? Thanks. Documentation/cgroup-v2.txt | 5 +++++ mm/memcontrol.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) --- a/Documentation/cgroup-v2.txt +++ b/Documentation/cgroup-v2.txt @@ -1199,6 +1199,11 @@ PAGE_SIZE multiple when read back. Swap usage hard limit. If a cgroup's swap usage reaches this limit, anonymous memory of the cgroup will not be swapped out. + When reduced under the current usage, the existing swap + entries are reclaimed gradually and the swap usage may stay + higher than the limit for an extended period of time. This + reduces the impact on the workload and memory management. + Usage Guidelines ~~~~~~~~~~~~~~~~ --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6144,11 +6144,7 @@ static ssize_t swap_max_write(struct ker if (err) return err; - mutex_lock(&memcg_limit_mutex); - err = page_counter_limit(&memcg->swap, max); - mutex_unlock(&memcg_limit_mutex); - if (err) - return err; + xchg(&memcg->swap.limit, max); return nbytes; }