Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1196346imm; Wed, 23 May 2018 11:52:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZuOn2ywa6C+RTKX6boiIAoMUpwHKnsEC47TNxLEzN220tT7d/M3ESCAJL68XN0cpU1dOy X-Received: by 2002:a17:902:284b:: with SMTP id e69-v6mr3983371plb.240.1527101547759; Wed, 23 May 2018 11:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527101547; cv=none; d=google.com; s=arc-20160816; b=Y7TVgDZJf0tKejkADW2BEwY3g69CDFq61eh9QIEyAXGYWGh/6YsVqGAKX+hkSCcYLE Hq0l28gPEW2SdoVQDyb1vHZEuUOIBldk2iwN22ZSqkkENNK58PnTYePQ0NG04zu3Z6Ln SvacuiJpq9SDgPjGYuvGicT5OL9LC/ocLF6IniUx89InL9GxutOwr58KLUeoBkgKF2I1 oVd9vgAWNqu/fAkV/VApxOxkdowDdF5H98HRkLD5AROmTgOL1oKR6FXvrTQIx1s8oz4m /CdBJGL5TGM4Go5aZyDZ9WjVREip1NYF5m0NUvAsBN1rw8pLk9E8sVsoAMNrAb+jPmTP W+6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=9U6A1Ro6rTIyzu6lM/AUu8I0xnd8/cO0kB0s+DrXUKg=; b=JRWzQFpD3q+xywWX1HN77y1LiwmB5uelDGIlK3he1m5WpGy6gYFjn8VFwanPn1w3mK uG5eC8pi0NQXuyZC24MM3OpTsJZFOoGd6C55mQfZhsDqle1Ji8yGoBrIZKIR/BIr38nr mw9dKxK3LoYrk32Un1OjqtuQXKhtzLG8XH84FBJ4MTIDamLHmOF6tfBZhAHb9V96CFOL Ba1mx5zRrsi9ej0FLmZPpJ5UlOLgS31Bn8R8Zv57ngWorTozysAOISUmmPa6DuDqlW8w UHKqr7+lBgs3UbX3nTtHRFPMfTVl0t3KQ0BcKvVoZxHnBIAmvzvKH+0i+BbayQGbRGSd BX0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=h3FNCqq5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si19160224ply.226.2018.05.23.11.52.12; Wed, 23 May 2018 11:52:27 -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=fail header.i=@gmail.com header.s=20161025 header.b=h3FNCqq5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934208AbeEWSuu (ORCPT + 99 others); Wed, 23 May 2018 14:50:50 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:44211 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933928AbeEWSup (ORCPT ); Wed, 23 May 2018 14:50:45 -0400 Received: by mail-yb0-f194.google.com with SMTP id s8-v6so6761088ybp.11; Wed, 23 May 2018 11:50:45 -0700 (PDT) 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-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mime-version:content-disposition:user-agent; bh=9U6A1Ro6rTIyzu6lM/AUu8I0xnd8/cO0kB0s+DrXUKg=; b=ANYpZXXd2iNzHFcG/8Am+jh12czK0dK3HJFUHtCeV0o3ZfkT8cYHnMg5H8UdNSe+YI nkiMSrO0kcCCRWn+aO68uKaIyg2r0Ofp/bsGX744LRmkQ3R8zRU5NcWfRfwCpUCcxsvo 8Y7Yr57N1NpC/8+3cc+KSRkOLV1NodfRPEMGhjMwDleZTBQXmRHjU4e4jeWkcCjO45vM /ojNExMN/4U1sK8Zoot93PigIKRmASnsgC0bBl9+Y+O1h8AvPmBiwSiCzc+TjzoCItNR 3HdbgYKmihHO7VM4Mi8eFhNmNaapAqBw4iDss5gH6BxWilG9gmzihx6yl6MAd12GHvZD RgZA== X-Gm-Message-State: ALKqPwd4zqdgRflspM5t2ujzXKzQj8E2zK/99Ba3JL/GQvu7HMZqPetc Cc5AMupQ5R5zej0ZevDy+q8= 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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; }