Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp750781rwe; Wed, 31 Aug 2022 10:16:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR63auaVY8n3vTeEzlGItPPO1nrGEvh+rINqfpCVRNmmN7tI3kRiN8nAUVwfgMcY+477W4Fv X-Received: by 2002:a17:90b:2bca:b0:1fd:a06b:ef4f with SMTP id ru10-20020a17090b2bca00b001fda06bef4fmr4200711pjb.201.1661966216603; Wed, 31 Aug 2022 10:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661966216; cv=none; d=google.com; s=arc-20160816; b=OFRbq9lXZQgvtbBdRrHvMr//HB5XtnLluMSA2hE81O5ct3RB686vICV1Noe4I76NBG XcOfSw1x9308NlYOf2xGn/EDGdlSgUqYLdHlo1lHZvd73VuCnMYl3rSw9m+i2OflfBCN KgIH3qXCau4/qVPPu2tNxUB+7J10ILvvb6SQDQ8LENHfSZ5Ceg7T57l3aOtGeta+9TlU WU6+1nt4LD4xNuTcBKh+C8YaXO9yUy6vEYDeKJxQu70XzsC/gzr/mDQG3FveC6y44LH9 Lvsl+zQDK1oh1Kpjp7jga2P8pYTVkAQnlmTRRys7AOWaIekD7Iz1kbgtygFOCi6/XvdU +uiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c2TX4X9uyLpPzlBA8SkX7a5tu94KGH4Yf0CSb9a5La0=; b=0bWX+gSOd9MOUGxZBEUwguh0j7wRPLTRoZF2Rvfkw+nBQldECeneHYOkFQx1h73neS lveFk5G7T7eAvmQa9phoxJwZ7JoFm8DIDf5RzxkgEgYKLDLbrxutc5zrcXvkAfrIcusg h3+BhUzT73re4yrToZUelngywIB/lb8zvKZteq/B9S+6yq9IT3cngyToFG02v0YpxH9g 6CK8dExRj2Zm7QCK8U2ZO0hU63HMM1RVLTZ7oXiUpuyQ9BxLwVgaC7yO19gpNbfOZQtv r4821SNzPXxPxk/SEyKmlpzhRBaEsmZvrUwWd6cLfUw9rBi4SbAzmXldime5QJEsymRV cMeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=gzn7AV6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s70-20020a637749000000b0042a8ba84c20si5780733pgc.631.2022.08.31.10.16.36; Wed, 31 Aug 2022 10:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=gzn7AV6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231485AbiHaQqe (ORCPT + 99 others); Wed, 31 Aug 2022 12:46:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbiHaQqc (ORCPT ); Wed, 31 Aug 2022 12:46:32 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 625DCD7D12 for ; Wed, 31 Aug 2022 09:46:31 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id lx1so29534058ejb.12 for ; Wed, 31 Aug 2022 09:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=c2TX4X9uyLpPzlBA8SkX7a5tu94KGH4Yf0CSb9a5La0=; b=gzn7AV6FF8ujOWh5fibOQxp7+QWz/iVO85IAc9S1w2Fyk1mCJS4enw4JqKzLOSs+UZ eWCx4pEMlFzayH4gm9OTAvX/QrFRL82yJU/pwgkhb3ZH9lOW3S8lNN/eqA66J3AXbLgb 0HHQSO0x9uYB+FObn7BeiQQQUDiWW866y5StE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=c2TX4X9uyLpPzlBA8SkX7a5tu94KGH4Yf0CSb9a5La0=; b=ADuWkZ3WUgs/1pBzTZdF08QPrK758WJbnwy0ISFI9HHyyc+OesWZiMGUiXEvgJsd09 4Bh6REX0K3qjpXc5Z+nnLVnitTbR4WQYTbD18p13m1TRBEFpT3ksaxbdK8oMAjHIlzrU V4yyUDMZ9eD9jUS/mZQ2pH0CVpfsVCCtJ6z+hkTOor9Gmb+jxzZUdW/F1vrsys5oxyqo 3ZxzVWClwG4lMS06a6vNBlEw6wckrdERvWze4ub4Okk+W41zAOYiGr/4F8qyVHDcQHBT nXDgC3esGB3uYHskkgW6pJkW1zUkz1PL0SPk8sY5DS79mJxoeyeZhtnxQH8W+Xi0Ji2f 63QA== X-Gm-Message-State: ACgBeo3hSOsLBz56Hx9LOrlBwhYTkDVAEbf8q3svSwUVpdW5twvT20Pb G64u2mDlzADYNVTA85gUfFRMouBX6OCgl9+4 X-Received: by 2002:a17:906:8442:b0:73d:a2fc:a87 with SMTP id e2-20020a170906844200b0073da2fc0a87mr20657460ejy.625.1661964389362; Wed, 31 Aug 2022 09:46:29 -0700 (PDT) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com. [209.85.128.46]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b0073d71b7527asm7220942ejf.151.2022.08.31.09.46.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Aug 2022 09:46:28 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id k17so7677199wmr.2 for ; Wed, 31 Aug 2022 09:46:28 -0700 (PDT) X-Received: by 2002:a7b:c399:0:b0:3a5:f3fb:85e0 with SMTP id s25-20020a7bc399000000b003a5f3fb85e0mr2629152wmj.38.1661964388324; Wed, 31 Aug 2022 09:46:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Wed, 31 Aug 2022 09:46:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: d4252071b9: fxmark.ssd_ext4_no_jnl_DWTL_54_directio.works/sec -26.5% regression To: kernel test robot Cc: Mikulas Patocka , lkp@lists.01.org, lkp@intel.com, Matthew Wilcox , linux-kernel@vger.kernel.org, ying.huang@intel.com, feng.tang@intel.com, zhengjun.xing@linux.intel.com, fengwei.yin@intel.com, regressions@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 31, 2022 at 12:21 AM kernel test robot wrote: > > hi, pleased be noted that we read this patch and understand it as a fix, > also what we understand is, since the patch itself adds some memory barrier, > some regression in block IO area is kind of expected. Well, yes and no. It's a memory ordering fix, but the memory ordering part is one that should *not* have any actual impact on x86, because the addition of smp_mb__before_atomic() should be a total no-op, and "smp_load_acquire()" should only imply a compiler scheduling barrier. IOW, it most definitely shouldn't cause something like this: > FYI, we noticed a -26.5% regression of > fxmark.ssd_ext4_no_jnl_DWTL_54_directio.works/sec because at most it should have caused tiny perturbation of the instruction scheduling (obviously possibly register allocation, stack spill differences and and instruction choice). Except there was a change there that isn't just about memory ordering: > after more internal review, we still decided to report out to share our finding > in our tests, and for your information that how this patch could impact > performance in some cases. please let us know if you have any concern. Oh, it's absolutely interesting and unexpected. And I think the cause is obvious: our "set_buffer_uptodate()" *used* to use the BUFFER_FNS() macro, which does that bit setting conditionally. And while that isn't actually correct in an "atomic op" situation, it *is* fine in the case of set_buffer_uptodate(), since if the buffer was already uptodate, any other CPU looking at that bit will not be caring about what *this* CPU did. IOW, if this CPU sees the bit as having ever been uptodate before, then any barriers are irrelevant, because they are about the original setting of 'uptodate', not the new one. So I think we can just do this: --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -137,12 +137,14 @@ BUFFER_FNS(Defer_Completion, defer_completion) static __always_inline void set_buffer_uptodate(struct buffer_head *bh) { - /* - * make it consistent with folio_mark_uptodate - * pairs with smp_load_acquire in buffer_uptodate - */ - smp_mb__before_atomic(); - set_bit(BH_Uptodate, &bh->b_state); + if (!test_bit(BH_Uptodate, &bh->b_state)) { + /* + * make it consistent with folio_mark_uptodate + * pairs with smp_load_acquire in buffer_uptodate + */ + smp_mb__before_atomic(); + set_bit(BH_Uptodate, &bh->b_state); + } } static __always_inline void clear_buffer_uptodate(struct buffer_head *bh) and re-introduce the original code (maybe extend that comment to talk about this "only first up-to-date matters". HOWEVER. I'd love to hear if you have a clear profile change, and to see exactly which set_buffer_uptodate() is *so* important. Honestly, I didn't expect the buffer head functions to even really matter much any more, with pretty much all IO being about the page cache.. Linus