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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=no 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 828FFC33CAF for ; Wed, 22 Jan 2020 12:01:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4330C24683 for ; Wed, 22 Jan 2020 12:01:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4330C24683 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 D3D326B0003; Wed, 22 Jan 2020 07:01:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CED806B0005; Wed, 22 Jan 2020 07:01:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDB946B0007; Wed, 22 Jan 2020 07:01:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id A95CF6B0003 for ; Wed, 22 Jan 2020 07:01:39 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 416CB181AEF10 for ; Wed, 22 Jan 2020 12:01:39 +0000 (UTC) X-FDA: 76405130718.05.beast73_48702970c883d X-HE-Tag: beast73_48702970c883d X-Filterd-Recvd-Size: 6567 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Jan 2020 12:01:37 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=38;SR=0;TI=SMTPD_---0ToLTDEr_1579694489; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0ToLTDEr_1579694489) by smtp.aliyun-inc.com(127.0.0.1); Wed, 22 Jan 2020 20:01:30 +0800 Subject: Re: [PATCH v8 03/10] mm/lru: replace pgdat lru_lock with lruvec lock To: Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, shakeelb@google.com, Michal Hocko , Vladimir Davydov , Roman Gushchin , Chris Down , Thomas Gleixner , Vlastimil Babka , Qian Cai , Andrey Ryabinin , "Kirill A. Shutemov" , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Andrea Arcangeli , David Rientjes , "Aneesh Kumar K.V" , swkhack , "Potyra, Stefan" , Mike Rapoport , Stephen Rothwell , Colin Ian King , Jason Gunthorpe , Mauro Carvalho Chehab , Peng Fan , Nikolay Borisov , Ira Weiny , Kirill Tkhai , Yafang Shao References: <1579143909-156105-1-git-send-email-alex.shi@linux.alibaba.com> <1579143909-156105-4-git-send-email-alex.shi@linux.alibaba.com> <20200116215222.GA64230@cmpxchg.org> <9ee80b68-a78f-714a-c727-1f6d2b4f87ea@linux.alibaba.com> <20200121160005.GA69293@cmpxchg.org> From: Alex Shi Message-ID: <0bd0a561-93cc-11b6-1eae-24b450b0f033@linux.alibaba.com> Date: Wed, 22 Jan 2020 20:01:29 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200121160005.GA69293@cmpxchg.org> 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: =E5=9C=A8 2020/1/22 =E4=B8=8A=E5=8D=8812:00, Johannes Weiner =E5=86=99=E9= =81=93: > On Mon, Jan 20, 2020 at 08:58:09PM +0800, Alex Shi wrote: >> >> >> =E5=9C=A8 2020/1/17 =E4=B8=8A=E5=8D=885:52, Johannes Weiner =E5=86=99=E9= =81=93: >> >>> You simply cannot serialize on page->mem_cgroup->lruvec when >>> page->mem_cgroup isn't stable. You need to serialize on the page >>> itself, one way or another, to make this work. >>> >>> >>> So here is a crazy idea that may be worth exploring: >>> >>> Right now, pgdat->lru_lock protects both PageLRU *and* the lruvec's >>> linked list. >>> >>> Can we make PageLRU atomic and use it to stabilize the lru_lock >>> instead, and then use the lru_lock only serialize list operations? >>> >> >> Hi Johannes, >> >> I am trying to figure out the solution of atomic PageLRU, but is=20 >> blocked by the following sitations, when PageLRU and lru list was prot= ected >> together under lru_lock, the PageLRU could be a indicator if page on l= ru list >> But now seems it can't be the indicator anymore. >> Could you give more clues of stabilization usage of PageLRU? >=20 > There are two types of PageLRU checks: optimistic and deterministic. >=20 > The check in activate_page() for example is optimistic and the result > unstable, but that's okay, because if we miss a page here and there > it's not the end of the world. >=20 > But the check in __activate_page() is deterministic, because we need > to be sure before del_page_from_lru_list(). Currently it's made > deterministic by testing under the lock: whoever acquires the lock > first gets to touch the LRU state. The same can be done with an atomic > TestClearPagLRU: whoever clears the flag first gets to touch the LRU > state (the lock is then only acquired to not corrupt the linked list, > in case somebody adds or removes a different page at the same time). Hi Johannes, Thanks a lot for detailed explanations! I just gonna to take 2 weeks holi= day from tomorrow as Chinese new year season with families. I am very sorry f= or=20 can not hang on this for a while. >=20 > I.e. in my proposal, if you want to get a stable read of PageLRU, you > have to clear it atomically. But AFAICS, everybody who currently does > need a stable read either already clears it or can easily be converted > to clear it and then set it again (like __activate_page and friends). >=20 >> __page_cache_release/release_pages/compaction __pagevec_lru= _add >> if (TestClearPageLRU(page)) if (!PageLRU(= )) >> lruvec= _lock(); >> list_a= dd(); >> lruvec_unlock(); >> SetPageLRU() //position 1 >> lock_page_lruvec_irqsave(page, &flags); >> del_page_from_lru_list(page, lruvec, ..); >> unlock_page_lruvec_irqrestore(lruvec, flags); >> SetPag= eLRU() //position 2 >=20 > Hm, that's not how __pagevec_lru_add() looks. In fact, > __pagevec_lru_add_fn() has a BUG_ON(PageLRU). >=20 > That's because only one thread can own the isolation state at a time. >=20 > If PageLRU is set, only one thread can claim it. Right now, whoever > takes the lock first and clears it wins. When we replace it with > TestClearPageLRU, it's the same thing: only one thread can win. >=20 > And you cannot set PageLRU, unless you own it. Either you isolated the > page using TestClearPageLRU, or you allocated a new page. Yes I understand isolatation would exclusive by PageLRU, but forgive my stupid, I didn't figure out how a new page lruvec adding could be blocked= . Anyway, I will try my best to catch up after holiday. Many thanks for nice cocaching! Alex