From owner-freebsd-fs@freebsd.org Mon May 20 16:26:32 2019 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F0F7315B1CA0 for ; Mon, 20 May 2019 16:26:31 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound1a.eu.mailhop.org (outbound1a.eu.mailhop.org [52.58.109.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F311985ADE for ; Mon, 20 May 2019 16:26:30 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1558368621; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=hCxZoBzJT19drGZsCQrrZcdsR9LZaO3nSlL5Ss/c12MrntcF+skjS1jF0Iw5GxakSbcXy4DvJCJXj 8MN/J96Q8Z/lI9CHbm0XTt9rF6mTXhVwzeE5br3RF7+kUx/piJKfqBNcI0LGoMbzMB5Qu+bhdwZP0n AKpXGiTpWWzHHOPl8DoNXaI/qCqg2Dbax2IVVdg7Nm9IXLXR8xMLXcmlXcDWJfsRKY+MAH/Wu4Vnwz nt+YH31Mh3b3HRNuVt496b/imZt32B/QvKpmC/0RukWVg879eEgxl/XLyFWiIVZOLU70EQaouEGeDZ VWfYLxHvEXLHzA7v3jqNbPYKNJj2yPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:dkim-signature:from; bh=O2Lw82ky9ld8ggooTZudj58wNggpWoWPWmDaXwDYlV8=; b=SLU8L7DG8aH7yXt3WEhp8g4eqBTjW59zHa7h4TQ7Qawz4spt8AmERzWL3VFcXYReL97W0lx6Rn2KC z5eD269SN4JwI8nBgHlZ1dfRbY/R0nqO3Eg5OA8/WNlGvXWKeGSvLX9Gwfq2b0jJCbc7mRo+/r1LSq vE/whgRiBRwDWsxmbzd9/RNW+jba034fbDuEXraopK+x9Kq/xIpUW3ylwz8o4tqMUbn4+JuoTlaZci BomvFcUg6zNImw7BEIZ2JSfO044jVwyxaPEp2tcphMFJ2kauvuUmkQpANuRbzPN006IWERVSWy9xH4 1JGrPxPNriKSB8lDBGr+xqmmWIWBwSQ== ARC-Authentication-Results: i=1; outbound2.eu.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:from; bh=O2Lw82ky9ld8ggooTZudj58wNggpWoWPWmDaXwDYlV8=; b=LB15JlqGEc/hcNz0vk6EIORpLacFWT1Vkh+sVi3mTsYV2YHGAm57MJWWpjXsGynyMz7vrOyxekuCf F73Rq1H58IovPO3mO86Q/EMv02YAWsfU0iJX2S4UvvUaohSs8dYxgeCV8yZdFmW2zEhgl2B7j854Ub FEmKI5c5SThbhJnXuzDevUB510hujF1Cr2qVBejnOjM3bHZzBRnIZGlbYjk7WjMRv8HolOIxLwwLg/ 4rFd53zOpR7rR8vXjzfAubqAKhxGdwl2fd3qpew08sE45dDalnuNMpDle7ezbPHY8xwEBnPCK8WZmi 3P9arKYh/gVq1K9PsQ8aeC315GG5EUA== X-MHO-RoutePath: aGlwcGll X-MHO-User: c1ac49d9-7b19-11e9-85c6-c97e5c048ed3 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [67.177.211.60]) by outbound2.eu.mailhop.org (Halon) with ESMTPSA id c1ac49d9-7b19-11e9-85c6-c97e5c048ed3; Mon, 20 May 2019 16:10:18 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id x4KGAGjq024895; Mon, 20 May 2019 10:10:16 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: <174f71126ca39907370a8904c07546b712ad91b9.camel@freebsd.org> Subject: Re: Commit r345200 (new ARC reclamation threads) looks suspicious to me. From: Ian Lepore To: lev@FreeBSD.org, freebsd-fs@freebsd.org, freebsd-hackers@FreeBSD.org, Alexander Motin Date: Mon, 20 May 2019 10:10:16 -0600 In-Reply-To: <55989579-a228-498e-2842-453cad6f315f@FreeBSD.org> References: <55989579-a228-498e-2842-453cad6f315f@FreeBSD.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: F311985ADE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.988,0]; ASN(0.00)[asn:16509, ipnet:52.58.0.0/15, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 May 2019 16:26:32 -0000 On Mon, 2019-05-20 at 18:38 +0300, Lev Serebryakov wrote: > I'm looking at last commit to > 'sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c' (r345200) and > have one question. > > Is it Ok for two threads to communicate via simple global variable? > Now > new code has (line 315): > > static boolean_t arc_adjust_needed = B_FALSE; > > And after that some threads run code like this: > > mutex_enter(&arc_adjust_lock); > arc_adjust_needed = B_TRUE; > mutex_exit(&arc_adjust_lock); > zthr_wakeup(arc_adjust_zthr); > > And thread `arc_adjust_zthr` has code like this (line 4874): > > return (arc_adjust_needed); > > This variable is not atomic. It is not updated and/or read in atomic > way. What code gives guarantees that `arc_adjust_zthr` will detect > this > change? I don't see any. Am I wrong? The arc_adjust_needed variable is the gating condition associated with a condition variable and lock. It is only read or changed while holding a lock, and the acquiring and releasing of that lock provides the needed memory barriers. In this case, the association with the condition variable and lock is somewhat obscured by the way the zthread timer stuff works. The arc_adjust_cb_check() function is called from line 193 of contrib/opensolaris/uts/common/fs/zfs/zthr.c, and that's where you'll find the code that makes it clear this is an idiomatic condition variable pattern. -- Ian