From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA936C4332E for ; Thu, 19 Mar 2020 08:31:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3DA5120773 for ; Thu, 19 Mar 2020 08:31:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O/OjG0aZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DA5120773 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A5ACC6B0003; Thu, 19 Mar 2020 04:31:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0C376B0005; Thu, 19 Mar 2020 04:31:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9208A6B0006; Thu, 19 Mar 2020 04:31:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 7ABA56B0003 for ; Thu, 19 Mar 2020 04:31:56 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1ED52824556B for ; Thu, 19 Mar 2020 08:31:56 +0000 (UTC) X-FDA: 76611443832.15.trail50_682a5928a0f1e X-HE-Tag: trail50_682a5928a0f1e X-Filterd-Recvd-Size: 6508 Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Mar 2020 08:31:55 +0000 (UTC) Received: by mail-qv1-f67.google.com with SMTP id m2so536170qvu.13 for ; Thu, 19 Mar 2020 01:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=0hH/8ZvXQv+Mfjqbb5U9DwxAPHLEKJbYdC6hBHVijbk=; b=O/OjG0aZGy9yhc1+2BMb27k6RQk2H0/k26Ns7y1G3IFc6qr4OIEx5piUhcRJD2rrPj JLSsocLIQqmFxF54te+uwug86NBcBvub9X2UfmlhWFqDQVw95MuNkzvPIBu4a2aCX/c4 dlN422LAV9iN812kP8M+XPow4V6+xhnacsrgYj/ujY1vu/lOVmWNVTDWBcN4HeB0k77k mq4wajr830ub2bBwNBgHgl87GdRjap86D0xoYm3HNXGavHg1fXOR4EwiKMU2PL0CCJ8i N518pbqhpIXrRaVAYmz+pJLJE4jrq77v++MEc2DZxRQciS0FSYV4gHj7qojBGVOYDOAV L9Lw== 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:content-transfer-encoding; bh=0hH/8ZvXQv+Mfjqbb5U9DwxAPHLEKJbYdC6hBHVijbk=; b=ZKmzjmVZHMrkm3sTt8JHwhvzwEPJKypFQ/o1YfB6VDRb+LejhUX6LLp1tB+hkxfrYb yi4Nozk0eNdWhbwf9VHtC13gO42hsnJOTNTn0cf0PuPuLIGLHRjfDybFCA7DKMtAQ112 FchyGiMIJhDLVDBJnkVywiCU2yx7j9D48IMLxNzv0Lzr6GQstO5xdNWJ6S8FJ5m3iy8D Ni2pzT0A8wE/b7um6sTmrRLnp4hPai824PjzOK51bjRzAxprvCepDaD/5xH2VSF4M2BC 9HrM31G4dhUyEcIVXm0wj8P2NI8ISVWxGiRetbVlciYnZC7Fm+bI/fFtqXRjQmlHrhpC dffA== X-Gm-Message-State: ANhLgQ1aa6r+ExgSYYYEj62iSK3jAMySpTsgjncWGOzs60w2lDaKpi+R xAa//xsKKsMRjiQLZ72IP7HU9BU/tYrBxn1bb5A= X-Google-Smtp-Source: ADFU+vvuRpn8VDUE6NrbjQLgwjoXTyQY98piTROb9Kh6G6elugJxnjNozpur/smZvr97PrgmTTVHwhR39cngLVVQSOM= X-Received: by 2002:a05:6214:11f4:: with SMTP id e20mr1862550qvu.66.1584606715035; Thu, 19 Mar 2020 01:31:55 -0700 (PDT) MIME-Version: 1.0 References: <1584423717-3440-1-git-send-email-iamjoonsoo.kim@lge.com> <1584423717-3440-7-git-send-email-iamjoonsoo.kim@lge.com> <20200318195911.GF154135@cmpxchg.org> In-Reply-To: <20200318195911.GF154135@cmpxchg.org> From: Joonsoo Kim Date: Thu, 19 Mar 2020 17:31:44 +0900 Message-ID: Subject: Re: [PATCH v3 6/9] mm/workingset: handle the page without memcg To: Johannes Weiner Cc: Andrew Morton , Linux Memory Management List , LKML , Michal Hocko , Hugh Dickins , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Joonsoo Kim Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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: 2020=EB=85=84 3=EC=9B=94 19=EC=9D=BC (=EB=AA=A9) =EC=98=A4=EC=A0=84 4:59, J= ohannes Weiner =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > On Tue, Mar 17, 2020 at 02:41:54PM +0900, js1304@gmail.com wrote: > > From: Joonsoo Kim > > > > When implementing workingset detection for anonymous page, I found > > some swapcache pages with NULL memcg. From the code reading, I found > > two reasons. > > > > One is the case that swap-in readahead happens. The other is the > > corner case related to the shmem cache. These two problems should be > > fixed, but, it's not straight-forward to fix. For example, when swap-of= f, > > all swapped-out pages are read into swapcache. In this case, who's the > > owner of the swapcache page? > > > > Since this problem doesn't look trivial, I decide to leave the issue an= d > > handles this corner case on the place where the error occurs. > > > > Signed-off-by: Joonsoo Kim > > It wouldn't be hard to find out who owns this page. The code in > mem_cgroup_try_charge() is only a few lines: lookup_swap_cgroup_id() uses additional memory and is only usable if CONFIG_MEMCG_SWAP is on. > swp_entry_t ent =3D { .val =3D page_private(page)= , }; > unsigned short id =3D lookup_swap_cgroup_id(ent); > > rcu_read_lock(); > memcg =3D mem_cgroup_from_id(id); > if (memcg && !css_tryget_online(&memcg->css)) > memcg =3D NULL; > rcu_read_unlock(); > > THAT BEING SAID, I don't think we actually *want* to know the original > cgroup for readahead pages. Because before they are accessed and > charged to the original owner, the pages are sitting on the root > cgroup LRU list and follow the root group's aging speed and LRU order. Okay. Sound reasonable. > Eviction and refault tracking is about the LRU that hosts the pages. > > So IMO your patch is much less of a hack than you might think. Good! > > diff --git a/mm/workingset.c b/mm/workingset.c > > index a9f474a..8d2e83a 100644 > > --- a/mm/workingset.c > > +++ b/mm/workingset.c > > @@ -257,6 +257,10 @@ void *workingset_eviction(struct page *page, struc= t mem_cgroup *target_memcg) > > VM_BUG_ON_PAGE(page_count(page), page); > > VM_BUG_ON_PAGE(!PageLocked(page), page); > > > > + /* page_memcg() can be NULL if swap-in readahead happens */ > > + if (!page_memcg(page)) > > + return NULL; > > + > > advance_inactive_age(page_memcg(page), pgdat, is_file); > > > > lruvec =3D mem_cgroup_lruvec(target_memcg, pgdat); > > This means a readahead page that hasn't been accessed will actively > not be tracked as an eviction and later as a refault. > > I think that's the right thing to do, but I would expand the comment: Okay. I will add the following comment. Thanks. > /* > * A page can be without a cgroup here when it was brought in by swap > * readahead and nobody has touched it since. > * > * The idea behind the workingset code is to tell on page fault time > * whether pages have been previously used or not. Since this page > * hasn't been used, don't store a shadow entry for it; when it later > * faults back in, we treat it as the new page that it is. > */