From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 24 11:57:35 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 55814FF3 for ; Sun, 24 Aug 2014 11:57:35 +0000 (UTC) Received: from mail-wi0-x231.google.com (mail-wi0-x231.google.com [IPv6:2a00:1450:400c:c05::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E393C3545 for ; Sun, 24 Aug 2014 11:57:34 +0000 (UTC) Received: by mail-wi0-f177.google.com with SMTP id ho1so1385031wib.16 for ; Sun, 24 Aug 2014 04:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; bh=7DAcNSmd4Byycelh9qQit5I0/8r+EnCIQyLWn4h1lJc=; b=LEo7P+8nZjQMc9uYx2ZIV6PXKWoL0XfCpBgDlpYe0mEbgAg7v954q2wpk6nLZ7MvP9 axwqBwvv+8n3LIN0slL1Fk5rUL5Og1LL8uJ6sssWBbg7v1hBwfE9/dkA3rEpgBYUvJUV Zx9UqDpCOvfpFq4Ds7Z8+l7e5Zb4x8/K19n3RqA5nF6hSLIKIzosPvNRnkR5XPtMk6QN OyTLPw5fpTLAjiurPRtsRyCbaGbzVIDXEzRp/iAuMgIJevPtGlWSU2Txhp1RKUFfaVV7 OIfEmpF8eWkJYmJFw3jPlUZ+41vt/qT08VE/SUWmnoFUDkZHRmBixcuCQ2cqP766odpD w5cg== X-Received: by 10.194.203.73 with SMTP id ko9mr1505470wjc.101.1408881452659; Sun, 24 Aug 2014 04:57:32 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id g1sm14338807wiy.16.2014.08.24.04.57.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 24 Aug 2014 04:57:31 -0700 (PDT) Date: Sun, 24 Aug 2014 13:57:29 +0200 From: Mateusz Guzik To: freebsd-hackers@freebsd.org Subject: atomic_load_acq_int in sequential_heuristic Message-ID: <20140824115729.GC2045@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Aug 2014 11:57:35 -0000 Writer side is: fp->f_seqcount = (arg + bsize - 1) / bsize; do { new = old = fp->f_flag; new |= FRDAHEAD; } while (!atomic_cmpset_rel_int(&fp->f_flag, old, new)); Reader side is: if (atomic_load_acq_int(&(fp->f_flag)) & FRDAHEAD) return (fp->f_seqcount << IO_SEQSHIFT); We can easily get the following despite load_acq: CPU0 CPU1 load_acq fp->f_flag fp->f_seqcount = ... store_rel fp->f_flag read fp->f_seqcount So the barrier does not seem to serve any purpose. Given that this is only a hint and rarely changes it should be fine. So how about the following: diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index f1d19ac..2e056de 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -438,7 +438,7 @@ static int sequential_heuristic(struct uio *uio, struct file *fp) { - if (atomic_load_acq_int(&(fp->f_flag)) & FRDAHEAD) + if (fp->f_flag & FRDAHEAD) return (fp->f_seqcount << IO_SEQSHIFT); /* I make no claims about any performance difference in this one. This is only a cleanup. -- Mateusz Guzik