Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13230425rwd; Fri, 23 Jun 2023 18:44:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6v9b+6ucx/yCGa1mMO3rpCYpDjMhG2WQ3tzWNb/D0OnM/zdC7B5wpsHhjo4DxG2jjhYDfV X-Received: by 2002:a05:6870:8c15:b0:19f:3c91:db71 with SMTP id ec21-20020a0568708c1500b0019f3c91db71mr12187706oab.7.1687571089005; Fri, 23 Jun 2023 18:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687571088; cv=none; d=google.com; s=arc-20160816; b=t0b8ssbzL/zynY630KHPiN4XvJ/jekp7AT7De1iL1bcsMg7W1cYSgEz7j22PjD9rXS Axz8QUQHYNLbXg93vplwYvWW7axd07UYJZOfBDTTB2XC4kBOHd8ALH/Pwc2Jm6dBHJWB EUruVTzLkQGSdAhncwyp011+u/7BN0yEdAAP7/zL3csz85WnyHLlfmaCC4rGJx3aq+aG iJzYw1zculN/5q7tCBdQBvxNMfVIAd97Zn1i3pr4wpXZxQw8P7MgQF2DkVQh3LJBibtO QflU7cXiI6HiDebWZoO175ael3Y/JTxV17p0ukz7wvxI3T7dBYOIh2LEmtKIOCeAhQov //uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=hhnrw4H8sVcNqTmP9yuf4/t4QYGO1txYgX4lELB3n9s=; fh=LN74zx3AY3iPURcX/gbnxUJ5zQnAXMeutfuiPp3fK0Y=; b=0aRp3+BzdsNeHFVkGNLljIcC7Ve43C/vQso+vsE5naegE4R8W1vyt1dVTs1t7w3pT5 J74u7MwfRMYyrWHFWa+2gQKRXl7k9gmH1Br6p2dh10YM1CN4GoNdYHj/vVDzu5WZOffI CSle+xdJEUUJ+yAYmm7pzESs5QmqoU42UBqjGAde4S3Yz5QpqzqkbKbq04wx5V1f+OOZ +e1ctmN+LQsB+aiuP9G5vtSCmOTLCYcq+hjoPwXakfrzviiyQz3smqgw7Yqlxpgz4Jmw 48dyicV7fKbbLDG0qrIa2IYqi/X9JtytscmoUqvXxASALyLFxI/yGOoOuNEtuum/KAtH RUrw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x34-20020a634a22000000b00553d904c946si579785pga.514.2023.06.23.18.44.37; Fri, 23 Jun 2023 18:44:48 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjFXBcF (ORCPT + 99 others); Fri, 23 Jun 2023 21:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjFXBcE (ORCPT ); Fri, 23 Jun 2023 21:32:04 -0400 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C5A7213A for ; Fri, 23 Jun 2023 18:32:02 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VlnYVQs_1687570316; Received: from 172.20.10.2(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VlnYVQs_1687570316) by smtp.aliyun-inc.com; Sat, 24 Jun 2023 09:31:58 +0800 Message-ID: <8573c838-bb88-83c1-4680-3cc500586e02@linux.alibaba.com> Date: Sat, 24 Jun 2023 09:31:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [RFC 0/2] erofs: introduce bloom filter for xattr To: Alexander Larsson Cc: hsiangkao@linux.alibaba.com, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20230621083209.116024-1-jefflexu@linux.alibaba.com> <3730215c-d59d-8b8e-fe36-7754f7782d15@linux.alibaba.com> Content-Language: en-US From: Jingbo Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 6/22/23 3:56 PM, Alexander Larsson wrote: > On Thu, Jun 22, 2023 at 8:37 AM Jingbo Xu wrote: >> >> >> >> On 6/21/23 7:50 PM, Alexander Larsson wrote: >>> On Wed, Jun 21, 2023 at 10:32 AM Jingbo Xu wrote: >>>> >>>> Background >>>> ========== >>>> Filesystems with ACL enabled generally need to read >>>> "system.posix_acl_access"/"system.posix_acl_default" xattr to get the >>>> access and default ACL. When filesystem is mounted with ACL enabled >>>> while files in the system have not set access/default ACL, the getattr() >>>> will run in vain while the round trip can decrease the performance in >>>> workload like "ls -lR". >>>> >>>> For example, there's a 12% performance boost if erofs is mounted with >>>> "noacl" when running "ls -lR" workload on dataset [1] (given in [2]). >>>> >>>> We'd better offer a fastpath to boost the above workload, as well as >>>> other negative xattr lookup. >>>> >>>> >>>> Proposal >>>> ======== >>>> Introduce a per-inode bloom filter for xattrs to boost the negative >>>> xattr queries. >>>> >>>> As following shows, a 32-bit bloom filter is introduced for each inode, >>>> describing if a xattr with specific name exists on this inode. >>>> >>>> ``` >>>> struct erofs_xattr_ibody_header { >>>> - __le32 h_reserved; >>>> + __le32 h_map; /* bloom filter */ >>>> ... >>>> } >>>> ``` >>>> >>>> Following are some implementation details for bloom filter. >>>> >>>> 1. Reverse bit value >>>> -------------------- >>>> The bloom filter structure describes if a given data is inside the set. >>>> It will map the given data into several bits of the bloom filter map. >>>> The data must not exist inside the set if any mapped bit is 0, while the >>>> data may be not inside the set even if all mapped bits is 1. >>>> >>>> While in our use case, as erofs_xattr_ibody_header.h_map is previously a >>>> (all zero) reserved field, the bit value for the bloom filter has a >>>> reverse semantics in consideration for compatibility. That is, for a >>>> given data, the mapped bits will be cleared to 0. Thus for a previously >>>> built image without support for bloom filter, the bloom filter is all >>>> zero and when it's mounted by the new kernel with support for bloom >>>> filter, it can not determine if the queried xattr exists on the inode and >>>> thus will fallback to the original routine of iterating all on-disk >>>> xattrs to determine if the queried xattr exists. >>>> >>>> >>>> 2. The number of hash functions >>>> ------------------------------- >>>> The optimal value for the number of the hash functions (k) is (ln2 * >>>> m/n), where m stands the number of bits of the bloom filter map, while n >>>> stands the number of all candidates may be inside the set. >>>> >>>> In our use case, the number of common used xattr (n) is approximately 8, >>>> including system.[posix_acl_access|posix_acl_default], >>>> security.[capability|selinux] and >>>> security.[SMACK64|SMACK64TRANSMUTE|SMACK64EXEC|SMACK64MMAP]. >>>> >>>> Given the number of bits of the bloom filter (m) is 32, the optimal value >>>> for the number of the hash functions (k) is 2 (ln2 * m/n = 2.7). >>> >>> This is indeed the optimal value in a traditional use of bloom >>> filters. However, I think it is based on a much larger set of values. >>> For this usecase it may be better to choose a different value. >>> >>> I did some research a while ago on this, and I thought about the >>> counts too. Having more than one hash function is useful because it >>> allows you to avoid problems if two values happen to hash to the same >>> bucket, but this happens at the cost of there being less "unique >>> buckets". I spent some time looking for common xattr values >>> (including some from userspace) and ended up with a list of about 30. >> >> Yeah, if the number of common used xattr (n) is 30, then the optimal >> value for the number of the hash functions (k) is 1 (ln2 * m/n = 0.74). >> The optimal value in theory also matches our intuition. >> >> >>> If we can choose a single hash function that maps all (or most) of >>> these to a unique bucket (mod 32), >> >> Excellent research! Would you mind sharing the list of these >> approximately 30 commonly used xattrs, so that I could check if they are >> mapped to unique bucket with the single hash function we proposed? > > This is the list I came up with: > > trusted.overlay.opaque > trusted.overlay.redirect > trusted.overlay.origin > trusted.overlay.impure > trusted.overlay.nlink > trusted.overlay.upper > trusted.overlay.metacopy > trusted.overlay.protattr > user.overlay.opaque > user.overlay.redirect > user.overlay.origin > user.overlay.impure > user.overlay.nlink > user.overlay.upper > user.overlay.metacopy > user.overlay.protattr > security.evm > security.ima > security.selinux > security.SMACK64 > security.SMACK64IPIN > security.SMACK64IPOUT > security.SMACK64EXEC > security.SMACK64TRANSMUTE > security.SMACK64MMAP > security.apparmor > security.capability > system.posix_acl_access > system.posix_acl_default > user.mime_type > Got it. Thanks a lot! -- Thanks, Jingbo