Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1031554imu; Wed, 9 Jan 2019 10:20:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN5FQEiTGBxv6dQVBNrggRo4tsDPXR+qB0v1Bpm+CaSwu4FJIyJy7lSO2XC9h0C3EGzUqwn/ X-Received: by 2002:a63:e156:: with SMTP id h22mr6408495pgk.255.1547058020601; Wed, 09 Jan 2019 10:20:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547058020; cv=none; d=google.com; s=arc-20160816; b=OfTv/SfSuKvvOstzU1ypqvJwdoWcw5rC4gGGZydOQAeexucoAUqX2N/efyB+QbqV92 SX8ySpD4LpVtKbvKBfGS0A0IlL9hKUISO7YBCpnbUUQT+zCvQGp0AnbhuvHpqhhtezAO kuwYLNbJ9/arI5QKOfZVcxgwDMLknmlLDq7ku5utgbNOAiRerLzsACjdTbjwFuGqHZpU wICue4iX+FNtAA/m4x2dUCKL5R+RjaLsl9r2vJYpYkLMt6HoziaAZ467Msooxvg2twpf obkC9Pl1Zlq2EkpJ05hXcb7GTAfcGrwb6LrrmnyFrAwxn5JQqi3qcJqbQxu3FQfrXXGP wQ8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=favChGVhwPSbb8qcnD+cylPo0WpvRGC/2kNhSiLoKK8=; b=yn4I32pUsWo433Y9nfIp3LAP8g3cw63IJizKIU2JSZKr2mRBphngSlHbcFVOCC6bBV shMbunvTL9m1FuJpcwlDiNYkoq31UW7sddza0kYOMFatNbL+/iNjahXqfAKpcCSFX1kR NA/Golh1YaoVufIJWP+Xpncb4VddqqQm7zIfLawIk7ub7ujG6ImGZhL79dZi+RfkmC2o upq+npmQN1exj3nr/xdjUzVROTDWAcQ/jXA0na4EphYF2uBM/QhtgP+pd9UsYy7INHAX Vy3lu4LBhkRMwjtslRBvU21vc6VuPpWwANoqodAnMuMnzGDu3i9YU27LXZwzuB5muiic iV4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H8OQnYnD; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si67858909ply.372.2019.01.09.10.20.05; Wed, 09 Jan 2019 10:20:20 -0800 (PST) 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=pass header.i=@google.com header.s=20161025 header.b=H8OQnYnD; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727091AbfAIRol (ORCPT + 99 others); Wed, 9 Jan 2019 12:44:41 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:34638 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbfAIRol (ORCPT ); Wed, 9 Jan 2019 12:44:41 -0500 Received: by mail-yw1-f67.google.com with SMTP id g75so3296438ywb.1 for ; Wed, 09 Jan 2019 09:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=favChGVhwPSbb8qcnD+cylPo0WpvRGC/2kNhSiLoKK8=; b=H8OQnYnDpT/QD8T010mYLe6weU82h+c6bUshO5RhL5vAF554uG6GZy8gWGa/3gfk3A nRuMdujfUO9i70TZ6N/RN/xV5IIAKoHUnw660UAZj+DX8C9BKGe6HkFU1WllF3x/wmm+ swls2lbw927qvQwGYx0s29w7oefWC+1LSRZBy2JJj682ePp/b3mdRbG74WSZNF78WxAG 6MlXRKuS44x6JrmgflIOiMtVd5XrUiq7sJRyvZx5fFj1GoRdpSP8LU6n6sJFrpBWmQO0 KK7MYHv6ZAg5OTUACAhCRn76t1JjuTE3xrKeeOMGcHmrWHtejxUi3laCB6hSlFpoNgvL 4xhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=favChGVhwPSbb8qcnD+cylPo0WpvRGC/2kNhSiLoKK8=; b=Dp/1LXZj9v1e+/QA5fsY1rzO4n4nwTripDP1+24f4z1zHkAPHxpSjXRJ0h49qzgrhH EBaGn52JjynG5ED2t2+z1Lnxmmtm9Ih5OxwWGYTRYLlO7LyISuc9zAljrhWfVUQbknI3 2PvDwdAPDHTiFNENegURy+CrbNge5ONB9z9lQYQ2rKFs8sUMZWF1yqZVxA8mT3D1FOLC MNqpw2JBZSPuq1/bgqeyEyOM2ACbar0bXfICDS7J3Sbst3QAA3WdCtyW5iVJOigSk6++ nslJ/5g+06jfDXpNKklzTnam3XOSTWWXHWMJwf9jF2bcGgBuztAFvSwByy1dxwN17a3i jIWw== X-Gm-Message-State: AJcUukemHwCtPe1OzToVFWmOepKuPblhZ2HxLJWgor/NG0sPUDg9PDzW 2c+ubKvEAInus8YkrUvf/G3YKJ9CA4BBUeHUUcJWSw== X-Received: by 2002:a0d:e4c5:: with SMTP id n188mr6537504ywe.349.1547055879675; Wed, 09 Jan 2019 09:44:39 -0800 (PST) MIME-Version: 1.0 References: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain> <20190109164528.GA13515@cmpxchg.org> In-Reply-To: <20190109164528.GA13515@cmpxchg.org> From: Shakeel Butt Date: Wed, 9 Jan 2019 09:44:28 -0800 Message-ID: Subject: Re: [PATCH RFC 0/3] mm: Reduce IO by improving algorithm of memcg pagecache pages eviction To: Johannes Weiner Cc: Kirill Tkhai , Andrew Morton , josef@toxicpanda.com, Jan Kara , Hugh Dickins , "Darrick J. Wong" , Michal Hocko , Andrey Ryabinin , Roman Gushchin , Mel Gorman , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Johannes, On Wed, Jan 9, 2019 at 8:45 AM Johannes Weiner wrote: > > On Wed, Jan 09, 2019 at 03:20:18PM +0300, Kirill Tkhai wrote: > > On nodes without memory overcommit, it's common a situation, > > when memcg exceeds its limit and pages from pagecache are > > shrinked on reclaim, while node has a lot of free memory. > > Further access to the pages requires real device IO, while > > IO causes time delays, worse powerusage, worse throughput > > for other users of the device, etc. > > > > Cleancache is not a good solution for this problem, since > > it implies copying of page on every cleancache_put_page() > > and cleancache_get_page(). Also, it requires introduction > > of internal per-cleancache_ops data structures to manage > > cached pages and their inodes relationships, which again > > introduces overhead. > > > > This patchset introduces another solution. It introduces > > a new scheme for evicting memcg pages: > > > > 1)__remove_mapping() uncharges unmapped page memcg > > and leaves page in pagecache on memcg reclaim; > > > > 2)putback_lru_page() places page into root_mem_cgroup > > list, since its memcg is NULL. Page may be evicted > > on global reclaim (and this will be easily, as > > page is not mapped, so shrinker will shrink it > > with 100% probability of success); > > > > 3)pagecache_get_page() charges page into memcg of > > a task, which takes it first. > > > > Below is small test, which shows profit of the patchset. > > > > Create memcg with limit 20M (exact value does not matter much): > > $ mkdir /sys/fs/cgroup/memory/ct > > $ echo 20M > /sys/fs/cgroup/memory/ct/memory.limit_in_bytes > > $ echo $$ > /sys/fs/cgroup/memory/ct/tasks > > > > Then twice read 1GB file: > > $ time cat file_1gb > /dev/null > > > > Before (2 iterations): > > 1)0.01user 0.82system 0:11.16elapsed 7%CPU > > 2)0.01user 0.91system 0:11.16elapsed 8%CPU > > > > After (2 iterations): > > 1)0.01user 0.57system 0:11.31elapsed 5%CPU > > 2)0.00user 0.28system 0:00.28elapsed 100%CPU > > > > With the patch set applied, we have file pages are cached > > during the second read, so the result is 39 times faster. > > > > This may be useful for slow disks, NFS, nodes without > > overcommit by memory, in case of two memcg access the same > > files, etc. > > What you're implementing is work conservation: avoid causing IO work, > unless it's physically necessary, not when the memcg limit says so. > > This is a great idea, but we already have that in the form of the > memory.low setting (or softlimit in cgroup v1). > > Say you have a 100M system and two cgroups. Instead of setting the 20M > limit on group A as you did, you set 80M memory.low on group B. If B > is not using its share and there is no physical memory pressure, group > A can consume as much memory as it wants. If B starts and consumes its > 80M, A will get pushed back to 20M. (And when B grows beyond 80M, they > compete fairly over the remaining 20M, just like they would if A had > the 20M limit setting). There is one difference between the example you give and the proposal. In your example when B starts and consumes its 80M and pushes back A to 20M, the direct reclaim can be very expensive and non-deterministic. While in the proposal, the B's direct reclaim will be very fast and deterministic (assuming no overcommit on hard limits) as it will always first reclaim unmapped clean pages which were charged to A. thanks, Shakeel