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=-0.6 required=3.0 tests=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 85AA7C33CA9 for ; Mon, 13 Jan 2020 16:35:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 472B321739 for ; Mon, 13 Jan 2020 16:35:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XlRk9bRC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 472B321739 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3DCD28E001B; Mon, 13 Jan 2020 11:35:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 38C7B8E0012; Mon, 13 Jan 2020 11:35:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2ACF28E001B; Mon, 13 Jan 2020 11:35:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 14D328E0012 for ; Mon, 13 Jan 2020 11:35:04 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id BE50A8248047 for ; Mon, 13 Jan 2020 16:35:03 +0000 (UTC) X-FDA: 76373160486.11.sleet08_2c27002c68f22 X-HE-Tag: sleet08_2c27002c68f22 X-Filterd-Recvd-Size: 3818 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 13 Jan 2020 16:35:03 +0000 (UTC) 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=OyWI+2CxCOjVFobV/HzUixcC6m6SP/UUicEvP6oEb8U=; b=XlRk9bRCU394R+rkkl6rrGt/r6 Qqn9DBhqjxKtJUEgSFbDy5JQNJbJrSLegPLKMIFaGZJU18NogpLUuIVMtSW9KicfpHxIQHnBO/ocW i6b7r6Sypq7BF6c/ab4JiZ9/G5L1ZIk9k7+CCRNARPqSaAzbPWx9fppVhgFp9uixD9X1Ccq6Wkp3i qaaCOJ0wKe++RohEAsXFx/2Fd4hbRAGlSezRtNA9jQ80y1+7E21HirlBOjtVUEsSogU7s6DPjzYcu hkcFwwu2lw67HcSA5E7Nk/AqE+ag7qc1Laiq0dLRZsn/4YzeVcznnqauAkfvMcLgbfs3C3d5NsjI/ kYfSRGdQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1ir2g4-0005KO-K2; Mon, 13 Jan 2020 16:34:56 +0000 Date: Mon, 13 Jan 2020 08:34:56 -0800 From: Matthew Wilcox To: Alex Shi Cc: Konstantin Khlebnikov , 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, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, shakeelb@google.com, hannes@cmpxchg.org, Michal Hocko , Vladimir Davydov Subject: Re: [PATCH v7 02/10] mm/memcg: fold lru_lock in lock_page_lru Message-ID: <20200113163456.GA332@bombadil.infradead.org> References: <1577264666-246071-1-git-send-email-alex.shi@linux.alibaba.com> <1577264666-246071-3-git-send-email-alex.shi@linux.alibaba.com> <36d7e390-a3d1-908c-d181-4a9e9c8d3d98@yandex-team.ru> <952d02c2-8aa5-40bb-88bb-c43dee65c8bc@linux.alibaba.com> <2ba8a04e-d8e0-1d50-addc-dbe1b4d8e0f1@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 Mon, Jan 13, 2020 at 08:47:25PM +0800, Alex Shi wrote: > =E5=9C=A8 2020/1/13 =E4=B8=8B=E5=8D=885:55, Konstantin Khlebnikov =E5=86= =99=E9=81=93: > >>> That's wrong. Here PageLRU must be checked again under lru_lock. > >> Hi, Konstantin, > >> > >> For logical remain, we can get the lock and then release for !PageLR= U. > >> but I still can figure out the problem scenario. Would like to give = more hints? > >=20 > > That's trivial race: page could be isolated from lru between > >=20 > > if (PageLRU(page)) > > and > > spin_lock_irq(&pgdat->lru_lock); >=20 > yes, it could be a problem. guess the following change could helpful: > I will update it in new version. > + if (lrucare) { > + lruvec =3D lock_page_lruvec_irq(page); > + if (likely(PageLRU(page))) { > + ClearPageLRU(page); > + del_page_from_lru_list(page, lruvec, page_lru(p= age)); > + } else { > + unlock_page_lruvec_irq(lruvec); > + lruvec =3D NULL; > + } What about a harder race to hit like a page being on LRU list A when you look up the lruvec, then it's removed and added to LRU list B by the time you get the lock? At that point, you are holding a lock on the wrong LRU list. I think you need to check not just that the page is still PageLRU but also still on the same LRU list.