Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp597767pxk; Wed, 16 Sep 2020 11:48:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPu1h56D1HicUw0GwmxrXwXmZ0m+lXs3wQ53mV19e+Tb+Wfe4whp1iWQVfzRgTfrsHn048 X-Received: by 2002:a17:906:9604:: with SMTP id s4mr27875399ejx.182.1600282116987; Wed, 16 Sep 2020 11:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600282116; cv=none; d=google.com; s=arc-20160816; b=Gwo5YZd6S3SKlPYFVll3LF3acDpDxFPrV9DPrEVooPOxF4/ldNwnpRuJjT472+p8kl egFfVS5NkCNKtqpkKJGyScgoafee1cyVT3rpCR/aDQntPAuu/y469Hm0PYag5vogP6DR Wobli823V4ix4T0twFGqkBPN95tdDDRwYF6y9od1Tx4AQIymfHNH5MTreF0A0+fmaqhj ba1qZ3KtVU5IvkxV6xprDeufLod33IfcgbRX40akzeJw9jhOcUqECw8N7hBBtXNW7Pi9 87vc583843GQ7uoZUSChsRUdbV4Vv8tzat3qRYwQupGY9bKrpMbjy39G+WzLxf2JSRXr D9/Q== 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=FvU3RmnxF4Fi3PPUl/NAHaQ6sckA0cZltUifXE0sQUY=; b=gp//RJGDzWoyYE3yS75kfOo6P+1T07buhjGED91ahv5EOH5DEfZFPBiD5u4vQauXAj IF9tVDomJ6PzujMrclSmo9fKgFjjp2OFS7oFH/j5Yer3/h1j98GUgUBo2WY9Z0RBEKJl h6biX6My3ObpWH+105M7SDsi+D9xiYBLcchqYTdbt3zQf2nrzCOsADRs/9LBG+JifgX/ faQp7/BQ7y1S1A+B5n/63A5axhaSysB85tqOIwpAOl1kwElNO9d5J+bz3jdJqfTuy36u FSs8BoJm3HEOTygrZxGZH9njg684jD/Pgv37zoltHiNyh97lsd6WKjrV3MIWlu2zpO7v ww0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=AiGhVJYF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si13449225ejb.496.2020.09.16.11.48.05; Wed, 16 Sep 2020 11:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=AiGhVJYF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727871AbgIPSr6 (ORCPT + 99 others); Wed, 16 Sep 2020 14:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728248AbgIPSro (ORCPT ); Wed, 16 Sep 2020 14:47:44 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CB6C061756 for ; Wed, 16 Sep 2020 11:47:43 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id k25so6862331ljk.0 for ; Wed, 16 Sep 2020 11:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FvU3RmnxF4Fi3PPUl/NAHaQ6sckA0cZltUifXE0sQUY=; b=AiGhVJYFwlZ76nh2p80nDW5KlWkzhVstC+ekxJgSj3hh4Dl41ChGlQj+8UxI5F9Xc9 pKW8C5G/1nb+f2eUFPyOHFNx3MYZgioEwfLY2TkTz0uC4umYfzyb0loAbP9D1r4fVoeg jK8KF5sV9qMp0+hOp7K8kAkTBJPF+XELbvJLo= 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=FvU3RmnxF4Fi3PPUl/NAHaQ6sckA0cZltUifXE0sQUY=; b=naqKWfv4NpAlZiorxVt7EdVbaiPZp2YIK9VjRrWX2W2Mm4qxOP0x6/ZUkd/UEc1yDq hiHatAxHsU43bsfWc7Vf/VJBtFKyt6nu4U578UshjMIyUyIO66lvi39f8zflREH4NzRc K+mUC0J9et/o1Nq+Jql3rNsIgGQVeryEG6nsHFPVKnCKxraAZt2UnOkC1P/9GVPpqNkT T+Q8cpImUf2jODf5QSO5O5hiIznIzds8hyLfFIs5FMScqbC6cKegBX2gC8sc3ZiztEy0 +WKYJST/rczwKr+005rPpOm9AzEjiQQAwRx+CZ/xo1pSslPSl0umGeJV9rNs6F0g+IqX PAgg== X-Gm-Message-State: AOAM530mASC0mC5rtAqYYo5g259rMq86KionbnqPOoVj3fK8AdhLujAT AzBSLq2c8DzKSsHfxYxVy3NGUvO4667bBQ== X-Received: by 2002:a05:651c:1064:: with SMTP id y4mr8199421ljm.107.1600282061172; Wed, 16 Sep 2020 11:47:41 -0700 (PDT) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com. [209.85.167.44]) by smtp.gmail.com with ESMTPSA id b20sm5119927lfg.57.2020.09.16.11.47.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Sep 2020 11:47:39 -0700 (PDT) Received: by mail-lf1-f44.google.com with SMTP id w11so8128214lfn.2 for ; Wed, 16 Sep 2020 11:47:38 -0700 (PDT) X-Received: by 2002:a19:4186:: with SMTP id o128mr7813977lfa.148.1600282058590; Wed, 16 Sep 2020 11:47:38 -0700 (PDT) MIME-Version: 1.0 References: <9550725a-2d3f-fa35-1410-cae912e128b9@tessares.net> <37989469-f88c-199b-d779-ed41bc65fe56@tessares.net> <20200916103446.GB3607@quack2.suse.cz> In-Reply-To: <20200916103446.GB3607@quack2.suse.cz> From: Linus Torvalds Date: Wed, 16 Sep 2020 11:47:22 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Kernel Benchmarking To: Jan Kara Cc: Matthieu Baerts , Michael Larabel , Matthew Wilcox , Amir Goldstein , "Ted Ts'o" , Andreas Dilger , Ext4 Developers List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Sep 16, 2020 at 3:34 AM Jan Kara wrote: > > wait_on_page_bit_common() has: > > spin_lock_irq(&q->lock); > SetPageWaiters(page); > if (!trylock_page_bit_common(page, bit_nr, wait)) > - which expands to: > ( > if (wait->flags & WQ_FLAG_EXCLUSIVE) { > if (test_and_set_bit(bit_nr, &page->flags)) > return false; > } else if (test_bit(bit_nr, &page->flags)) > return false; > ) > > __add_wait_queue_entry_tail(q, wait); > spin_unlock_irq(&q->lock); > > Now the suspicious thing is the ordering here. What prevents the compiler > (or the CPU for that matter) from reordering SetPageWaiters() call behind > the __add_wait_queue_entry_tail() call? I know SetPageWaiters() and > test_and_set_bit() operate on the same long but is it really guaranteed > something doesn't reorder these? I agree that we might want to make this much more specific, but no, those things can't be re-ordered. Part of it is very much that memory ordering is only about two different locations - accessing the *same* location is always ordered, even on weakly ordered CPU's. And the compiler can't re-order them either, we very much make test_and_set_bit() have the proper barriers. We'd be very screwed if a "set_bit()" could pass a "test_and_set_bit". That said, the PageWaiters bit is obviously very much by design in the same word as the bit we're testing and setting - because the whole point is that we can then at clear time check the PageWaiters bit atomically with the bit we're clearing. So this code optimally shouldn't use separate operations for those bits at all. It would be better to just have one atomic sequence with a cmpxchg that does both at the same time. So I agree that sequence isn't wonderful. But no, I don't think this is the bug. And as you mention, Matthieu sees it on UP, so memory ordering wouldn't have been an issue anyway (and compiler re-ordering would cause all kinds of other problems and break our bit operations entirely). Plus if it was some subtle bug like that, it wouldn't trigger as consistently as it apparently does for Matthieu. Of course, the reason that I don't see how it can trigger at all (I still like my ABBA deadlock scenario, but I don't see anybody holding any crossing locks in Matthieu's list of processes) means that I'm clearly missing something Linus