Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4430243ybv; Tue, 25 Feb 2020 20:06:41 -0800 (PST) X-Google-Smtp-Source: APXvYqw+bOe1KbhJ3pIf6I1VfC1N2v1VslcI5myfmFNBp9kp7adeFb3/ny8OoEAcPYEyMqlSDIUu X-Received: by 2002:aca:388:: with SMTP id 130mr1550618oid.89.1582690001254; Tue, 25 Feb 2020 20:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582690001; cv=none; d=google.com; s=arc-20160816; b=mpT23TD9dabrdcxRcsZm5bJLxhx3S6nfwTW11dS9jXkcExEttZz4tXbX32uRmKe291 RnqV30/VVvGDVVjsiUQOrH4triHuCcau37MDXH2+jOh4oR9o9uh2k91ZXCh39/m4jN43 j9tmANDujWTmjnVNNWszwv1wSdd37iJQWdJnmJ2eSBz93oVqiHwaoOfsC3X/CjEGZKAm 4X4axCss4x7r4mRfE00EMDWInwffdMOxo/L9V9XxRTXHYY992bs9q5STlxpYFl91Q6bT 74vzrnyZMI5AU2RRkjDHld4VFhzgr3u2Bsccn9OveB0OUyAMn175W82Sdy+uwE66l5Mg B2Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Qu2aPURbegdzfjSgtAkPb+TbG3uomn1JGpoqTQmr/0g=; b=sOCfDD64KBLE3x/l0z8GzKDQFwvLJAIsbyb/RYT3ArsFzH2R5M5WFMvPqc8ID1sRZX Vo9lsK6Cv1IBZJc4g9q795F8uTPqz0681oSATfsXOiCIVvkoGaDExzfQbaye5PR9frID gMhVLLqFh3ZFdppfE9LLrM2ZSsvGR2Hwt6Fgg0KmfiwFr+tmNux/rxZSfe16X+dNN/WD KKczxPpUDRx53SO+HuIQVFdySFtO5TW0NdV8/4ifJgpOQZnihEIsznXgmQGFPpJxWUo9 ePqPrYrF6We8WL/IHtVupHLGKtrGovtU6Y6GWpB4gis3cemV/NdcnVKJ66Qhb4K1K0D3 sQQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=FIZTPvRn; 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 b191si473263oii.266.2020.02.25.20.06.28; Tue, 25 Feb 2020 20:06:41 -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=FIZTPvRn; 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 S1726277AbgBZEGS (ORCPT + 99 others); Tue, 25 Feb 2020 23:06:18 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:52042 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbgBZEGS (ORCPT ); Tue, 25 Feb 2020 23:06:18 -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-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Qu2aPURbegdzfjSgtAkPb+TbG3uomn1JGpoqTQmr/0g=; b=FIZTPvRn3595XVQory0Jhecsta 7XjC4muiAu+9tLTT/ALg6Wttpv6fpY+HJQLq4Y7fPKXszStHmceKhxiLlF1bAsyYbTkoxvhVa2khJ 9fjlkcmhi2t2MCy94H98F65UBVbwCWVYf771eZCuA6YrXgSl6j4GB5amo8hdAFdl1BBwd1gHUb+yY u2uQJm3Rx3cxA5GHwL120ApkFqoadtRq0F6StjPiuJNO6aHI5WyUtnsP+xpSPRGBIzXbEKsHHj3Ss 8KFa64/bKLds0lA1SsVnuQb2afuoHhuDBWIBtIBf4c5G7gGkMxWRQ1rhktcynjjdGFkqFFY5MS1Ro sLtvsvsA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6nxc-0007Kc-S7; Wed, 26 Feb 2020 04:06:12 +0000 Date: Tue, 25 Feb 2020 20:06:12 -0800 From: Matthew Wilcox To: Qian Cai Cc: akpm@linux-foundation.org, elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/vmscan: fix data races at kswapd_classzone_idx Message-ID: <20200226040612.GW24185@bombadil.infradead.org> References: <20200226035827.1285-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226035827.1285-1-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 25, 2020 at 10:58:27PM -0500, Qian Cai wrote: > pgdat->kswapd_classzone_idx could be accessed concurrently in > wakeup_kswapd(). Plain writes and reads without any lock protection > result in data races. Fix them by adding a pair of READ|WRITE_ONCE() as > well as saving a branch (compilers might well optimize the original code > in an unintentional way anyway). While at it, also take care of > pgdat->kswapd_order and non-kswapd threads in allow_direct_reclaim(). I don't understand why the usages of kswapd_classzone_idx in kswapd() and kswapd_try_to_sleep() don't need changing too? kswapd_classzone_idx() looks safe to me, but I'm prone to missing stupid things that compilers are allowed to do.