Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp680069imu; Wed, 9 Jan 2019 04:43:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN7KxP2MM1wV9u9/JMRekw7MUrh/X2iMJs+jEDFS+XILixGXQzJ/vF1VE71KHiw4/Qzlx3ii X-Received: by 2002:a17:902:6b87:: with SMTP id p7mr6000799plk.282.1547037818523; Wed, 09 Jan 2019 04:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547037818; cv=none; d=google.com; s=arc-20160816; b=yssKGaHIWPE1kSyJf/T/hgsYCFBr3emOE6jg9f4xxCwHZ7HrsDRCKPVgiRW+aGaxDh RimOf6VSBsewlDk8gbuwe55OebXLFFneml/rXDFNpkWMclSCtDhKYD68CdxLaoMK0Hb9 u6keBaMObyW00u0/tTzvsws0jIBmonH+npacznNm4qw+aQNpUHzoAM0zW/wbRsDOJRZ5 KSkP93hhmHZVi2BYsuURPt8AcsGmC+raBDJ53oFodFFK5JRKIXDp2gFqAgzLFw2OpMbB VAZ47Oe4fJ7AneCG5DznEZnYgyiIutrpZx1Hl6ZjN0GIPnv3yjGiSlyc/lZdbonuNf2d Theg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=DlQlWlVWuj5IakiQCuo6n4LBXun72uWkrZSTrhrcs3U=; b=pGv1BKHxi5oTkbolwyqe9zCQzqFbDrr/98fRAe9EMBuGKVXuA2cKYQNus1nHH4U4Ti rFiI1Z18Bgbk7Gqi8x0DcFAGZY347uBcfh966FOztCvKnFJVzm6xu8yXlDa0QFlvWyWt 0TpTqmUulVDW2EfL2q74OSbkSFg/a9V2hbIRgLex/hgr+/1vG/ycWHxC0oVZja0RzHrI +RE96QTjEH7i3e2HIgBCnAyA0k5vnyf1PGwXeneKoNP1gIeeylIYz4QzHcerI4xknRk8 OOEwi/qaHvcUJHKrQWCIRHHM1KoZikHdbY6MD7kEsToqkpw8qJrB4fl3NfRCXWvdl9YT Zz3w== 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 b14si13195507plk.333.2019.01.09.04.43.22; Wed, 09 Jan 2019 04:43:38 -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 S1730821AbfAIMUw (ORCPT + 99 others); Wed, 9 Jan 2019 07:20:52 -0500 Received: from relay.sw.ru ([185.231.240.75]:42310 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729911AbfAIMUh (ORCPT ); Wed, 9 Jan 2019 07:20:37 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1ghCqU-0004h4-FM; Wed, 09 Jan 2019 15:20:30 +0300 Subject: [PATCH 2/3] mm: Recharge page memcg on first get from pagecache 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:30 +0300 Message-ID: <154703642996.32690.7131436841852687919.stgit@localhost.localdomain> In-Reply-To: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain> References: <154703479840.32690.6504699919905946726.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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);