Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4711948ybc; Fri, 15 Nov 2019 08:54:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxZnvs0lJKSt/7ivVEAUmPWbLkJOzaBCHApu6fkOt/ASloPd0NUsc+7kKqGHX8lvasd+79b X-Received: by 2002:a17:906:5448:: with SMTP id d8mr2093474ejp.79.1573836865478; Fri, 15 Nov 2019 08:54:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573836865; cv=none; d=google.com; s=arc-20160816; b=VJOYeG1LtQE4Fv4xYNGmfD+3C4abn0Z1S2gv176MVoTCN2V2lVdnM7oafP2IOdPFi7 s+tLVpDvW2qKXgaEQDKwORTRbOugzllq+eIBRYg4IVGDM/+kVXvCYPeFhbbdgOsam30w ISNSmL7dcumjag5uJrRGJDA2d6CrIzz89kEZgbt49Ano55F3xdQooMVIZMoj6xKILWe1 11ym83v232GMHSCSk/52vyyBYh3nwTYEzBGHfLETmyt9OnVf+eKCoyY2geHxlIRAp38s bke4NJRLqbYH1vF2p98buxlSuqiK2wVeiZG9j6xSIvoM669EI319YZLp+P5AWOlvXpFF IjVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=x9nEfpm4Qn3KUPLEqiBqX+Wd5id0rONEYyby+X9G1pY=; b=l3VNgthI7z7zhQnfcPYGqlnLVwhz0XPO+4h4hVTKc10ASqkwN7tZ/Zzxt7EGs0dpOn bfzLfb/WbFm0HM2dgt+Hxv/ADMruZGOLndtp+IJITXiYAjx0V/vr4iGps74c9QUMQE7n /NN47L8V3TwXYE6tSziI45sYk7GsYuqYOBgHTBGYoMRcdRY8r5pn4kRFqn06vPerqrSb Y4vsdmmLyvwFSkOxo8o1/zEqs4TXsxlh//QZeoHjrSP++Og1U3nqaWwGO8y2OTn6LlsB sY4RyShS6UsJqnB/R3l0fIzSgvgAQsCls9F+rHf/NxeLj2NMc4pNDfvS7kyY7Or4PsnY Ke6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dZnOiRST; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si4747493ejc.277.2019.11.15.08.54.00; Fri, 15 Nov 2019 08:54:25 -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=@google.com header.s=20161025 header.b=dZnOiRST; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727625AbfKOQwh (ORCPT + 99 others); Fri, 15 Nov 2019 11:52:37 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:36418 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727552AbfKOQwh (ORCPT ); Fri, 15 Nov 2019 11:52:37 -0500 Received: by mail-oi1-f195.google.com with SMTP id j7so9189043oib.3 for ; Fri, 15 Nov 2019 08:52:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x9nEfpm4Qn3KUPLEqiBqX+Wd5id0rONEYyby+X9G1pY=; b=dZnOiRSTLZSxks+CVIAANablbHG+rIYQIX3NV7GjDmo/GIrgxmBn8pgMKzhF99Nf8W T37eXKZegY3lpG8kmBVdH3+UpUoxgAzo5EbonaljTE64o96bjQBiNSRYAl/sthMnPi1g g9TiNZzFHEFLJ2eCr+Xa6RHsinhdBYjxEYFd0GOlHCVrOIio9KP0ZQRumTJhosrYcL4F 23cjDvd7e1akEQLnakcYzmmHy58/3Bgd9X/1wCjNiZFpv5sZUO9pXguURYrKJKJ224j8 JOH33/I93oBH8RwMtbsqT4zlw6+wp5KlhZFC4QsIPG904WjC6r+hdpC/QOhqoRIAYckF NlCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x9nEfpm4Qn3KUPLEqiBqX+Wd5id0rONEYyby+X9G1pY=; b=jLp9E1KynzZ5I7DATaHa2ECN9/r+6Becld0kaY3z5e0NBW8bptxw/nZzN4vgI1uq/C 8pPL7zFaKIdw41uoPsV+KgfdzP+OEiVDxUZ6D46YyL3ucF3/857MYb01ItWFZ0QqGsT+ 8emO4JuzDvAKYDgGKkRXwSv7K733A8lBo0EEp8F/47zoeEbzj+3jgAsZCTnhYXwpDL72 qUXqpNppv7r9gElg0NxaQsGnC4jYnXxm24QkO2eiliityEZ0wgKKxreAQfppyPT6QZDS Tk1jkUgo6vyFo4UY4LyNia13S11czFRyfcD67dzLfEzahasyxBlpi/nyCUIRD4gPV75Q /g4g== X-Gm-Message-State: APjAAAVV3TJA3rkOjQJfENai9zMBzno+qvwmX2EdLBdLLBjRsBD3ATq+ Mhhrq4olv+TIl8yWKM4htSNP998D61Vll6KCnSG6dg== X-Received: by 2002:aca:4fce:: with SMTP id d197mr8992480oib.142.1573836755958; Fri, 15 Nov 2019 08:52:35 -0800 (PST) MIME-Version: 1.0 References: <20191107205334.158354-1-hannes@cmpxchg.org> <20191107205334.158354-3-hannes@cmpxchg.org> <20191115160722.GA309754@cmpxchg.org> In-Reply-To: <20191115160722.GA309754@cmpxchg.org> From: Shakeel Butt Date: Fri, 15 Nov 2019 08:52:24 -0800 Message-ID: Subject: Re: [PATCH 2/3] mm: vmscan: detect file thrashing at the reclaim root To: Johannes Weiner Cc: Andrew Morton , Andrey Ryabinin , Suren Baghdasaryan , Rik van Riel , Michal Hocko , Linux MM , Cgroups , LKML , Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 15, 2019 at 8:07 AM Johannes Weiner wrote: > > 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. > Thanks for the clarification. > > > @@ -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 For the complete patch: Reviewed-by: Shakeel Butt > --- > 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 >