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.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,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 873F4C433E0 for ; Wed, 29 Jul 2020 02:28:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51CA22070B for ; Wed, 29 Jul 2020 02:28:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51CA22070B 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 B660B6B0062; Tue, 28 Jul 2020 22:27:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B15C46B0068; Tue, 28 Jul 2020 22:27:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E20C8D000B; Tue, 28 Jul 2020 22:27:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 83D796B0062 for ; Tue, 28 Jul 2020 22:27:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 03577180AD806 for ; Wed, 29 Jul 2020 02:27:59 +0000 (UTC) X-FDA: 77089528278.12.rate51_5d13b9826f6e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id CAD6D18036FF9 for ; Wed, 29 Jul 2020 02:27:58 +0000 (UTC) X-HE-Tag: rate51_5d13b9826f6e X-Filterd-Recvd-Size: 7707 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Jul 2020 02:27:55 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0U46lJml_1595989668; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U46lJml_1595989668) by smtp.aliyun-inc.com(127.0.0.1); Wed, 29 Jul 2020 10:27:49 +0800 Subject: Re: [PATCH v17 17/21] mm/lru: replace pgdat lru_lock with lruvec lock To: Alexander Duyck Cc: Andrew Morton , Mel Gorman , Tejun Heo , Hugh Dickins , Konstantin Khlebnikov , Daniel Jordan , Yang Shi , Matthew Wilcox , Johannes Weiner , kbuild test robot , linux-mm , LKML , cgroups@vger.kernel.org, Shakeel Butt , Joonsoo Kim , Wei Yang , "Kirill A. Shutemov" , Rong Chen , Michal Hocko , Vladimir Davydov References: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> <1595681998-19193-18-git-send-email-alex.shi@linux.alibaba.com> <09aeced7-cc36-0c9a-d40b-451db9dc54cc@linux.alibaba.com> From: Alex Shi Message-ID: <0590862b-0705-fb9b-be1b-ed0745ca1b76@linux.alibaba.com> Date: Wed, 29 Jul 2020 10:27:34 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 X-Rspamd-Queue-Id: CAD6D18036FF9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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/7/29 =E4=B8=8A=E5=8D=889:27, Alexander Duyck =E5=86=99=E9=81= =93: > On Tue, Jul 28, 2020 at 6:00 PM Alex Shi w= rote: >> >> >> >> =E5=9C=A8 2020/7/28 =E4=B8=8B=E5=8D=8810:54, Alexander Duyck =E5=86=99= =E9=81=93: >>> On Tue, Jul 28, 2020 at 4:20 AM Alex Shi = wrote: >>>> >>>> >>>> >>>> =E5=9C=A8 2020/7/28 =E4=B8=8A=E5=8D=887:34, Alexander Duyck =E5=86=99= =E9=81=93: >>>>>> @@ -1876,6 +1876,12 @@ static unsigned noinline_for_stack move_pag= es_to_lru(struct lruvec *lruvec, >>>>>> * list_add= (&page->lru,) >>>>>> * list_add(&page->lru,) //corrupt >>>>>> */ >>>>>> + new_lruvec =3D mem_cgroup_page_lruvec(page, page_p= gdat(page)); >>>>>> + if (new_lruvec !=3D lruvec) { >>>>>> + if (lruvec) >>>>>> + spin_unlock_irq(&lruvec->lru_lock)= ; >>>>>> + lruvec =3D lock_page_lruvec_irq(page); >>>>>> + } >>>>>> SetPageLRU(page); >>>>>> >>>>>> if (unlikely(put_page_testzero(page))) { >>>>> I was going through the code of the entire patch set and I noticed >>>>> these changes in move_pages_to_lru. What is the reason for adding t= he >>>>> new_lruvec logic? My understanding is that we are moving the pages = to >>>>> the lruvec provided are we not?If so why do we need to add code to = get >>>>> a new lruvec? The code itself seems to stand out from the rest of t= he >>>>> patch as it is introducing new code instead of replacing existing >>>>> locking code, and it doesn't match up with the description of what >>>>> this function is supposed to do since it changes the lruvec. >>>> >>>> this new_lruvec is the replacement of removed line, as following cod= e: >>>>>> - lruvec =3D mem_cgroup_page_lruvec(page, pgdat); >>>> This recheck is for the page move the root memcg, otherwise it cause= the bug: >>> >>> Okay, now I see where the issue is. You moved this code so now it has >>> a different effect than it did before. You are relocking things befor= e >>> you needed to. Don't forget that when you came into this function you >>> already had the lock. In addition the patch is broken as it currently >>> stands as you aren't using similar logic in the code just above this >>> addition if you encounter an evictable page. As a result this is >>> really difficult to review as there are subtle bugs here. >> >> Why you think its a bug? the relock only happens if locked lruvec is d= ifferent. >> and unlock the old one. >=20 > The section I am talking about with the bug is this section here: > while (!list_empty(list)) { > + struct lruvec *new_lruvec =3D NULL; > + > page =3D lru_to_page(list); > VM_BUG_ON_PAGE(PageLRU(page), page); > list_del(&page->lru); > if (unlikely(!page_evictable(page))) { > - spin_unlock_irq(&pgdat->lru_lock); > + spin_unlock_irq(&lruvec->lru_lock); > putback_lru_page(page); > - spin_lock_irq(&pgdat->lru_lock); > + spin_lock_irq(&lruvec->lru_lock); It would be still fine. The lruvec->lru_lock will be checked again before we take and use it.=20 And this lock will optimized in patch 19th which did by Hugh Dickins. > continue; > } >=20 > Basically it probably is not advisable to be retaking the > lruvec->lru_lock directly as the lruvec may have changed so it > wouldn't be correct for the next page. It would make more sense to be > using your API and calling unlock_page_lruvec_irq and > lock_page_lruvec_irq instead of using the lock directly. >=20 >>> >>> I suppose the correct fix is to get rid of this line, but it should >>> be placed everywhere the original function was calling >>> spin_lock_irq(). >>> >>> In addition I would consider changing the arguments/documentation for >>> move_pages_to_lru. You aren't moving the pages to lruvec, so there is >>> probably no need to pass that as an argument. Instead I would pass >>> pgdat since that isn't going to be moving and is the only thing you >>> actually derive based on the original lruvec. >> >> yes, The comments should be changed with the line was introduced from = long ago. :) >> Anyway, I am wondering if it worth a v18 version resend? >=20 > So I have been looking over the function itself and I wonder if it > isn't worth looking at rewriting this to optimize the locking behavior > to minimize the number of times we have to take the LRU lock. I have > some code I am working on that I plan to submit as an RFC in the next > day or so after I can get it smoke tested. The basic idea would be to > defer returning the evictiable pages or freeing the compound pages > until after we have processed the pages that can be moved while still > holding the lock. I would think it should reduce the lock contention > significantly while improving the throughput. >=20 I had tried once, but the freeing page cross onto release_pages which har= d to deal with. I am very glad to wait your patch, and hope it could be resovled. :) Thanks Alex