Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4664165ybc; Fri, 15 Nov 2019 08:09:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzxku2HOLaNWPRrtyzqbvjyNsSzDcvqRZ8Dt0yiklbbfd6D9OSI37QEq1xwLYMC2iSskl9b X-Received: by 2002:a17:906:b2c7:: with SMTP id cf7mr1866551ejb.218.1573834194082; Fri, 15 Nov 2019 08:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573834194; cv=none; d=google.com; s=arc-20160816; b=iN/4ld2ebE8xSMDRIQ9fuFQXh1H+bXVLrjpO2DL3Z+MnlIkMasONSmd08egWwr5aGU ZiL8GxUnI0PItmti2BuET2CClIR1S0dYOdrpxsDfSLxL/L0ETo/nWaEm3YVehXaEkOw6 V9gs0Huwmp7FLEssmGmxomYRL+DgXVtjrEyphZ7mr2BamnL/DkUYMoBg9ysRlAH73jKm JpAupBjVOWkxsVSXUpA4lbuEXsiXBLxG1WfDT5K/WP/6sbuR9L28HBf9+AwWA1w5h9q6 epEckQRdlk5ONOnahWRSjfoz5Mtvy0GIh1ch8hNVoZ70NpjrFA52AbWJQz3N61icbfKx uEvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1MDIj/Ne5pWo+qodnUOYNjkosiDdOXlcWKy8+ElVdyg=; b=m2Wzr53U5bzKjSmFzZsy6yEPIE3tXnPnvdX/nHngIQl1yLd2mr0zn0rquUBHFExAX7 6r1wBi3zoJwUrltg9+pTpqpkxUAh5HXZKNpJru2D3r127RWwQJEZbCRHtW+9lRcjEMaP bse4NDz7CAqqvJ87qdXdPTmyUfUuNUq3EXy8zHgwlSe/l5gA+EHyaPnfDwHBbRce9ZCB gBnCn+IMcuh79rrr5EXoxgejbdEoK8jc+g1b43GeTOOquZkEaxJfcJqqfLD24yN5JuLf 5Dz1Zm7vY9LlHNKJduH3R3plJ9lLSg3Umls3C44UPtePP4xJBtZi1yJk/cEK3oJjkBLS LvKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=HzFBCREP; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s23si5742132eju.55.2019.11.15.08.09.28; Fri, 15 Nov 2019 08:09:54 -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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=HzFBCREP; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727632AbfKOQH1 (ORCPT + 99 others); Fri, 15 Nov 2019 11:07:27 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42028 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfKOQH0 (ORCPT ); Fri, 15 Nov 2019 11:07:26 -0500 Received: by mail-pl1-f196.google.com with SMTP id j12so4949825plt.9 for ; Fri, 15 Nov 2019 08:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1MDIj/Ne5pWo+qodnUOYNjkosiDdOXlcWKy8+ElVdyg=; b=HzFBCREP8wXPZZXgWF27J4qUzWH5xoBUAuAtElEVPcSC+Ki7U/c5SUXGvYZa01flfV YDHshfhjrztIe8xP8xPhd0nx9YE4eVyuCblRCwS1pg7oij+8FE1TrEk6Jj+fNx6W+AHI IYJZHmpNmtsc6G8iFGqUHRz8muPDmz4HrNqZ0zvq6vfgirhS0QoZnsj8w6jFmfHkfh7U 4+cd6pqvCvowO/FlGZ1B/OCnQxWPbEIlFGrWe1Ss8FEf4VixRWYaqnJ/T8tNNgV4NOiC GIYUSUi39Pu5pVdEbudq/SadJ+Hy2Pg2kisrZ/lT3gydRjxhPK7Lg+wUJrhxZoUP8mHx qhhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1MDIj/Ne5pWo+qodnUOYNjkosiDdOXlcWKy8+ElVdyg=; b=dDuzS2HmZXy7EyiUElrMXWHPBDVaAr1M8ixMuLzAGDe1xh1CQgxtSHsCKOf4tMk35M x1xTDq8b8syAiJ7dM6iTlcT3bImliF3r3PK5YXqfLgxLaaulfa2+Tx7LxT9le4KYUb/R cIqKUi02fqN/5lbt+wIFUdLFSe0ERlytZo7Ujbaujh+p9gyERS/uOejEvXtuXZ0dLbCO CENyCxoCEhWLb1oXfElRyue7HuAlkVfkfCbJMlihlAVETgc1kcShKxrJz+puluR1aXdh 2seKzMRvQ5AwWZ6CcKbZtym/MCB6NS5MZDsQ1AkA3UNxqhwLgSDJbAdYAFdYZddXBtGp a5iQ== X-Gm-Message-State: APjAAAVKreh3yPCx1YMvYikBUU1OFPsp7mc1ofDdOmIibpBIqj3D0ZZl C7ddPEar/W3TzuFGSTzy9Vnmxg== X-Received: by 2002:a17:902:322:: with SMTP id 31mr4544289pld.244.1573834045491; Fri, 15 Nov 2019 08:07:25 -0800 (PST) Received: from localhost ([2620:10d:c090:180::a9db]) by smtp.gmail.com with ESMTPSA id v10sm10527644pfg.11.2019.11.15.08.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 08:07:24 -0800 (PST) Date: Fri, 15 Nov 2019 11:07:22 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Andrew Morton , Andrey Ryabinin , Suren Baghdasaryan , Rik van Riel , Michal Hocko , Linux MM , Cgroups , LKML , Kernel Team Subject: Re: [PATCH 2/3] mm: vmscan: detect file thrashing at the reclaim root Message-ID: <20191115160722.GA309754@cmpxchg.org> References: <20191107205334.158354-1-hannes@cmpxchg.org> <20191107205334.158354-3-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 14, 2019 at 03:47:59PM -0800, Shakeel Butt wrote: > On Thu, Nov 7, 2019 at 12:53 PM Johannes Weiner wrote: > > > > We use refault information to determine whether the cache workingset > > is stable or transitioning, and dynamically adjust the inactive:active > > file LRU ratio so as to maximize protection from one-off cache during > > stable periods, and minimize IO during transitions. > > > > With cgroups and their nested LRU lists, we currently don't do this > > correctly. While recursive cgroup reclaim establishes a relative LRU > > order among the pages of all involved cgroups, refaults only affect > > the local LRU order in the cgroup in which they are occuring. As a > > result, cache transitions can take longer in a cgrouped system as the > > active pages of sibling cgroups aren't challenged when they should be. > > > > [ Right now, this is somewhat theoretical, because the siblings, under > > continued regular reclaim pressure, should eventually run out of > > inactive pages - and since inactive:active *size* balancing is also > > done on a cgroup-local level, we will challenge the active pages > > eventually in most cases. But the next patch will move that relative > > size enforcement to the reclaim root as well, and then this patch > > here will be necessary to propagate refault pressure to siblings. ] > > > > This patch moves refault detection to the root of reclaim. Instead of > > remembering the cgroup owner of an evicted page, remember the cgroup > > that caused the reclaim to happen. When refaults later occur, they'll > > correctly influence the cross-cgroup LRU order that reclaim follows. > > Can you please explain how "they'll correctly influence"? I see that > if the refaulted page was evicted due to pressure in some ancestor, > then that's ancestor's refault distance and active file size will be > used to decide to activate the refaulted page but how that is > influencing cross-cgroup LRUs? I take it the next patch answered your question: Activating a page inside a cgroup has an effect on how it's reclaimed relative to pages in sibling cgroups. So the influence part isn't new with this change - it's about recognizing that an activation has an effect on a wider scope than just the local cgroup, and considering that scope when making the decision whether to activate or not. > > @@ -302,6 +330,17 @@ void workingset_refault(struct page *page, void *shadow) > > */ > > refault_distance = (refault - eviction) & EVICTION_MASK; > > > > + /* > > + * The activation decision for this page is made at the level > > + * where the eviction occurred, as that is where the LRU order > > + * during page reclaim is being determined. > > + * > > + * However, the cgroup that will own the page is the one that > > + * is actually experiencing the refault event. > > + */ > > + memcg = get_mem_cgroup_from_mm(current->mm); > > Why not page_memcg(page)? page is locked. Nice catch! Indeed, the page is charged and locked at this point, so we don't have to do another lookup and refcounting dance here. Delta patch: --- From 8984f37f3e88b1b39c7d6470b313730093b24474 Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Fri, 15 Nov 2019 09:14:04 -0500 Subject: [PATCH] mm: vmscan: detect file thrashing at the reclaim root fix Shakeel points out that the page is locked and already charged by the time we call workingset_refault(). Instead of doing another cgroup lookup and reference from current->mm we can simply use page_memcg(). Signed-off-by: Johannes Weiner --- mm/workingset.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index f0885d9f41cd..474186b76ced 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -338,7 +338,7 @@ void workingset_refault(struct page *page, void *shadow) * However, the cgroup that will own the page is the one that * is actually experiencing the refault event. */ - memcg = get_mem_cgroup_from_mm(current->mm); + memcg = page_memcg(page); lruvec = mem_cgroup_lruvec(memcg, pgdat); inc_lruvec_state(lruvec, WORKINGSET_REFAULT); @@ -349,7 +349,7 @@ void workingset_refault(struct page *page, void *shadow) * the memory was available to the page cache. */ if (refault_distance > active_file) - goto out_memcg; + goto out; SetPageActive(page); advance_inactive_age(memcg, pgdat); @@ -360,9 +360,6 @@ void workingset_refault(struct page *page, void *shadow) SetPageWorkingset(page); inc_lruvec_state(lruvec, WORKINGSET_RESTORE); } - -out_memcg: - mem_cgroup_put(memcg); out: rcu_read_unlock(); } -- 2.24.0