From: Kirill Tkhai <ktkhai@virtuozzo.com>
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
Subject: [PATCH 2/3] mm: Recharge page memcg on first get from pagecache
Date: Wed, 09 Jan 2019 15:20:30 +0300 [thread overview]
Message-ID: <154703642996.32690.7131436841852687919.stgit@localhost.localdomain> (raw)
In-Reply-To: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain>
This patch makes pagecache_get_page() to charge uncharged
page into memcg of process, which accesses the page first.
Page will be returned in case of it's charged only, so
memcg tasks can't use pages, which was left by __remove_mapping(),
without accounting them. In case of accounting is not possible,
pages remain in pagecache, and further global reclaim will
remove them (and this will be easily, since pages are not
mapped by any task).
Also, note that uncharged page can't be dirty or under
writeback, since it was able to be isolated in __remove_mapping()
earlier.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
mm/filemap.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index 65c85c47bdb1..2603c44fc74a 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1576,15 +1576,18 @@ EXPORT_SYMBOL(find_lock_entry);
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
int fgp_flags, gfp_t gfp_mask)
{
+ struct mem_cgroup *memcg;
struct page *page;
+ bool drop_lock;
repeat:
+ drop_lock = false;
page = find_get_entry(mapping, offset);
if (xa_is_value(page))
page = NULL;
if (!page)
goto no_page;
-
+lock:
if (fgp_flags & FGP_LOCK) {
if (fgp_flags & FGP_NOWAIT) {
if (!trylock_page(page)) {
@@ -1604,6 +1607,31 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
VM_BUG_ON_PAGE(page->index != offset, page);
}
+ if (!mem_cgroup_disabled() && !PageHuge(page) &&
+ !page_memcg(page) && !page_mapped(page) &&
+ test_bit(AS_KEEP_MEMCG_RECLAIM, &mapping->flags)) {
+ if (!(fgp_flags & FGP_LOCK)) {
+ drop_lock = true;
+ fgp_flags |= FGP_LOCK;
+ goto lock;
+ }
+
+ if (!WARN_ON(PageDirty(page) || PageWriteback(page))) {
+ if (mem_cgroup_try_charge(page, current->mm,
+ gfp_mask, &memcg, false)) {
+ unlock_page(page);
+ put_page(page);
+ return NULL;
+ }
+ mem_cgroup_commit_charge(page, memcg, true, false);
+ if (!isolate_lru_page(page))
+ putback_lru_page(page);
+ }
+ }
+
+ if (drop_lock)
+ unlock_page(page);
+
if (fgp_flags & FGP_ACCESSED)
mark_page_accessed(page);
next prev parent reply other threads:[~2019-01-09 12:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 12:20 [PATCH RFC 0/3] mm: Reduce IO by improving algorithm of memcg pagecache pages eviction Kirill Tkhai
2019-01-09 12:20 ` [PATCH 1/3] mm: Uncharge and keep page in pagecache on memcg reclaim Kirill Tkhai
2019-01-09 12:20 ` Kirill Tkhai [this message]
2019-01-09 12:20 ` [PATCH 3/3] mm: Pass FGP_NOWAIT in generic_file_buffered_read and enable ext4 Kirill Tkhai
2019-01-09 14:11 ` [PATCH RFC 0/3] mm: Reduce IO by improving algorithm of memcg pagecache pages eviction Michal Hocko
2019-01-09 15:43 ` Kirill Tkhai
2019-01-09 17:10 ` Michal Hocko
2019-01-10 9:42 ` Kirill Tkhai
2019-01-10 9:57 ` Michal Hocko
2019-01-09 15:49 ` Josef Bacik
2019-01-09 16:08 ` Kirill Tkhai
2019-01-09 16:33 ` Josef Bacik
2019-01-10 10:06 ` Kirill Tkhai
2019-01-09 16:45 ` Johannes Weiner
2019-01-09 17:44 ` Shakeel Butt
2019-01-09 17:44 ` Shakeel Butt
2019-01-09 19:20 ` Johannes Weiner
2019-01-09 17:37 ` Shakeel Butt
2019-01-09 17:37 ` Shakeel Butt
2019-01-10 9:46 ` Kirill Tkhai
2019-01-10 19:19 ` Shakeel Butt
2019-01-10 19:19 ` Shakeel Butt
2019-01-11 12:17 ` Kirill Tkhai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=154703642996.32690.7131436841852687919.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=darrick.wong@oracle.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=josef@toxicpanda.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=shakeelb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox