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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 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 8A203C2BA19 for ; Tue, 21 Apr 2020 09:23:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 545E020857 for ; Tue, 21 Apr 2020 09:23:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 545E020857 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 039AB8E0005; Tue, 21 Apr 2020 05:23:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2C138E0003; Tue, 21 Apr 2020 05:23:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E43488E0005; Tue, 21 Apr 2020 05:23:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id CAD048E0003 for ; Tue, 21 Apr 2020 05:23:41 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9075E180ACF62 for ; Tue, 21 Apr 2020 09:23:41 +0000 (UTC) X-FDA: 76731324642.30.oil84_30a73689b429 X-HE-Tag: oil84_30a73689b429 X-Filterd-Recvd-Size: 4067 Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com [47.88.44.36]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 21 Apr 2020 09:23:40 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TwDn7z8_1587460926; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TwDn7z8_1587460926) by smtp.aliyun-inc.com(127.0.0.1); Tue, 21 Apr 2020 17:22:07 +0800 Subject: Re: [PATCH 18/18] mm: memcontrol: update page->mem_cgroup stability rules To: Johannes Weiner , Joonsoo Kim Cc: Shakeel Butt , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-19-hannes@cmpxchg.org> From: Alex Shi Message-ID: <1f905391-5676-2db6-efb9-74ade130740e@linux.alibaba.com> Date: Tue, 21 Apr 2020 17:20:59 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200420221126.341272-19-hannes@cmpxchg.org> Content-Type: text/plain; charset=gbk 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: =D4=DA 2020/4/21 =C9=CF=CE=E76:11, Johannes Weiner =D0=B4=B5=C0: > The previous patches have simplified the access rules around > page->mem_cgroup somewhat: >=20 > 1. We never change page->mem_cgroup while the page is isolated by > somebody else. This was by far the biggest exception to our rules > and it didn't stop at lock_page() or lock_page_memcg(). >=20 > 2. We charge pages before they get put into page tables now, so the > somewhat fishy rule about "can be in page table as long as it's > still locked" is now gone and boiled down to having an exclusive > reference to the page. >=20 > Document the new rules. Any of the following will stabilize the > page->mem_cgroup association: >=20 > - the page lock > - LRU isolation > - lock_page_memcg() > - exclusive access to the page >=20 > Signed-off-by: Johannes Weiner Reviewed-by: Alex Shi > --- > mm/memcontrol.c | 21 +++++++-------------- > 1 file changed, 7 insertions(+), 14 deletions(-) >=20 > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index a8cce52b6b4d..7b63260c9b57 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1201,9 +1201,8 @@ int mem_cgroup_scan_tasks(struct mem_cgroup *memc= g, > * @page: the page > * @pgdat: pgdat of the page > * > - * This function is only safe when following the LRU page isolation > - * and putback protocol: the LRU lock must be held, and the page must > - * either be PageLRU() or the caller must have isolated/allocated it. > + * This function relies on page->mem_cgroup being stable - see the > + * access rules in commit_charge(). > */ > struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist= _data *pgdat) > { > @@ -2605,18 +2604,12 @@ static void commit_charge(struct page *page, st= ruct mem_cgroup *memcg) > { > VM_BUG_ON_PAGE(page->mem_cgroup, page); > /* > - * Nobody should be changing or seriously looking at > - * page->mem_cgroup at this point: > - * > - * - the page is uncharged > - * > - * - the page is off-LRU > - * > - * - an anonymous fault has exclusive page access, except for > - * a locked page table > + * Any of the following ensures page->mem_cgroup stability: > * > - * - a page cache insertion, a swapin fault, or a migration > - * have the page locked > + * - the page lock > + * - LRU isolation > + * - lock_page_memcg() > + * - exclusive reference > */ > page->mem_cgroup =3D memcg; > } >=20