From patchwork Wed Jan 9 12:20:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10753983 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 DE652746 for ; Wed, 9 Jan 2019 12:20:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB1BC28E99 for ; Wed, 9 Jan 2019 12:20:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF1C728EB8; Wed, 9 Jan 2019 12:20:44 +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 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 51FC928E95 for ; Wed, 9 Jan 2019 12:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 546A28E00A0; Wed, 9 Jan 2019 07:20:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F87A8E0038; Wed, 9 Jan 2019 07:20:42 -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 36CCC8E00A0; Wed, 9 Jan 2019 07:20:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id BF5048E0038 for ; Wed, 9 Jan 2019 07:20:41 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id t22-v6so1774967lji.14 for ; Wed, 09 Jan 2019 04:20:41 -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 :content-transfer-encoding:subject:from:to:date:message-id :user-agent:mime-version; bh=GKPKeE9zsCJfHrJ3BFOP9+uRYM0vh20Sl5vUoqB5QH0=; b=bygTI7iYRKtvFQPaEGq/sRbEYtziuGqGTJKxLVZlhhWmrRJDIMvd8Cjx3yO4VYAf/n R0Islm8XC7fPIk6ejorbul+NCY4sTyA8newja42qMfswe7w5rs9++ehOJLci1zlbz+T0 R3+s+osXmUiSQYsqB9pURSj7wMWiWm3AEmwTwckulEAmDmozcBwhle553Y+VoueH5TOJ yMlp+YwRD5oit1PhSNxdVK7RjVRDMhQJi+jygArhmUBLFX/I3e0nWPUeduw3tutjkF81 AUjCCwFQxVwP8NzSBsuyCgDIumy22eJiWsSYqu6+ERmxOSCQyNzmM7dG1vxgUxY0VEKE MHZA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com X-Gm-Message-State: AJcUukezB6X46KqeVYbPJAIqOi4JmQpXNXbBgaB65HwNlbnxgUZv3XT7 zwuO/joJIoOebwUlKgT+irM7NO3CtFWth5ct4RMiNmoADQfbDcJRyiundz7TGcPmihko1Cl5/Me Z/Ed6c1iXPB6QAn/YcXFYTjExsV4QbaVXB5+Grbj1A53FMjOkj+UQyxWghJWkguz98Q== X-Received: by 2002:a2e:131a:: with SMTP id 26-v6mr3609320ljt.107.1547036441029; Wed, 09 Jan 2019 04:20:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN5JWU4JZOOzLoUbK6sX7/EFN9cgHAL+Xg7oLDl1IR9tYD8fOzzEEwMpoj+WTI3XAfzCnGal X-Received: by 2002:a2e:131a:: with SMTP id 26-v6mr3609290ljt.107.1547036439981; Wed, 09 Jan 2019 04:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547036439; cv=none; d=google.com; s=arc-20160816; b=zfC8GFO+989gEs+46vVIbYyMheWyrLB5qi9NHRlc9b3tWjp0trt1VYgoJQcASvMbge w1tYAeda09rtmiOulbPWsgWra6RK5JHzbRiP7WgzeYVWTltIyl+5kDO2+qKV1GArHKKV 95f77qFxHttzlNtlyWkg7POhJI819avK3kBcD3cYJd3AjZn2CEn/uiz5IvjushqgC2eG ZHOKZWUdc/GaSIAb5eBYLpB2ZBmWQZKqocAoUBG08HXf5Lfhp+SpzwVxWzFosPy8sFpX tBHp76wyM5uhuqakyOZ5vSbzaUX0t7OmBOMF/4l8jkYVTPr7f/tdAlbOvknwtiGjDtvz SCaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:to:from:subject :content-transfer-encoding; bh=GKPKeE9zsCJfHrJ3BFOP9+uRYM0vh20Sl5vUoqB5QH0=; b=Izh4NcPIYHLGoqDmejIKI+8qxgza9kH8REIhAXFJy+0U/WbU/6JDNuDDKjdTxhYcYS eHjs/PDnVQap/RonKygAvA9RFJcJv0ieGSuBbfvu+Ddf7dMFHXsCePVF5AxIorpnNQxw 5Gw80fhMEwsE52qSrsw7eMtXAd2Bsv1CIjg1PUaW802rHEMkzoCmX/h6KW3cQDmOthji zSrnHhegDkbwo3t0YHZpyhR2fZ9g8U10TgKpZZhvJBGYyrcXrDiE/JafUWE5lybB7Wam U9PHQ6LYhpBmctNFNwKdsuFCHuG1UYSPCeBRSVPtRxDrBKxxqkj3ApeeXpPA0OEVMTpw VpRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from relay.sw.ru (relay.sw.ru. [185.231.240.75]) by mx.google.com with ESMTPS id q5-v6si75650981lji.207.2019.01.09.04.20.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 04:20:39 -0800 (PST) Received-SPF: pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) client-ip=185.231.240.75; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1ghCqJ-0004gq-0w; Wed, 09 Jan 2019 15:20:19 +0300 Subject: [PATCH RFC 0/3] mm: Reduce IO by improving algorithm of memcg pagecache pages eviction From: Kirill Tkhai To: akpm@linux-foundation.org, hannes@cmpxchg.org, josef@toxicpanda.com, jack@suse.cz, hughd@google.com, ktkhai@virtuozzo.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 Date: Wed, 09 Jan 2019 15:20:18 +0300 Message-ID: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 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 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. --- Kirill Tkhai (3): mm: Uncharge and keep page in pagecache on memcg reclaim mm: Recharge page memcg on first get from pagecache mm: Pass FGP_NOWAIT in generic_file_buffered_read and enable ext4 fs/ext4/inode.c | 1 + include/linux/pagemap.h | 1 + mm/filemap.c | 38 ++++++++++++++++++++++++++++++++++++-- mm/vmscan.c | 22 ++++++++++++++++++---- 4 files changed, 56 insertions(+), 6 deletions(-) -- Signed-off-by: Kirill Tkhai