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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 16B58C4338F for ; Thu, 19 Aug 2021 02:04:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8ECFA60FC4 for ; Thu, 19 Aug 2021 02:04:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8ECFA60FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 100EA8D0001; Wed, 18 Aug 2021 22:04:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1366B0071; Wed, 18 Aug 2021 22:04:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE00F8D0001; Wed, 18 Aug 2021 22:04:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id D72126B006C for ; Wed, 18 Aug 2021 22:04:46 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6B99582DF1A9 for ; Thu, 19 Aug 2021 02:04:46 +0000 (UTC) X-FDA: 78490186572.15.846FBE6 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf30.hostedemail.com (Postfix) with ESMTP id 64FD3E004EA1 for ; Thu, 19 Aug 2021 02:04:45 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so6351502pje.0 for ; Wed, 18 Aug 2021 19:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P8pSq2ahTDuGoiVpRUZKFPdbsfAusrUrIIUu2Ni7e/s=; b=MwyQKUFxuRCfpT7aSdwhgTpvG5iUx1xgrIXYt3rxB7MHSmzkskfDLFcbxeXvm+FoKM ocgF37XHI8qFhpJONlkRaoLK7yTqzWaJM4ZwtgzcdPvKbjFItjbiDvIFispOfR9w7nTI Ha1VyaEWTKRQrbtabTSg3aiHf++IfgVW6B9UZCAKnxuFLzhbOXcvjVwQWEdMj5/YtvOX y21AQozEUgxJl7t8+BKEGuTIIBkxxvKkt1Jb2VjvfIux1gW0lzNyvIK/h3cmdSqbAOvq huqmoj0KHFnAis97/PsQ2ysH82VXin9Oc7MN1dD+z0Vtx5WVHd6aiu8JT4ygUwq5szei LAoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P8pSq2ahTDuGoiVpRUZKFPdbsfAusrUrIIUu2Ni7e/s=; b=HGvgFImnA/U4647pGwEFVI8D2vSN98xRIGLpnIop89DwETrqZDOWWyfmWNHs3bsXvJ j0UiomalfGUnQ1EmevDglRduC0aCnMepvh8Mk1ITZi9gJ3MRMWyEnqEDy7147gKLpOBz ch8X0hFOXLlnDuKhlUBnuZs6R61cvyvk7oktgIrvkQmOL9Zn8T7+WD25QRiYA5kkSBFn QsSvq/ZFwU+9g+EGS9Ep76YzjEEGDhWETxNzEFX7RYhZ8tn7SXnxgeM3UWlBV52hE7LM 0gqmn5i/aV5b31dhAFtqUtPTCHliZdcCa2ikv1xTkej3+lESazVB71eprQ6MHiqD/sMf cuAg== X-Gm-Message-State: AOAM531cG5+xLCNWPy7ZkVQE46f0QE1x7fMoq21kCm9dL2sYfcMrG6Rp RS6uffZ0K5xj+eZqPfFWiezEyLKW8OkvPbUNM8DtAQ== X-Google-Smtp-Source: ABdhPJwEss61R+YGuKuQ/7eeNweeErVCe+4SBPDaGMiRjtIhpwl7hLMuELKSaujA/O01JKE9PkmjK0uXJc8fTLRHebY= X-Received: by 2002:a17:902:d48e:b0:12d:7aa5:de2e with SMTP id c14-20020a170902d48e00b0012d7aa5de2emr9670291plg.34.1629338684303; Wed, 18 Aug 2021 19:04:44 -0700 (PDT) MIME-Version: 1.0 References: <20210815061034.84309-1-yanghui.def@bytedance.com> <20210816175952.3c0d1eee821cd2d9ed7c3879@linux-foundation.org> In-Reply-To: From: Muchun Song Date: Thu, 19 Aug 2021 10:04:06 +0800 Message-ID: Subject: Re: [PATCH v3] mm/mempolicy: fix a race between offset_il_node and mpol_rebind_task To: Matthew Wilcox Cc: Andrew Morton , yanghui , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 64FD3E004EA1 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=MwyQKUFx; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf30.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam04 X-Stat-Signature: seqyr8mznx3o3suia3e654crzmcfzeg7 X-HE-Tag: 1629338685-822145 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 Wed, Aug 18, 2021 at 11:07 PM Matthew Wilcox wrote: > > On Wed, Aug 18, 2021 at 10:02:46PM +0800, Muchun Song wrote: > > On Tue, Aug 17, 2021 at 9:43 AM Matthew Wilcox wrote: > > > > > + unsigned int target, nnodes; > > > > > int i; > > > > > int nid; > > > > > + /* > > > > > + * The barrier will stabilize the nodemask in a register or on > > > > > + * the stack so that it will stop changing under the code. > > > > > + * > > > > > + * Between first_node() and next_node(), pol->nodes could be changed > > > > > + * by other threads. So we put pol->nodes in a local stack. > > > > > + */ > > > > > + barrier(); > > > > > > I think this could be an smp_rmb()? > > > > Hi Matthew, > > > > I have a question. Why is barrier() not enough? > > I think barrier() may be more than is necessary. We don't need a > barrier on non-SMP systems (or do we?) And we only need to order reads, > not writes. Here barrier() is just a compiler barrier, which is cheaper than smp_rmb() which usually equals to memory barrier instruction plus barrier(). So I think barrier() , which will stabilize the nodemask in a register or on the stack, is more appropriate here. Thanks.