Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3925602imu; Mon, 28 Jan 2019 13:27:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN4+fmH9axQvgOe0O4zoHvfILHRyIe0kANm0NqRtcdGIGIscAneom1YhV/GEQY1vUZ7x/JPX X-Received: by 2002:a62:c583:: with SMTP id j125mr23635698pfg.37.1548710863269; Mon, 28 Jan 2019 13:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548710863; cv=none; d=google.com; s=arc-20160816; b=kGBrq5DJ7vbth5eK2oKujizB75ba/i3YdT7d2LVYfsO6WTKJ+rx2E3i12EDOWeVuLn hYaid4/vZqS4lzaMv03ZjI/9SIIs16iQ+2V7mfqDqDcYAmIJUDQLwdKJlgkBheNtTI5L qVPWH6Q9KaJlMU/pxboT/vPXckCUik4kP8PSrDB9L3JhlhnTKk9QIUG6dh7evv/E/zyC 0EfUKDmjAXYtDGEAa1dL65K0XMSRv9zKOAZmIno+8h0RZVmCvxn2+Kv9Vqy5efmrp/+l ZO//yXEvmbxoHPDZLWxtKCUXGFApRtXNDae5xq5bSdGoiOkIiv0fGsI8a7hFZc2EGIVW II9Q== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=doeprTD75a3wN3TW5uXx5DNXAT9rchfp4Kk5IuJTQxU=; b=eDjqGHfk6au3gLAnt0Qdr0HlGPS/+Ph0IS+1NIBeUTwviXHYWY6LwrC8gqWdyXW3ui JzXBW/QPyGoZVmUIF13GKi7yRajvOK/WcVvfuqFkNQg3HWhI4jx3bQsWvgZrg8pjga72 d1PEN3oWjI0WFomvY8qpepKEXm1X4mmSE5yPC13KznYIvyfv/iO/A1iBWUMIrqUxSe0f tVu2kTPReI9R0H0RryPaLwOJwmwWMZKO3l/DzHDEYhh7QKG5GXr5Buo/cuNDrWFY8TiB mlystdr6HCoPmfm4Ww4vGjXzQRjBF8VaJyQFRRIWH1M7V8Swqw/SCcLFlJWzzEUyTCtT LLxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=CoGlOMn7; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h70si32896157pge.221.2019.01.28.13.27.27; Mon, 28 Jan 2019 13:27:43 -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=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=CoGlOMn7; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728234AbfA1V0f (ORCPT + 99 others); Mon, 28 Jan 2019 16:26:35 -0500 Received: from mail-yw1-f52.google.com ([209.85.161.52]:33671 "EHLO mail-yw1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727963AbfA1V0f (ORCPT ); Mon, 28 Jan 2019 16:26:35 -0500 Received: by mail-yw1-f52.google.com with SMTP id p65so7371087ywe.0 for ; Mon, 28 Jan 2019 13:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=doeprTD75a3wN3TW5uXx5DNXAT9rchfp4Kk5IuJTQxU=; b=CoGlOMn7uIwWJDcMJfm+Rj/Qm/gD747PAjoLMDuaAsDCqLhZQSn/JpFhVuDGuDVsjF ZCc8zkEIpRrNHtUDlnkc1025YEepn5whj5fHLPPzwg/nGaOXJ4pD5bxCR2wI5TuxUC48 BWSV8pZ8PCO4Myh5kKyI+tOm9WAx/oi7OMNMgHZUxJn7ycktWfXZZsol5OtiRFtjo1HM WCiToVrQxB7D49DqB2cfga9Imv1GfrUhMWjHVChx4ubG1zTMX4qOhNIsAbTi2dC5vikw xTOivor07e6gs17gDt22abifNO9qMz2FPPi8SCfL2ZFPvFyjHEY7VVO+xC22K209SvVq OA/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=doeprTD75a3wN3TW5uXx5DNXAT9rchfp4Kk5IuJTQxU=; b=uX5/ojJPSKd4K5L2N9xbxIPiD9/1pZXmCwHtGE5vVViLDDpvXn4+sJccfquCIi6dWN hijqMnLKeOj4S7AflGzqjmXNgPfqFmBJMEinEUcRGpOu9VyxPDynTlniCdO0vl3SUEdB k5N5SmK5GjnR4H2Gjy02Z8p74z38eSdGXSbBKcVk2N43JAXQp/ooc06y9wzDadXCjbMd 4dVRPTDRjsm/BuTDOcoL9E84DrmtiBmm0FDqd/5tTzBNrKZCIMruz7kByJyISSvuP8mn La5ZTKvge2mDbdRYM+klhWEQ3nnSMPe3NS0htsMDk/5njWzcxYEgd87Eg/+7ipzqGq+D DGKQ== X-Gm-Message-State: AJcUukfcUhXHdGtXNE+BulQJ5omSpcHUYIdeGF3BU7IEH7yTMhBOj9X7 RPbRc7blv6Egwccvh1f2Yg7Fsw== X-Received: by 2002:a81:3d3:: with SMTP id 202mr22391227ywd.18.1548710793942; Mon, 28 Jan 2019 13:26:33 -0800 (PST) Received: from localhost ([2620:10d:c091:200::5:42c8]) by smtp.gmail.com with ESMTPSA id e3sm14662632ywe.63.2019.01.28.13.26.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 13:26:33 -0800 (PST) Date: Mon, 28 Jan 2019 16:26:32 -0500 From: Johannes Weiner To: Suren Baghdasaryan Cc: gregkh@linuxfoundation.org, tj@kernel.org, lizefan@huawei.com, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 5/5] psi: introduce psi monitor Message-ID: <20190128212632.GD1416@cmpxchg.org> References: <20190124211518.244221-1-surenb@google.com> <20190124211518.244221-6-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190124211518.244221-6-surenb@google.com> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One thought on the v3 delta that I missed earlier: On Thu, Jan 24, 2019 at 01:15:18PM -0800, Suren Baghdasaryan wrote: > +/* > + * psi_update_work represents slowpath accounting part while psi_group_change > + * represents hotpath part. There are two potential races between them: > + * 1. Changes to group->polling when slowpath checks for new stall, then hotpath > + * records new stall and then slowpath resets group->polling flag. This leads > + * to the exit from the polling mode while monitored state is still changing. > + * 2. Slowpath overwriting an immediate update scheduled from the hotpath with > + * a regular update further in the future and missing the immediate update. > + * Both races are handled with a retry cycle in the slowpath: > + * > + * HOTPATH: | SLOWPATH: > + * | > + * A) times[cpu] += delta | E) delta = times[*] > + * B) start_poll = (delta[poll_mask] &&| if delta[poll_mask]: > + * cmpxchg(g->polling, 0, 1) == 0)| F) polling_until = now + grace_period > + * if start_poll: | if now > polling_until: > + * C) mod_delayed_work(1) | if g->polling: With the polling flag being atomic now, this "if g->polling" line isn't accurate anymore. Since this diagram is specifically about memory ordering, this should move the g->polling load up to where delta is read and then refer to unordered local variables down here.