Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1877928ybc; Wed, 13 Nov 2019 05:48:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzyugA5OoOQtj9P49OS3DNAIy64caZmQYseG0nNhTMC9Na7rHzaGYiiJMEFnw2W9+cBQqL1 X-Received: by 2002:a50:bb48:: with SMTP id y66mr3624251ede.66.1573652920434; Wed, 13 Nov 2019 05:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573652920; cv=none; d=google.com; s=arc-20160816; b=Ur+OqIAw2nbVlsCAeMN5Ye1T4rp+93oLlnrroP6GvMZl57dNsx6EKu5F8r32a7C6Hm w8hWNAycB+zRywSSta+cVwuClwpGLVwOL8XSlaRGBtyrZ38mKUwvhfPjyQP2szC963IF SJLYJ+rvSlimlFmjHUFb5pnM9wYySBlTfIuqBvpxtqCSi4HFJu6oor37ek/UrKRx9XfR fGU2Ba7oiNfSiTU6Dx1+9sqMEG1EiEMBWvqlgnOo7CXNAValH1ITnEixHucnivM56+le EBAk6TqYcXesPuq2zerRCr+x3B9NW1LprGw5dI226cDbu37Bb59sCeqI95enDYkkdsfQ JhzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zRi6DLbBkEdEozkjZm98oVK/x7aADkM+iJVk1EnTFWk=; b=0QhZw+SttjEq+klXrj111wx+3NsIIpAREdfYVfRA1YkLAOzm+7hIuqtLtRmOXai9y3 Ja+4R5BBCyE7E8s0xmpNxxMdv6YV5OC07QJAzenGotuNYm5xwNbVNzYukqRZTrwNHdNz DdNNgyXf5gq7nugjR4ICs6OI66/gEHfY443+1b9ycm43bJz1I2MPbkEtsab7bYCeO4Gm ajvphIwMTfD4LpGLVIX6yBfn4cWbilr5QpYDviSH/WYLDRBzKHSXs/2zV1mGG82chg9e IHfwDbb+vli3gPhgr3ArQUGYlT7ZdoNZtwd05dZ0tu8dInHEyd5SoaresYEZ/ChXNTJn RncA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eLUpbLpu; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si1045768eja.211.2019.11.13.05.48.16; Wed, 13 Nov 2019 05:48:40 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eLUpbLpu; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727385AbfKMNpG (ORCPT + 99 others); Wed, 13 Nov 2019 08:45:06 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:51770 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfKMNpG (ORCPT ); Wed, 13 Nov 2019 08:45:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zRi6DLbBkEdEozkjZm98oVK/x7aADkM+iJVk1EnTFWk=; b=eLUpbLpu+7Mqv1XqZbOAstW1Xr s3S9M4qabuNrKeHjr+aMtQQTUqyJI+s3ZAcWxGGHoOLFIGkzrOpj7FV2i53sWElgDVbC8aR6ahCw4 RBdV5TnpKLElNuiyfEOEHdptZ1Paw4v6/YHhRda6W3KlU4ay0toajZfXkccooGszCUXu/yLxgAaC/ pFK9jKjJHT0Yqv57ZjYInT11Yq0q2yNowES80QxjYTVAK0ETrYGnpDUU1t5IkbFEWy6JC/g55VRZ8 Y+YCQRbkdtBuG2DTLd8Fj+26ap7yNVh1HvvGzY2S79eh+sc42JHFGRS0kewhOnmDsZICEEYfZx3N+ TuByAZvw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iUsxC-0003wY-TT; Wed, 13 Nov 2019 13:45:02 +0000 Date: Wed, 13 Nov 2019 05:45:02 -0800 From: Matthew Wilcox To: Alex Shi Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, Johannes Weiner , Michal Hocko , Vladimir Davydov , Roman Gushchin , Shakeel Butt , Chris Down , Thomas Gleixner , Vlastimil Babka , Andrey Ryabinin , swkhack , "Potyra, Stefan" , Jason Gunthorpe , Mauro Carvalho Chehab , Peng Fan , Nikolay Borisov , Ira Weiny , Kirill Tkhai , Yafang Shao Subject: Re: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different Message-ID: <20191113134502.GD7934@bombadil.infradead.org> References: <1573567588-47048-1-git-send-email-alex.shi@linux.alibaba.com> <1573567588-47048-5-git-send-email-alex.shi@linux.alibaba.com> <20191112143624.GA7934@bombadil.infradead.org> <297ad71c-081c-f7e1-d640-8720a0eeeeba@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <297ad71c-081c-f7e1-d640-8720a0eeeeba@linux.alibaba.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 13, 2019 at 10:26:24AM +0800, Alex Shi wrote: > 在 2019/11/12 下午10:36, Matthew Wilcox 写道: > > On Tue, Nov 12, 2019 at 10:06:24PM +0800, Alex Shi wrote: > >> +/* Don't lock again iff page's lruvec locked */ > >> +static inline struct lruvec *relock_page_lruvec_irq(struct page *page, > >> + struct lruvec *locked_lruvec) > >> +{ > >> + struct pglist_data *pgdat = page_pgdat(page); > >> + struct lruvec *lruvec; > >> + > >> + rcu_read_lock(); > >> + lruvec = mem_cgroup_page_lruvec(page, pgdat); > >> + > >> + if (locked_lruvec == lruvec) { > >> + rcu_read_unlock(); > >> + return lruvec; > >> + } > >> + rcu_read_unlock(); > > > > Why not simply: > > > > rcu_read_lock(); > > lruvec = mem_cgroup_page_lruvec(page, pgdat); > > rcu_read_unlock(); > > > > if (locked_lruvec == lruvec) > > The rcu_read_unlock here is for guarding the locked_lruvec/lruvec comparsion. > Otherwise memcg/lruvec maybe changed, like, from memcg migration etc. I guess. How does holding the RCU lock guard the comparison? You're comparing two pointers for equality. Nothing any other CPU can do at this point will change the results of that comparison. > > Also, why are you bothering to re-enable interrupts here? Surely if > > you're holding lock A with interrupts disabled , you can just drop lock A, > > acquire lock B and leave the interrupts alone. That way you only need > > one of this variety of function, and not the separate irq/irqsave variants. > > > > Thanks for the suggestion! Yes, if only do re-lock, it's better to leave the irq unchanging. but, when the locked_lruvec is NULL, it become a first time lock which irq or irqsave are different. Thus, in combined function we need a nother parameter to indicate if it do irqsaving. So comparing to a extra/indistinct parameter, I guess 2 inline functions would be a bit more simple/cleary? Ah, right, I missed the "if it's not held" case.