From patchwork Wed Jan 9 12:20:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10753979 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 797B01850 for ; Wed, 9 Jan 2019 12:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F4C28E97 for ; Wed, 9 Jan 2019 12:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66F1A28EF7; Wed, 9 Jan 2019 12:20:40 +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 7BC7C28EBB for ; Wed, 9 Jan 2019 12:20:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B4148E009E; Wed, 9 Jan 2019 07:20:38 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 73C3D8E0038; Wed, 9 Jan 2019 07:20:38 -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 62B2F8E009E; Wed, 9 Jan 2019 07:20:38 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id EB4AE8E0038 for ; Wed, 9 Jan 2019 07:20:37 -0500 (EST) Received: by mail-lf1-f72.google.com with SMTP id m19so561225lfj.17 for ; Wed, 09 Jan 2019 04:20:37 -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:subject:from :to:date:message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=DlQlWlVWuj5IakiQCuo6n4LBXun72uWkrZSTrhrcs3U=; b=jXBcAlr7vdtpnl9JB+oSn5lD2QSowl83EeHRY2R2x6LAV5JVDXKgd8wBIydPd1T+vS QE0SP4woFIaxNtto4SxazzBJOnomjQKzndG5Pb0qgD5kFZpZrSnEBHnEgh5c3hIC5j8T H0VzXD1ejmr9pfC5gDBj18EcPbiaGlhUvTuwgJKxqdXHOxziTuGKdW1ONTuLx85uJZet oW+ZzqobYy+u8lkI0M9/1i1IngHdc2xvBU5oDaAYDAMzyZ/8DxuljNqenrWTgCv6WV7l PW8QLYkcL+AZMLeXuNTvhbkSG/2tI0tG5U272u8/b+Hxla0GyGWvH10mWf+MfU0MMzQO NX3w== 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: AJcUukePMazWSu/STDco2GN232t0PlKEOJ8uiUSVpRIVIFRtuWWm7P2p LxYww8EiaUIKwsQgCRMSex3kcdcJOFTlNaIFidzW2ikgFHKdi0b6NssQPgZWyDJRaQWa2VgykI9 2qqWAWSnVAvg8bJCEZ/+hUe5ZxbTBg4XMoA1UN0L7Cl6EYNi4jeGWkymbgRTN2A8WgA== X-Received: by 2002:a2e:a289:: with SMTP id k9-v6mr3267522lja.24.1547036437214; Wed, 09 Jan 2019 04:20:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN5wg76lhjKNqeRCDIxd6SfdwcHR5dUq1oQvHl+djSx7CbX/whpB0HvPQ+710rjUVPyfVhMY X-Received: by 2002:a2e:a289:: with SMTP id k9-v6mr3267477lja.24.1547036436124; Wed, 09 Jan 2019 04:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547036436; cv=none; d=google.com; s=arc-20160816; b=o1+4ERFIuauT9EqAcuEM2A9qggLxZZhKZh34zEwc6ZOcyb/zhH4C5ZAgoTjJ9TOsSO jmhte5RvXCT9uJu+HbAI2B8oh/AszrFzyhRERfRFh1D2GrX4FlDkWINCv1S303pXYUsO Uwelc6fgse0A2rpPnSpsTru/1C6FKQBnxIzUbqLYES4DKDuYAn9qLaFwhd7YajHQa4zP gUHW+yvxNshfj/aaJWosHOtb4eDwGIi5F83YFN08jHF7KT6Z65fDEgOeUI0oHbzEjFwW NsQjjtbEtPgiebOtRQwyMiLCgzV5SrnBrm3curZKRQkySzeGcEUmG1OD2/U2YmTqiEJ/ ehIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:to:from:subject; bh=DlQlWlVWuj5IakiQCuo6n4LBXun72uWkrZSTrhrcs3U=; b=b83lOkRH69EKkXdjla0vOoiobc1HCa8mrsiYnQtdCVuvWGX+5jTLdK96Vnvdz2BO4E Ycts31C2ksgQ6TfuEez3sSVxCoV8v1pGPDSG+BNC3C0ZZ1WpT0JcwY9KU+PUqlCCWgxC eRsCOp1rixPeZaX/q8GZ0/U4LWH6DT1g6nRVh4+IZFqffYStqAHY6XWJaIn+Vrpu4tEj hAPvsugekR1qxdlXIEldlrJCvA5Tnzz4UAKMP7Y/anhtM75Ld4Q7WtOQHUEswRyRJN5d aozDgpkfOTNj9PEhfvh7FwuROpIESnNpdHzcTK4bZ2x6lsJ1KpywYvYVQqVA6ZoInCaM UDhQ== 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 p11-v6si61579253ljc.73.2019.01.09.04.20.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 04:20:36 -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 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 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 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);