Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp932475imu; Wed, 9 Jan 2019 08:43:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN4D2D5fcF77ks/knJu2zUMzRkP3ClNVgVWPsHDsPrNeh3nOOoCF0zMdrlz7MPrka5ShhuAb X-Received: by 2002:a63:3507:: with SMTP id c7mr6055864pga.315.1547052204656; Wed, 09 Jan 2019 08:43:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547052204; cv=none; d=google.com; s=arc-20160816; b=WBCegxIohb8YDu5z4yOUUV5WgPv0GCgCgfVmBOu4o8qrF6zQDqk0hgxS4UDuavLPia 40KPS2nNLXr1aBtZfHOIZltNhuQtvvF2gXJK2aIIl+xNmLJuaxnTChn0D7xQRgu+BaWV 24M8zSL258gD68yhvJqLF6T4ME08A/3A5beZ+Y6PHJtDCr0bPBItWg1PwEfqiQvXpqQl PNv98/8BR7jw50JTymcqzbSEvMuV3BmxHYV5QxQyxUEKvvQETUd8LSs6Ala2wLnWEq0o AEDIOsnPagYbui3y1L/3tlES2z3bKAQiNQSRA5S0Ns6dbzuQYFTjqCI7EYhQ5wSQBmaH AegA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=0plkDlC1B2y82zyr/pL8LRVnEgX12Evn7c2VaESelV4=; b=Bw1HbLHiTqEtt5eSTLfiaLEcM8aLmorkLdMv8EabRKPxgYkcjzkLQXgf4HKCOj0VoV dmEgO+ZJAz4UA4xD0gSqRzw3OWnTbhkfG1caDy6NsAdULj3LWWme6PFW7Hlpb6fFlIXW c+ZhKcrdjJjnwMQ2gMre/mMpeVCTWb8iBL/SXiNVmt3IyxW3EgZQHVSKm4huYT7/5BPf zMjPIQMjqqQj9i05/Kb8hOuKFTgud/A8Eyj352XfoytM2Chx18vbUFS7Fe9ec3BuGngZ vIXhKnQhjFH+cyzO9BRS9uqOtiZIzE5ELORgJ3cC1dvCiVhEf/e+rAO5ZQU6sZTUtUFN /0zw== ARC-Authentication-Results: i=1; mx.google.com; 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19si12506935pgf.573.2019.01.09.08.43.09; Wed, 09 Jan 2019 08:43:24 -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; 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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732569AbfAIQIP (ORCPT + 99 others); Wed, 9 Jan 2019 11:08:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:50220 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731882AbfAIQIO (ORCPT ); Wed, 9 Jan 2019 11:08:14 -0500 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1ghGOo-0007H8-Cg; Wed, 09 Jan 2019 19:08:10 +0300 Subject: Re: [PATCH RFC 0/3] mm: Reduce IO by improving algorithm of memcg pagecache pages eviction To: Josef Bacik Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, jack@suse.cz, hughd@google.com, darrick.wong@oracle.com, mhocko@suse.com, aryabinin@virtuozzo.com, guro@fb.com, mgorman@techsingularity.net, shakeelb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain> <20190109154932.tpc27dk2hzeycqex@MacBook-Pro-91.local> From: Kirill Tkhai Message-ID: Date: Wed, 9 Jan 2019 19:08:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20190109154932.tpc27dk2hzeycqex@MacBook-Pro-91.local> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Josef, On 09.01.2019 18:49, Josef Bacik 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. >> > > This isn't going to work for us (Facebook). The whole reason the hard limit > exists is to keep different groups from messing up other groups. Page cache > reclaim is not free, most of our pain and most of the reason we use cgroups > is to limit the effect of flooding the machine with pagecache from different > groups. I understand the problem. > Memory leaks happen few and far between, but chef doing a yum > update in the system container happens regularly. If you talk about suddenly > orphaning these pages to the root container it still creates pressure on the > main workload, pressure that results in it having to take time from what it's > doing and free up memory instead. Could you please to clarify additional pressure, which introduces the patchset? The number of actions, which are needed to evict a pagecache page, remain almost the same: we just delay __delete_from_page_cache() to global reclaim. Global reclaim should not introduce much pressure, since it's the iteration on a single memcg (we should not dive into hell of children memcg, since root memcg reclaim should be successful and free enough pages, should't we?). Also, what is about implementing this as static key option? What about linking orphaned pagecache pages into separate list, which is easy-to-iterate? Thanks, Kirill