Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp221173rwi; Sun, 30 Oct 2022 23:43:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MVM+zfaLFzF8hcj1bhzht07UkLQ55d6ByDZeE9qSAbXdwsYv3h1PrCaz4DTmrbLIFFJ8J X-Received: by 2002:a17:90b:3141:b0:20d:49d6:30c with SMTP id ip1-20020a17090b314100b0020d49d6030cmr12886520pjb.175.1667198586151; Sun, 30 Oct 2022 23:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667198586; cv=none; d=google.com; s=arc-20160816; b=ok83CJsbwEeYhxzZMud5Xb+xzMYRO86T80M+NCthvp5qc742YTlVd8V0ssNcK9XEa8 THZv/VegZR9L82wZWOdhbuGhjEyeOTz1yniQj68vz0cPepcYzSpsMUn6msBknouoNPSQ O2GrBk73nk+pGVRgVgX8gQoRrWR7SGAVANQnZS7QRsS6EbVVo8DF7k70Ka2pS9XjFiUC fXwfhldm0BF66yghgyCXjnRTr5nvOc3RhMx+kJjP0dw6yXW+/mV2HpHSL4Q5sH5YkGQ6 qPqbc3Z9hnSapu2NbXjkh8Wn87VfVahvo71V/xKi4KD6AGbmIsGUfOPZEK1DjyHnL8KZ Nmyw== 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:references :in-reply-to:mime-version:dkim-signature; bh=WLYM+oLWKnllICHQ+zLBfeC2ltRzs9SonYVNyoAgoqY=; b=oJ+kJigo1WMsexhv/n93EDGqaF2p+Xai/Fw6GUJUhspN46thJoHVTgpScWVHNaavIU bzei8SzQt856t2t7jyZtbbq5SDEJLDV7rvVj8nULJO5gowBma0xJAdUF2O6fAMZp77Vf Q/P6rZShWc8lm2EqSriHUYAsd4GqSBNQwVChEuUErQUxiah43oqFePM2cbXwAReBBkZI 35cQY16zXoTZuwo0IR4LuKZhl2EiNIjHq3urcCl4GMZCfURjgN+rkw+SR28BFOd+K3S1 pI4CnXOSODEjPPRwu3x9JQtPEfUSMeMBF6O9ubCZTRNWOBcbbmi/Umm0IkpSnJKMcHCb 59mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AwcaUC6G; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o33-20020a635a21000000b0046b0e168af0si8025929pgb.597.2022.10.30.23.42.53; Sun, 30 Oct 2022 23:43:06 -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=@kernel.org header.s=k20201202 header.b=AwcaUC6G; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbiJaGb7 (ORCPT + 99 others); Mon, 31 Oct 2022 02:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiJaGb5 (ORCPT ); Mon, 31 Oct 2022 02:31:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2172A7652; Sun, 30 Oct 2022 23:31:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A396EB8112D; Mon, 31 Oct 2022 06:31:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5611DC433D7; Mon, 31 Oct 2022 06:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667197914; bh=WMgot3r3lmIGWk8l/1uUXf340754ZrT4DVOXSAzPkY4=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=AwcaUC6GrQ/oLpwR4UQRmwFS+JjGMMjs1d1aI11H8Ff1OSfxuaI77glJG1ChBWUQ9 yqptdMwauC4bstCap1l3DYqgZTiAR+c3WHPBdiUsbImRI8B0kEQi8w8SQR910VWrY5 Yr0gvicOfeDk5LYLao5/0G7Yq+izPqS7X286jV6OFZIU6vB+QKgtoi6VUCybOTY95F e7OaH9of+VyBRr8myDdRUkZGMkK85FC1Fp1T7g4UkSe9BOpoQAC4rHlc9a3bP6sgj6 zlU3L62/JLo4iYJz2RYAWhqMzC+M2k4L3ZH+8qV2WSzO+PAKBEukfMqDUDR/dIGCy6 iOZYrW6y+fX9g== Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-13c569e5ff5so12157394fac.6; Sun, 30 Oct 2022 23:31:54 -0700 (PDT) X-Gm-Message-State: ACrzQf34Y6ukQyq1tHRgo4sA5yNRRcSQBeBK1s484DyULRkO07ijy2t4 8M7GcOwWuIQqG/YHqUMKJ3EUdmNcvGE+Qgpgj7A= X-Received: by 2002:a05:6871:58b:b0:13c:be46:a02 with SMTP id u11-20020a056871058b00b0013cbe460a02mr5070202oan.8.1667197913541; Sun, 30 Oct 2022 23:31:53 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6839:1a4e:0:0:0:0 with HTTP; Sun, 30 Oct 2022 23:31:53 -0700 (PDT) In-Reply-To: <014c01d8ecf0$6e74bc80$4b5e3580$@samsung.com> References: <014c01d8ecf0$6e74bc80$4b5e3580$@samsung.com> From: Namjae Jeon Date: Mon, 31 Oct 2022 15:31:53 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] exfat: hint the empty entry which at the end of cluster chain To: Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Add missing Cc: Yuezhang Mo. 2022-10-31 15:17 GMT+09:00, Sungjong Seo : > Hi, Yuezhang Mo, > >> After traversing all directory entries, hint the empty directory >> entry no matter whether or not there are enough empty directory >> entries. >> >> After this commit, hint the empty directory entries like this: >> >> 1. Hint the deleted directory entries if enough; >> 2. Hint the deleted and unused directory entries which at the >> end of the cluster chain no matter whether enough or not(Add >> by this commit); >> 3. If no any empty directory entries, hint the empty directory >> entries in the new cluster(Add by this commit). >> >> This avoids repeated traversal of directory entries, reduces CPU >> usage, and improves the performance of creating files and >> directories(especially on low-performance CPUs). >> >> Test create 5000 files in a class 4 SD card on imx6q-sabrelite >> with: >> >> for ((i=0;i<5;i++)); do >> sync >> time (for ((j=1;j<=1000;j++)); do touch file$((i*1000+j)); done) >> done >> >> The more files, the more performance improvements. >> >> Before After Improvement >> 1~1000 25.360s 22.168s 14.40% >> 1001~2000 38.242s 28.72ss 33.15% >> 2001~3000 49.134s 35.037s 40.23% >> 3001~4000 62.042s 41.624s 49.05% >> 4001~5000 73.629s 46.772s 57.42% >> >> Signed-off-by: Yuezhang Mo >> Reviewed-by: Andy Wu >> Reviewed-by: Aoyama Wataru >> --- >> fs/exfat/dir.c | 26 ++++++++++++++++++++++---- >> fs/exfat/namei.c | 22 ++++++++++++++-------- >> 2 files changed, 36 insertions(+), 12 deletions(-) >> >> diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c >> index a569f285f4fd..7600f3521246 100644 >> --- a/fs/exfat/dir.c >> +++ b/fs/exfat/dir.c >> @@ -936,18 +936,25 @@ struct exfat_entry_set_cache >> *exfat_get_dentry_set(struct super_block *sb, >> >> static inline void exfat_hint_empty_entry(struct exfat_inode_info *ei, >> struct exfat_hint_femp *candi_empty, struct exfat_chain *clu, >> - int dentry, int num_entries) >> + int dentry, int num_entries, int entry_type) >> { >> if (ei->hint_femp.eidx == EXFAT_HINT_NONE || >> ei->hint_femp.count < num_entries || >> ei->hint_femp.eidx > dentry) { >> + int total_entries = EXFAT_B_TO_DEN(i_size_read(&ei- >> >vfs_inode)); >> + >> if (candi_empty->count == 0) { >> candi_empty->cur = *clu; >> candi_empty->eidx = dentry; >> } >> >> - candi_empty->count++; >> - if (candi_empty->count == num_entries) >> + if (entry_type == TYPE_UNUSED) >> + candi_empty->count += total_entries - dentry; > > This seems like a very good approach. Perhaps the key fix that improved > performance seems to be the handling of cases where empty space was not > found and ended with TYPE_UNUSED. > > However, there are concerns about trusting and using the number of free > entries after TYPE_UNUSED calculated based on directory size. This is > because, unlike exFAT Spec., in the real world, unexpected TYPE_UNUSED > entries may exist. :( > That's why exfat_search_empty_slot() checks if there is any valid entry > after TYPE_UNUSED. In my experience, they can be caused by a wrong FS > driver > and H/W defects, and the probability of occurrence is not low. > > Therefore, when the lookup ends with TYPE_UNUSED, if there are no empty > entries found yet, it would be better to set the last empty entry to > hint_femp.eidx and set hint_femp.count to 0. > If so, even if the lookup ends with TYPE_UNUSED, exfat_search_empty_slot() > can start searching from the position of the last empty entry and check > whether there are actually empty entries as many as the required > num_entries as now. > > what do you think? > >> + else >> + candi_empty->count++; >> + >> + if (candi_empty->count == num_entries || >> + candi_empty->count + candi_empty->eidx == total_entries) >> ei->hint_femp = *candi_empty; >> } >> } > [snip] >> -- >> 2.25.1 > >