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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 D35CBC55178 for ; Thu, 5 Nov 2020 15:38:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 05CE92078E for ; Thu, 5 Nov 2020 15:38:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="e8y3o+IK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05CE92078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1490E6B012A; Thu, 5 Nov 2020 10:38:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FE0E6B012C; Thu, 5 Nov 2020 10:38:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2B0F6B012D; Thu, 5 Nov 2020 10:38:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id B8C296B012A for ; Thu, 5 Nov 2020 10:38:40 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D22EE362B for ; Thu, 5 Nov 2020 15:38:37 +0000 (UTC) X-FDA: 77450771874.19.town48_4613958272cb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 88C001AD1B0 for ; Thu, 5 Nov 2020 15:38:37 +0000 (UTC) X-HE-Tag: town48_4613958272cb X-Filterd-Recvd-Size: 6532 Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.66]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 15:38:36 +0000 (UTC) Received: by mail-qv1-f66.google.com with SMTP id w5so857686qvn.12 for ; Thu, 05 Nov 2020 07:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=gJn4RrhgML8VnnTGge57cXSGujNjtgZ05i1FRRImWao=; b=e8y3o+IKqhhxV7akZZldI6gyK1nc1DOad8e1uBzEMak6DsXvwHPrRI8r3GWOaI+yoP dk31zHh4gAAoOXdGxC4LA0dB3GCRCzaDpN6BHMXyTXBtwLOKKtG4zwcHcGfhosDznZ8x Fgj95HDnzganMbEoxUo6h1vOvPr34F6a4g/+u+YmQCKqTo2FydNqWiEDSCFp040h47sH V0HEAytJrVwkVWml2z5K3OdZruFcjWXcUgkysE5tgSAMOqyzZfmP0V5U+n8TVKw0FdLu dbeRygU1pwJ+U3OATtx7ElipTO3sccVxMtzBEkVZLy5NzKQvhV1fofu1iWN86fw7fH4v 7vfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=gJn4RrhgML8VnnTGge57cXSGujNjtgZ05i1FRRImWao=; b=URp7csjwpJN9ZlHLjf+PztFiUEdQuF79ODiv0o4ygWChzFyglXT2ye2I/Oh9AAKCwh MJknh+QSqgKFIKtMkaAK/j8eVHJq5Q2qMMsJjhBim+Qi9f9Q3tE6us+A93pTg+mlB9Xj xonDcNbgZWzPqVNf2olJMD/EaJDL8zQqCiMoXuN4qWwpkeUKk66a1v/m5E1lXEAzx7aW /lZYlI6BRhBOIgqS6LsuMIrx0EEO3idyt703kuSBTY0Hz/9zMfcV0qOLkdt7xqipJoIq 3UVRyN0SJJH7D3CUXAiNYzm5xL6g00Xyfx+98U3HdzT2NPx0zhfiLoIUhBp9lqugz+Gm /G0A== X-Gm-Message-State: AOAM531VxihO6KGGorXy6byhUu9zhFPy+V690+sGIB/jC2+7X6+uRerK O7TS6eefDDiJVd/ZYoNPrDwTqQ== X-Google-Smtp-Source: ABdhPJznRNE8E9a5EXrGvaKmLqQRIxP/m+auIfdNbAsuBf75INXE3XnVMIGAaRoz7CO/MkSMjRnUHQ== X-Received: by 2002:a05:6214:401:: with SMTP id z1mr2772209qvx.53.1604590715972; Thu, 05 Nov 2020 07:38:35 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:fc05]) by smtp.gmail.com with ESMTPSA id x75sm1244661qka.59.2020.11.05.07.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 07:38:35 -0800 (PST) Date: Thu, 5 Nov 2020 10:36:49 -0500 From: Johannes Weiner To: Alex Shi Cc: Matthew Wilcox , akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com, Vlastimil Babka , Minchan Kim Subject: Re: [PATCH v20 08/20] mm: page_idle_get_page() does not need lru_lock Message-ID: <20201105153649.GC744831@cmpxchg.org> References: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> <1603968305-8026-9-git-send-email-alex.shi@linux.alibaba.com> <20201102144110.GB724984@cmpxchg.org> <20201102144927.GN27442@casper.infradead.org> <20201102202003.GA740958@cmpxchg.org> <20201104174603.GB744831@cmpxchg.org> <6eea82d8-e406-06ee-2333-eb6e2f1944e5@linux.alibaba.com> <20201105045702.GI17076@casper.infradead.org> <1e8f0162-cf2e-03eb-e7e0-ccc9f6a3eaf2@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1e8f0162-cf2e-03eb-e7e0-ccc9f6a3eaf2@linux.alibaba.com> 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: On Thu, Nov 05, 2020 at 01:03:18PM +0800, Alex Shi wrote: >=20 >=20 > =E5=9C=A8 2020/11/5 =E4=B8=8B=E5=8D=8812:57, Matthew Wilcox =E5=86=99=E9= =81=93: > > On Thu, Nov 05, 2020 at 12:52:05PM +0800, Alex Shi wrote: > >> @@ -1054,8 +1054,27 @@ static void __page_set_anon_rmap(struct page = *page, > >> if (!exclusive) > >> anon_vma =3D anon_vma->root; > >> =20 > >> + /* > >> + * w/o the WRITE_ONCE here the following scenario may happens due = to > >> + * store reordering. > >> + * > >> + * CPU 0 CPU 1 > >> + * > >> + * do_anonymous_page page_idle_clear_pte_refs > >> + * __page_set_anon_rmap > >> + * page->mapping =3D anon_vma + PAGE_MAPPING_ANON > >> + * lru_cache_add_inactive_or_unevictable() > >> + * SetPageLRU(page) > >> + * rmap_walk > >> + * if PageAnon(page= ) > >> + * > >> + * The 'SetPageLRU' may reordered before page->mapping setting, a= nd > >> + * page->mapping may set with anon_vma, w/o anon bit, then rmap_w= alk > >> + * may goes to rmap_walk_file() for a anon page. > >> + */ > >> + > >> anon_vma =3D (void *) anon_vma + PAGE_MAPPING_ANON; > >> - page->mapping =3D (struct address_space *) anon_vma; > >> + WRITE_ONCE(page->mapping, (struct address_space *) anon_vma); > >> page->index =3D linear_page_index(vma, address); > >> } > >=20 > > I don't like these verbose comments with detailed descriptions in > > the source code. They're fine in changelogs, but they clutter the > > code, and they get outdated really quickly. My preference is for > > something more brief: > >=20 > > /* > > * Prevent page->mapping from pointing to an anon_vma without > > * the PAGE_MAPPING_ANON bit set. This could happen if the > > * compiler stores anon_vma and then adds PAGE_MAPPING_ANON to it. > > */ > >=20 Yeah, I don't think this scenario warrants the full race diagram in the code itself. But the code is highly specific - synchronizing one struct page member for one particular use case. Let's keep at least a reference to what we are synchronizing against. There is a non-zero chance that if the comment goes out of date, so does the code. How about this? /* * page_idle does a lockless/optimistic rmap scan on page->mapping. * Make sure the compiler doesn't split the stores of anon_vma and * the PAGE_MAPPING_ANON type identifier, otherwise the rmap code * could mistake the mapping for a struct address_space and crash. */