Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp250229pxb; Wed, 4 Nov 2020 21:43:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4dh4NscZmqVmVV+/G3mrMixSlmQgBqlPSjrEJREx6ZRetgCesaUfzdg3rII667oTzc1JE X-Received: by 2002:a05:6402:1ca6:: with SMTP id cz6mr867980edb.129.1604554995904; Wed, 04 Nov 2020 21:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604554995; cv=none; d=google.com; s=arc-20160816; b=oUd0Mt9Iip7i+KQ11PoR0YSgGJRd3lMNyrwic7LccCnrSh89tSR2XrgEVMo4O15wYS XRfx/oFs0B9IEXrx/x0CmBZWBQFWMVFYR05p7Onq9BKrr+OUFcAu0U++NCSzhol/z6W6 ToFkQw3hlXTx/DK54mVqf9fINvp/4eQn2OKRV9J0mb9BwRR6VdW8aaiTgzczNoWBwI0A y8nBJ8r6SCqLVpI6FNrUBE+WfZieb3R3e1gpOSHXejLWpix/TV/OFbiRjw/A0EXbxnAI LCveb1MYkcAv5c3BXohJHZ5trLyDu3O+7A0pWoX72bBOy07vTo+q12iFPHwEgAI+7PPP kbFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=56c9MV1aCT4xOSMBx0nzDfblxOWC6xg3JuAgCQPVoo0=; b=w3BOO54Uedrc8dmq8Mg0by+Qx5EaKXzXh5/EcSmeNF79X5d4Uxs1ovzcxE18vWcV9z VCXoOMyV01WJWGb4QEvPiOo25hMevlNINMHqQH0fJyjLjC87w9eodkx7XvU0Q7hqMTA7 Fhz8CyPaH4B62EVFsVWiYcRZF6bi60BcnSXWjbCIb51D2L9oWi4qBm0DfT0sFmOhk0KE RU3O0/pCLpqeMUzvhwQUz5xqHca3pMDGZ+EXXETX+u3LBok3MxwwloQAzLTww4XwH0zy vd4ULz/nvrhmNQChTsSo2/2XcPZEynpqSFtl8l0LO0wdvjxwj4Eo9G4KZ39EGtxohx5u dT+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=MtP3X+6N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p9si398769eja.144.2020.11.04.21.42.53; Wed, 04 Nov 2020 21:43:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=MtP3X+6N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbgKEE5Z (ORCPT + 99 others); Wed, 4 Nov 2020 23:57:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727046AbgKEE5Y (ORCPT ); Wed, 4 Nov 2020 23:57:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B08EFC0613CF; Wed, 4 Nov 2020 20:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=56c9MV1aCT4xOSMBx0nzDfblxOWC6xg3JuAgCQPVoo0=; b=MtP3X+6N16mNIoQ6VM+zP+mX61 xZhlLyrMFKBSQTOZqsKgI2SCh4tyCwBipKSKtLPZPw8rs9YxwuiECV/9yS6LDhjuFH/I6yx/YIqh2 AtQ2CarlmnIs0bwEq890VCWLJakxZsRt/8s3NcD0RPGmUylZaF1L6bKy3RznRg6rB5ufu6PPe5U5d Ncq+WO3G3/Sbvn4apMoUtQ2IpG80ZqwDA1iTW+8eJ196udcXf4cOm07Ys1UIw3LqCA/zVJwwRmuw2 i5B/BI2/zdUb/O22aIeIvtNS/a1NmY4r81q25n70CdNrUNdBVoXybkARM3DiDjAYXFkPUUXTds/+G eRC2VJXg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXKY-0003Di-FI; Thu, 05 Nov 2020 04:57:02 +0000 Date: Thu, 5 Nov 2020 04:57:02 +0000 From: Matthew Wilcox To: Alex Shi Cc: Johannes Weiner , 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: <20201105045702.GI17076@casper.infradead.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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6eea82d8-e406-06ee-2333-eb6e2f1944e5@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = anon_vma->root; > > + /* > + * 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 = 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, and > + * page->mapping may set with anon_vma, w/o anon bit, then rmap_walk > + * may goes to rmap_walk_file() for a anon page. > + */ > + > anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; > - page->mapping = (struct address_space *) anon_vma; > + WRITE_ONCE(page->mapping, (struct address_space *) anon_vma); > page->index = linear_page_index(vma, address); > } 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: /* * 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. */