Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1296487imu; Wed, 16 Jan 2019 16:38:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN4LuH+TINzIGf1h4LmzPQVUeHECG8ZrYcUmJccASTnpxKV0/g8TIp8M1q3k/2uT4Y6nWw7y X-Received: by 2002:a17:902:2f03:: with SMTP id s3mr12560143plb.277.1547685514176; Wed, 16 Jan 2019 16:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685514; cv=none; d=google.com; s=arc-20160816; b=QF3lkShRgKzsf3PxRUjGHQEZNN0szuyd6qw0AU4T3vtiRkpaT2Xh7LA3ggl+zHlFWB iiFvAMFHfoROEEv7GoQJO9M5yGJG5kU0qHCpiI7CnMGL9/8fivjrGAMx2dsvU/DKqjLD A56dPWCaH3HmFO0JasRIXK1h07B9ljcEz+1embYgCtIXn7Geg64fpVjA1PfvM1deYQv6 p4ton2hUQayx4ohOCP65qcRel8b++H+WfVqrnP2A7Q2RHR2FGaZDw1C9REWgrfTaJ5al sJostczxNC0ar5UOPJv9nZp80OJ2v/90SPPUIWAzdZkgA8W8LXHHkCGowKzqFBNXgm8R AWpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=HJrfE3jaolNs6YKqdZtpYFmOvcf18H8OhY7pa4kzWEY=; b=FFQVPE8+PT8v2k/x2EDizi0r0bOkcDaWUlMhHyogYu2ok3aTelMFvQ+EoB/JaFIObh +3pFjzBglyHfAajGw0BXoD5zOaahY4TwwHqWmyMGZvnrAUIHBUjhcQhNBYVhPoQd4Hwo Ek8Nz58ULEIKNRVJejZEwfuj44yO8ID8A0Vj1wkHoM7ZqpEH/zrPS2gB08WlCRxhtVev dVzJlIvvJWjeiDvjvK+n4V5EAOAoO8vLA/FNaIrngfBGwVqwtihdwfl3RpSnUL271GoX fAuwnNM6ChxSBsNSQS2nAqeY6kmwqHHJM7VWaKcOPZm5R+I5Vyvs5i5HrQB8RsXccnVP nvBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j8HwzKf4; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb1si7953103plb.37.2019.01.16.16.38.19; Wed, 16 Jan 2019 16:38:34 -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=@google.com header.s=20161025 header.b=j8HwzKf4; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730305AbfAPV3j (ORCPT + 99 others); Wed, 16 Jan 2019 16:29:39 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44440 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730241AbfAPV3h (ORCPT ); Wed, 16 Jan 2019 16:29:37 -0500 Received: by mail-wr1-f67.google.com with SMTP id z5so8618488wrt.11 for ; Wed, 16 Jan 2019 13:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HJrfE3jaolNs6YKqdZtpYFmOvcf18H8OhY7pa4kzWEY=; b=j8HwzKf4QtGnl55VhWxxU62RJz2zdHqwwXdAJtf4r17Cb5i4Z9PTr3LYowNmAp7bfs +ORL7QKVLtsnXsxfog2gfV4zCd8b0Lp/hBynHbSFCWHpsjhb+gUzSAD4s6BHH/fRV6pB Y8RKIyku/qvSySJPfI4lQbUHofvTuiB69SAxZnEm2/M1qYVOb6tzofxI8DeoSsxlVo+u nZ82jRaDZ+i/eUXJAlQsvkLtbuNxntHHswTgQKdk/B7zvICxLyY6D2dBF/Yx3CINZzCc r7EEDIuZ1ahCWCcTqQtXrHreZMO0rz9tVS/ldkSGVBMgfPl+UDSbYYc4Q+A3wO26h8wa jfTw== 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=HJrfE3jaolNs6YKqdZtpYFmOvcf18H8OhY7pa4kzWEY=; b=kr17ToiJIO19SbIzOJqafrIfesz/n0PYafaBchTIZmpJDl+wEEIadnm8nBxj5cPc3T Y4pYzesjr6aUzCyfWt0YaWtC5C4AX93qXTRjDNqqq2+tg5o39ne2u1DPdxz9WYmmVSC7 pua8iKnSTDh4iEbI6dDjIEkvHIlTOfacH5wgyDDq0QbZEntP2uPWTiS2Ee2XMffFKDhE NDm4POoelOV/abdIYxWV9IUfvJWl+JB3yZMBO8U1bBya4a4TBNR1PInuJ68wwSlCloj0 AiNJYCZuIBy2qjWMGGS9A4ghUi2Bw6WVSIBTESOZRLF480GDBKfPEbETiadBky4iae9y sbhQ== X-Gm-Message-State: AJcUukdmMcUgf7BMotSsq6KNooBJ1Fe53kqI52RfEU3Gpm5WtipgO6fA d5M22WZEwVBJ4LiTg2GYAbA3OGa8UIJyK/qJkbrCPg== X-Received: by 2002:adf:de91:: with SMTP id w17mr9843729wrl.320.1547674175412; Wed, 16 Jan 2019 13:29:35 -0800 (PST) MIME-Version: 1.0 References: <20190110220718.261134-1-surenb@google.com> <20190110220718.261134-6-surenb@google.com> <20190114102137.GB14054@worktop.programming.kicks-ass.net> <20190116132446.GF10803@hirez.programming.kicks-ass.net> <20190116191728.GA1380@cmpxchg.org> <20190116192744.GA1576@cmpxchg.org> In-Reply-To: <20190116192744.GA1576@cmpxchg.org> From: Suren Baghdasaryan Date: Wed, 16 Jan 2019 13:29:24 -0800 Message-ID: Subject: Re: [PATCH v2 5/5] psi: introduce psi monitor To: Johannes Weiner Cc: Peter Zijlstra , Greg Kroah-Hartman , Tejun Heo , lizefan@huawei.com, axboe@kernel.dk, dennis@kernel.org, Dennis Zhou , Ingo Molnar , Andrew Morton , Jonathan Corbet , cgroups@vger.kernel.org, linux-mm , linux-doc@vger.kernel.org, LKML , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 11:27 AM Johannes Weiner wrote: > > On Wed, Jan 16, 2019 at 02:17:28PM -0500, Johannes Weiner wrote: > > On Wed, Jan 16, 2019 at 09:39:13AM -0800, Suren Baghdasaryan wrote: > > > On Wed, Jan 16, 2019 at 5:24 AM Peter Zijlstra wrote: > > > > > > > > On Mon, Jan 14, 2019 at 11:30:12AM -0800, Suren Baghdasaryan wrote: > > > > > For memory ordering (which Johannes also pointed out) the critical point is: > > > > > > > > > > times[cpu] += delta | if g->polling: > > > > > smp_wmb() | g->polling = polling = 0 > > > > > cmpxchg(g->polling, 0, 1) | smp_rmb() > > > > > | delta = times[*] (through goto SLOWPATH) > > > > > > > > > > So that hotpath writes to times[] then g->polling and slowpath reads > > > > > g->polling then times[]. cmpxchg() implies a full barrier, so we can > > > > > drop smp_wmb(). Something like this: > > > > > > > > > > times[cpu] += delta | if g->polling: > > > > > cmpxchg(g->polling, 0, 1) | g->polling = polling = 0 > > > > > | smp_rmb() > > > > > | delta = times[*] (through goto SLOWPATH) > > > > > > > > > > Would that address your concern about ordering? > > > > > > > > cmpxchg() implies smp_mb() before and after, so the smp_wmb() on the > > > > left column is superfluous. > > > > > > Should I keep it in the comments to make it obvious and add a note > > > about implicit barriers being the reason we don't call smp_mb() in the > > > code explicitly? > > > > I'd keep 'em out if they aren't actually in the code. But I'd switch > > > > delta = times[*] > > > > in this comment to to > > > > get_recent_times() // implies smp_mb() > > Actually, I might have been mistaken about this. The seqcount locking > does an smp_rmb() and an smp_wmb(), and that orders reads and writes > respectively, but doesn't necessarily order reads against writes. > > So I think we need an explicit smp_mb() after all. I see. So, the action items I collected so far: 1. Add a comment in the code next to cmpxchg() indicating implicit smp_mb. 2. Add explicit smp_mb after "g->polling = 0" and before "delta = times[*]" both in the code and in the comments (in the slowpath). 3. Use atomic_t for g->polling. Add a note in the comments why atomic operations are not needed in the slowpath. 4. Minimize line-breaks. Please let me know if I missed anything, otherwise will make these changes and post ver 3 of the patchset. Thanks, Suren.