Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18205246rwd; Tue, 27 Jun 2023 13:18:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7C3d0nbii9hAB6tmW8Z1ADZIH+znRctFktbKdH7C2Yk/+TAWX7xUi7NBY3rtRa+j48yjSK X-Received: by 2002:a17:90a:d917:b0:262:ec12:7c40 with SMTP id c23-20020a17090ad91700b00262ec127c40mr9848860pjv.11.1687897106261; Tue, 27 Jun 2023 13:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687897106; cv=none; d=google.com; s=arc-20160816; b=CfIu2at5oREzXaoliainjhcmXLwXyGFIRI+q2CHKvUXO2x4+mJdCBoen/iJyTALorC 1xrsqjIVGLABiwUi46g0X+RCbFj1XtUNQEBcxU2nJgNCQwnOkdQHBsaev2yFQ5x6CPAW ZIU5EfugJNb2EuRee9kWLlSw9pWLYecmTZeWCoM96TzL9iJ6QGC4KWKf7QToF4BVi5JM uTdNj9/jgUPe0xun28CNKYy+IqW/b8jJvm1WDJ/zDzR39T1qX7lZg9i4k1BSO/t992Yj zlGSokyautyr0glW6e2W9c1Axc8kpbJS7C7qCXHiIsGVHyNpCukNNw7D20AvX3LDWzha eCfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o49YVz6zjhepi8Xmg4g4xUo0hw9c73jq1r9IaIy9q2o=; fh=Nv6u2UDaNMZDGhBlz/PRCPhLOeojJ2Ub0TXNE8ax4yQ=; b=jNE+6UTNXTONuMOmGffesvGniZty+wTH2WGmLzRt3+8JzAH7+sm5hHxC4LCsLf4X0L ONQf1aZSzraLiljMRUiuu+CRvdJQ3w9OXt/LRqIITkB/RUXce4ex/JADWeb0mafjuemQ owRMtmCqF5zOi6+nJJ7vqEfRg5oyOiJx8yCplij7SIBDDgK7+uMEj13Pk5oV911fHYmo GT6yTMw4eK7NXEi2iapp8W1afsGD7DVSzeV/GdHIP6/W6DPjr8MmeGe9+JvYiKMCzQmZ rzfH2bWVDlQ4EZjsQwb8+PYudqNVS6DfvNt/rZYEYizgJWA6DoFZuwfeZpWre7wU1tnn z4Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jSVyFpWK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a17090aa00400b00253160141c7si10048825pjp.83.2023.06.27.13.18.10; Tue, 27 Jun 2023 13:18:26 -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=@redhat.com header.s=mimecast20190719 header.b=jSVyFpWK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbjF0UJb (ORCPT + 99 others); Tue, 27 Jun 2023 16:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjF0UJ2 (ORCPT ); Tue, 27 Jun 2023 16:09:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6E61B2 for ; Tue, 27 Jun 2023 13:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687896519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=o49YVz6zjhepi8Xmg4g4xUo0hw9c73jq1r9IaIy9q2o=; b=jSVyFpWKTaVWTd96CvFWrfYMjYPezEVc+DOitauzAmlXUJNQHvneS5XAlTH1HQNqh4Mypz weRwDmPkqgRp2oupDkLhH0Q+i7DUXvmW7mUBjwgkPPl/gJnXEj0UxnfmshQ5oU0m+xHhuo mpyWuC0NBsb5+lui53NZQab0KWeM7k8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-L8xX7TwjMq6D_ynhzpfbgQ-1; Tue, 27 Jun 2023 16:08:37 -0400 X-MC-Unique: L8xX7TwjMq6D_ynhzpfbgQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBAC8104D51F; Tue, 27 Jun 2023 20:08:35 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B16340C6F5A; Tue, 27 Jun 2023 20:08:35 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id CC6B8400E5693; Tue, 27 Jun 2023 14:53:52 -0300 (-03) Date: Tue, 27 Jun 2023 14:53:52 -0300 From: Marcelo Tosatti To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexander Viro , Christian Brauner , Christoph Hellwig , Jens Axboe , Frederic Weisbecker , Dave Chinner , Valentin Schneider , Leonardo Bras , Yair Podemsky , P J P Subject: Re: [PATCH] fs/buffer.c: remove per-CPU buffer_head lookup cache Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, Jun 26, 2023 at 07:47:42PM +0100, Matthew Wilcox wrote: > On Mon, Jun 26, 2023 at 03:04:53PM -0300, Marcelo Tosatti wrote: > > Upon closer investigation, it was found that in current codebase, lookup_bh_lru > > is slower than __find_get_block_slow: > > > > 114 ns per __find_get_block > > 68 ns per __find_get_block_slow > > > > So remove the per-CPU buffer_head caching. > > LOL. That's amazing. I can't even see why it's so expensive. The > local_irq_disable(), perhaps? Your test case is the best possible > one for lookup_bh_lru() where you're not even doing the copy. Oops, that was due to incorrect buffer size being looked up versus installed size. About 15ns is due to irq disablement. 6ns due to checking preempt is disabled (from __this_cpu_read). So the actual numbers for the single block lookup are (searching for the same block number repeatedly): 42 ns per __find_get_block 68 ns per __find_get_block_slow And increases linearly as the test increases the number of blocks which are searched for: say mod 3 is __find_get_block(blocknr=1) __find_get_block(blocknr=2) __find_get_block(blocknr=3) 41 ns per __find_get_block mod=1 41 ns per __find_get_block mod=2 42 ns per __find_get_block mod=3 43 ns per __find_get_block mod=4 45 ns per __find_get_block mod=5 48 ns per __find_get_block mod=6 48 ns per __find_get_block mod=7 49 ns per __find_get_block mod=8 51 ns per __find_get_block mod=9 52 ns per __find_get_block mod=10 54 ns per __find_get_block mod=11 56 ns per __find_get_block mod=12 58 ns per __find_get_block mod=13 60 ns per __find_get_block mod=14 61 ns per __find_get_block mod=15 63 ns per __find_get_block mod=16 138 ns per __find_get_block mod=17 138 ns per __find_get_block mod=18 138 ns per __find_get_block mod=19 <-- results from first patch, when lookup_bh_lru is a miss 70 ns per __find_get_block_slow mod=1 71 ns per __find_get_block_slow mod=2 71 ns per __find_get_block_slow mod=3 71 ns per __find_get_block_slow mod=4 71 ns per __find_get_block_slow mod=5 72 ns per __find_get_block_slow mod=6 71 ns per __find_get_block_slow mod=7 72 ns per __find_get_block_slow mod=8 71 ns per __find_get_block_slow mod=9 71 ns per __find_get_block_slow mod=10 71 ns per __find_get_block_slow mod=11 71 ns per __find_get_block_slow mod=12 71 ns per __find_get_block_slow mod=13 71 ns per __find_get_block_slow mod=14 71 ns per __find_get_block_slow mod=15 71 ns per __find_get_block_slow mod=16 71 ns per __find_get_block_slow mod=17 72 ns per __find_get_block_slow mod=18 72 ns per __find_get_block_slow mod=19 ls on home directory: hits: 2 misses: 91 find on a linux-2.6 git tree: hits: 25453 misses: 51084 make clean on a linux-2.6 git tree: hits: 247615 misses: 32855 make on a linux-2.6 git tree: hits: 1410414 misses: 166896 In more detail, where each bucket below indicates which index into per-CPU buffer lookup_bh_lru was found: hits idx1 idx2 ... idx16 hits 139506 24299 21597 7462 15790 19108 6477 1349 1237 938 845 636 637 523 431 454 misses: 65773 So i think it makes more sense to just disable the cache for isolated CPUs. > Reviewed-by: Matthew Wilcox (oracle) Thanks.