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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, 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 70A5AC433DF for ; Tue, 4 Aug 2020 06:14:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3FDFC2076E for ; Tue, 4 Aug 2020 06:14:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FDFC2076E 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 6F4A78D0123; Tue, 4 Aug 2020 02:14:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67E158D0081; Tue, 4 Aug 2020 02:14:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F6F28D0123; Tue, 4 Aug 2020 02:14:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 367728D0081 for ; Tue, 4 Aug 2020 02:14:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EC6743626 for ; Tue, 4 Aug 2020 06:14:14 +0000 (UTC) X-FDA: 77111871228.21.gun88_5f033de26fa4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id C3B8C180442D3 for ; Tue, 4 Aug 2020 06:14:14 +0000 (UTC) X-HE-Tag: gun88_5f033de26fa4 X-Filterd-Recvd-Size: 7472 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 4 Aug 2020 06:14:12 +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=e01e07488;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=22;SR=0;TI=SMTPD_---0U4j3O5d_1596521639; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U4j3O5d_1596521639) by smtp.aliyun-inc.com(127.0.0.1); Tue, 04 Aug 2020 14:14:00 +0800 Subject: Re: [PATCH RFC] mm: Add function for testing if the current lruvec lock is valid To: Alexander Duyck Cc: "Duyck, Alexander H" , Andrew Morton , Andrey Ryabinin , cgroups@vger.kernel.org, Daniel Jordan , Johannes Weiner , Hugh Dickins , Joonsoo Kim , Konstantin Khlebnikov , "Kirill A. Shutemov" , LKML , linux-mm , kbuild test robot , Mel Gorman , Wei Yang , Rong Chen , Shakeel Butt , Thomas Gleixner , Tejun Heo , Matthew Wilcox , Yang Shi References: <1595681998-19193-19-git-send-email-alex.shi@linux.alibaba.com> <159622999150.2576729.14455020813024958573.stgit@ahduyck-desk1.jf.intel.com> <0c0a415a-52a0-5c06-b4be-80cbd3cb49c2@linux.alibaba.com> From: Alex Shi Message-ID: Date: Tue, 4 Aug 2020 14:13:43 +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: C3B8C180442D3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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/8/3 =E4=B8=8A=E5=8D=882:20, Alexander Duyck =E5=86=99=E9=81= =93: > Feel free to fold it into your patches if you want. >=20 > I think Hugh was the one that had submitted a patch that addressed it, > and it looks like you folded that into your v17 set. It was probably > what he had identified which was the additional LRU checks needing to > be removed from the code. Yes, Hugh's patch was folded into patch [PATCH v17 16/21] mm/swap: serial= ize memcg changes in pagevec_lru_move_fn and your change is on patch 18. seems there are no interfere with each ot= her. Both of patches are fine. Thanks >=20 > Thanks. >=20 > - Alex >=20 > On Fri, Jul 31, 2020 at 4:55 PM Alex Shi w= rote: >> >> It looks much better than mine. and could replace 'mm/lru: introduce t= he relock_page_lruvec function' >> with your author signed. :) >> >> BTW, >> it's the rcu_read_lock cause the will-it-scale/page_fault3 regression = which you mentained in another >> letter? >> >> Thanks >> Alex >> >> =E5=9C=A8 2020/8/1 =E4=B8=8A=E5=8D=885:14, alexander.h.duyck@intel.com= =E5=86=99=E9=81=93: >>> From: Alexander Duyck >>> >>> When testing for relock we can avoid the need for RCU locking if we s= imply >>> compare the page pgdat and memcg pointers versus those that the lruve= c is >>> holding. By doing this we can avoid the extra pointer walks and acces= ses of >>> the memory cgroup. >>> >>> In addition we can avoid the checks entirely if lruvec is currently N= ULL. >>> >>> Signed-off-by: Alexander Duyck >>> --- >>> include/linux/memcontrol.h | 52 +++++++++++++++++++++++++++-------= ---------- >>> 1 file changed, 32 insertions(+), 20 deletions(-) >>> >>> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h >>> index 6e670f991b42..7a02f00bf3de 100644 >>> --- a/include/linux/memcontrol.h >>> +++ b/include/linux/memcontrol.h >>> @@ -405,6 +405,22 @@ static inline struct lruvec *mem_cgroup_lruvec(s= truct mem_cgroup *memcg, >>> >>> struct lruvec *mem_cgroup_page_lruvec(struct page *, struct pglist_d= ata *); >>> >>> +static inline bool lruvec_holds_page_lru_lock(struct page *page, >>> + struct lruvec *lruvec) >>> +{ >>> + pg_data_t *pgdat =3D page_pgdat(page); >>> + const struct mem_cgroup *memcg; >>> + struct mem_cgroup_per_node *mz; >>> + >>> + if (mem_cgroup_disabled()) >>> + return lruvec =3D=3D &pgdat->__lruvec; >>> + >>> + mz =3D container_of(lruvec, struct mem_cgroup_per_node, lruvec)= ; >>> + memcg =3D page->mem_cgroup ? : root_mem_cgroup; >>> + >>> + return lruvec->pgdat =3D=3D pgdat && mz->memcg =3D=3D memcg; >>> +} >>> + >>> struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); >>> >>> struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm); >>> @@ -880,6 +896,14 @@ static inline struct lruvec *mem_cgroup_page_lru= vec(struct page *page, >>> return &pgdat->__lruvec; >>> } >>> >>> +static inline bool lruvec_holds_page_lru_lock(struct page *page, >>> + struct lruvec *lruvec) >>> +{ >>> + pg_data_t *pgdat =3D page_pgdat(page); >>> + >>> + return lruvec =3D=3D &pgdat->__lruvec; >>> +} >>> + >>> static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup= *memcg) >>> { >>> return NULL; >>> @@ -1317,18 +1341,12 @@ static inline void unlock_page_lruvec_irqrest= ore(struct lruvec *lruvec, >>> static inline struct lruvec *relock_page_lruvec_irq(struct page *pag= e, >>> struct lruvec *locked_lruvec) >>> { >>> - struct pglist_data *pgdat =3D page_pgdat(page); >>> - bool locked; >>> + if (locked_lruvec) { >>> + if (lruvec_holds_page_lru_lock(page, locked_lruvec)) >>> + return locked_lruvec; >>> >>> - rcu_read_lock(); >>> - locked =3D mem_cgroup_page_lruvec(page, pgdat) =3D=3D locked_lr= uvec; >>> - rcu_read_unlock(); >>> - >>> - if (locked) >>> - return locked_lruvec; >>> - >>> - if (locked_lruvec) >>> unlock_page_lruvec_irq(locked_lruvec); >>> + } >>> >>> return lock_page_lruvec_irq(page); >>> } >>> @@ -1337,18 +1355,12 @@ static inline struct lruvec *relock_page_lruv= ec_irq(struct page *page, >>> static inline struct lruvec *relock_page_lruvec_irqsave(struct page = *page, >>> struct lruvec *locked_lruvec, unsigned long *flags) >>> { >>> - struct pglist_data *pgdat =3D page_pgdat(page); >>> - bool locked; >>> - >>> - rcu_read_lock(); >>> - locked =3D mem_cgroup_page_lruvec(page, pgdat) =3D=3D locked_lr= uvec; >>> - rcu_read_unlock(); >>> - >>> - if (locked) >>> - return locked_lruvec; >>> + if (locked_lruvec) { >>> + if (lruvec_holds_page_lru_lock(page, locked_lruvec)) >>> + return locked_lruvec; >>> >>> - if (locked_lruvec) >>> unlock_page_lruvec_irqrestore(locked_lruvec, *flags); >>> + } >>> >>> return lock_page_lruvec_irqsave(page, flags); >>> } >>> >>