Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3072401ybh; Mon, 16 Mar 2020 15:19:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvBLeS4RLRQv76eoDFHTHNS26OzidF5YnbWWIilZTt5oXYb0cGKBo5A80XaVw4PpTQ7D+7M X-Received: by 2002:a9d:4c98:: with SMTP id m24mr1282985otf.158.1584397171962; Mon, 16 Mar 2020 15:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584397171; cv=none; d=google.com; s=arc-20160816; b=j2JFRAxdDRqJBFONWJyaXcBlYZBJ09Sx2+E5x9ZNzMn1rQ0C0LyFwt4/NC0B1NUTgF pKkFKTUEtYoA13U1gY1RnhefV20IUg7I5uArY8dXbbdKC9eQYZzX6H3BiaxHHVWtetam XiF9yvAOHAwzclCoBqq0rUZCqsoqS84JY9QnH1/3PmwWV1gSrDvjNioVbv9dCt8WITOt Y/SGJ8qphmg6ZtoavlLIxfboZrKpKVlXIn+pw2IsI117tavqO6f4YTyPM9I2mRZ8si5j ffKMZLiFwLMyX3Jc/tzH6bG1UZr8alvu8XjsgbRHwxcYM41+Y2zJTd89ORykmPz78ZTy gC3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=nM5+rARDO3JP0+rmC3g+C1T6Hr8XDK/cThOzGtMjnZ0=; b=BrjjL2IGQsBsUloh796OXMANkFhhzMJLEDDYhIKV/e6MJVX6JAm4HYF9Pt9IGgjg4N 4x7e4aC0GX+7XZn4+ZsxxzL8cpDR5S/fZrn/p0qzdkJPxlx3TvGKlbl0QaxmPqciGerj Kih+JE0W/jGUyH12unwsLRhQ7kweRsflLmYe2SKT+Rv13MIfAffw3iL6ld/OkTSslKRE nd4DXBqhrbJOpTsuPGdVRW53uUrNYxU272rZ6hUMKzWI1Zomcx7CfjXt9AAt2+JYpY8V 4iirIIS5qEM5o4qiCaWlmYD4QhvoR/lH5MunOhp2zLzxKjExfhoCkdjupLOQigs0PmB3 WBMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si567691oiy.229.2020.03.16.15.19.20; Mon, 16 Mar 2020 15:19:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732747AbgCPWSe (ORCPT + 99 others); Mon, 16 Mar 2020 18:18:34 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:55268 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732716AbgCPWSe (ORCPT ); Mon, 16 Mar 2020 18:18:34 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Tsp8z.Q_1584397108; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tsp8z.Q_1584397108) by smtp.aliyun-inc.com(127.0.0.1); Tue, 17 Mar 2020 06:18:30 +0800 Subject: Re: [PATCH 2/2] mm: swap: use smp_mb__after_atomic() to order LRU bit set From: Yang Shi To: Vlastimil Babka , shakeelb@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1584124476-76534-1-git-send-email-yang.shi@linux.alibaba.com> <1584124476-76534-2-git-send-email-yang.shi@linux.alibaba.com> <3c13c484-8fbf-3c3a-fbe1-a40434869e55@suse.cz> <52877743-bb43-f928-2995-92607272dbb8@linux.alibaba.com> Message-ID: Date: Mon, 16 Mar 2020 15:18:27 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <52877743-bb43-f928-2995-92607272dbb8@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/16/20 10:49 AM, Yang Shi wrote: > > > On 3/16/20 10:40 AM, Vlastimil Babka wrote: >> On 3/13/20 7:34 PM, Yang Shi wrote: >>> Memory barrier is needed after setting LRU bit, but smp_mb() is too >>> strong.  Some architectures, i.e. x86, imply memory barrier with atomic >>> operations, so replacing it with smp_mb__after_atomic() sounds better, >>> which is nop on strong ordered machines, and full memory barriers on >>> others.  With this change the vm-calability cases would perform better >>> on x86, I saw total 6% improvement with this patch and previous inline >>> fix. >>> >>> The test data (lru-file-readtwice throughput) against v5.6-rc4: >>>     mainline    w/ inline fix    w/ both (adding this) >>>     150MB        154MB        159MB >>> >>> Fixes: 9c4e6b1a7027 ("mm, mlock, vmscan: no more skipping pagevecs") >>> Cc: Shakeel Butt >>> Cc: Vlastimil Babka >>> Signed-off-by: Yang Shi >> According to my understanding of Documentation/memory_barriers.txt >> this would be >> correct (but it might not say much :) > > This is my understanding too. > >> >> Acked-by: Vlastimil Babka >> >> But i have some suggestions... >> >>> --- >>>   mm/swap.c | 6 +++--- >>>   1 file changed, 3 insertions(+), 3 deletions(-) >>> >>> diff --git a/mm/swap.c b/mm/swap.c >>> index cf39d24..118bac4 100644 >>> --- a/mm/swap.c >>> +++ b/mm/swap.c >>> @@ -945,20 +945,20 @@ static void __pagevec_lru_add_fn(struct page >>> *page, struct lruvec *lruvec, >>>        * #0: __pagevec_lru_add_fn        #1: clear_page_mlock >>>        * >>>        * SetPageLRU()                TestClearPageMlocked() >>> -     * smp_mb() // explicit ordering    // above provides strict >>> +     * MB()     // explicit ordering    // above provides strict >> Why MB()? That would be the first appareance of 'MB()' in the whole >> tree. I >> think it's fine keeping smp_mb()... > > I would like to use a more general name, maybe just use "memory barrier"? Keeping smp_mb() should be just fine... > >> >>>        *                    // ordering >>>        * PageMlocked()            PageLRU() >>>        * >>>        * >>>        * if '#1' does not observe setting of PG_lru by '#0' and fails >>>        * isolation, the explicit barrier will make sure that >>> page_evictable >>> -     * check will put the page in correct LRU. Without smp_mb(), >>> SetPageLRU >>> +     * check will put the page in correct LRU. Without MB(), >>> SetPageLRU >> ... same here ... >> >>>        * can be reordered after PageMlocked check and can make '#1' >>> to fail >>>        * the isolation of the page whose Mlocked bit is cleared (#0 >>> is also >>>        * looking at the same page) and the evictable page will be >>> stranded >>>        * in an unevictable LRU. >> Only here I would note that SetPageLRU() is an atomic bitop so we can >> use the >> __after_atomic() variant. And I would move the actual SetPageLRU() >> call from >> above the comment here right before the barrier. > > Sure. Thanks. > >> >>>        */ >>> -    smp_mb(); >>> +    smp_mb__after_atomic(); >> Thanks. >> >>>         if (page_evictable(page)) { >>>           lru = page_lru(page); >>> >