From patchwork Wed Nov 2 07:11:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 14047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3456719wru; Wed, 2 Nov 2022 00:19:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5w4A0g1pixIFt378nogZfnD+fLzLigOE0FuxWQ3Az6xiGj9Ugloq4HxPeqEzEiZ3i/rYUv X-Received: by 2002:a17:907:7e9a:b0:796:7a21:1520 with SMTP id qb26-20020a1709077e9a00b007967a211520mr22451155ejc.236.1667373584609; Wed, 02 Nov 2022 00:19:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667373584; cv=pass; d=google.com; s=arc-20160816; b=z08W4Dj4n6ttESUNhUpeVzFQPU9embIbNXg/HI2bttM3igk//tV9dLBJe7i/2LY3iM 8taUqC+koCv4bsWZblzT/Ays4BllmQ5tLiB2UXrQMKBhcAWfuQEMXCmH8x8YIUVNUMpf yGYyKnMQPVTfXRqstI9ulZqP9wFbeoQNMrCzq69iba/xb8+LPEY/S+eVIFy+Kxv7hXCK cO6o5rS10ND28QyATthI+DF5kPsb55CMm0e3MWlgbXmxSaOO78zWyZt/eJbc8CxDLdd2 yW900bh74oi4taO45QLIFL6eqDUmcoYAb/AzB+Qa26hHje7RuatXBemTy22HHo4JjWyi 6pcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=l2uHTGsMyHlxbrdJ3Hhgv0YxmRF9V6gTmaJe9uNYoxU=; b=wA8R5OCEpBowq3+uan4IOzoyzVyR65RNeVheiq2vPRMETpFGhEFPTipUDY9j4bi0RG xlHIZYn6mRsJZITGAabKk/LcAlGDgmfahIXFQmBAwWdIgrw+r1di3IKIuW3+8oqhH93Q L8WLjjjIoKPbnFLBvXDmwig61pBQ9EdPUq6vUchpjPfZxov7s2CBlhyS+SWjdEZM3TKO iKU+fai24qYfwkDAe35wAxqMmmJZ/4WxWcnAAomr5uGizPfoxGS9FJgy1B5lJO3eR4V7 VA8AISKeKHUbsLe5biGYF5d4bJ0Eom6Q3uBAf01tEDCkMmq7ISEBYY3k3SVn1nkAdxD6 LtVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sony.com header.s=S1 header.b=DvrIpn5v; arc=pass (i=1 spf=pass spfdomain=sony.com dkim=pass dkdomain=sony.com dmarc=pass fromdomain=sony.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=pass (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a1709065d1000b007adadfc97c7si13874643ejt.918.2022.11.02.00.19.20; Wed, 02 Nov 2022 00:19:44 -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=@sony.com header.s=S1 header.b=DvrIpn5v; arc=pass (i=1 spf=pass spfdomain=sony.com dkim=pass dkdomain=sony.com dmarc=pass fromdomain=sony.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=pass (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230271AbiKBHLq (ORCPT + 99 others); Wed, 2 Nov 2022 03:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiKBHLh (ORCPT ); Wed, 2 Nov 2022 03:11:37 -0400 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D6E3186FE; Wed, 2 Nov 2022 00:11:35 -0700 (PDT) Received: from pps.filterd (m0209323.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A22tocg015311; Wed, 2 Nov 2022 07:11:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=S1; bh=l2uHTGsMyHlxbrdJ3Hhgv0YxmRF9V6gTmaJe9uNYoxU=; b=DvrIpn5vblQNX7pQ/RZ1lJ+J0E9YaWCok+kkKZ+dmSXn9aA0LMyLzMoW/VH2/1kJnhlE sbOOzXMFaLT0RcFS1Qjnm84rkjbN7vlrzJnJF22+Evegbw9PMp4ca3Mc3e4tQQiDt/0L pTTKm28lrZYyKDClsVVRZAuKhAQLZWjutFPhUVKiUwVvBXhQRjd265TVaxBvga7iAwrX NQmh2Uu+krN43prIo2GApQB6h1weNlxe2MMjiLX7nSVNT79ahS6RbbnZwto9zHd0cMhc hd2YcCvAF/InB1ULmLEG6jkuIIi+Tg0RLfLYZjVcDHK13nvBNCA7V5RQA/466D/LoqA4 kg== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2044.outbound.protection.outlook.com [104.47.26.44]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3kjhf8j0dc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Nov 2022 07:11:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AD0+Fd02S9auKkzSpn/k08/zrmWTsYzozucjodDQIYUZhL/61Au9K7QukpsMqQqu4QdlyvyVU1zvRTfV5q0A01K49Xg3X6N/4U4+JKQbn6mL0n7BfxEm7NphShHnUp6UsUxuJfvpdtiCzcbt3oCyvkonWLFMMjez5BiF8+1LpVhKMHiHIE5HwgVinRUEXNED9L3YK/ywGm014fx85vZO+tPGiYW6Zf9vmu4viqBvd4hTBVIwDCZo1DW92zvITPf83W2kilr0XeyFVvYankyAgzmc03WykA8v6bANb1qeA+5/syt4Ku0Xy27p1DVZEScpk/Mek34Jc9Vls++rNH4r7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l2uHTGsMyHlxbrdJ3Hhgv0YxmRF9V6gTmaJe9uNYoxU=; b=A6VJ4uEXm57uCmXHYmI20D4d0qXo11nZdpH7aM/ChHDnEPIp75no+/wgk8dAmifcApaVzdEfaHi1zWvJh+Xq5nmqPqX3SPjfoKpJfMW5GCXI9vDVY274s+967LJIIhK//c/lwU+J9/RLwAHrd5DLZbSKydnwH/C4UFHn9RmBqKNn3JK6/SnEJlddBdxN8FIc2ZgDihx0WXRLjsde4uuEn20Ap9InzSU6c0tkw1rEN3gKD6W76UBIMTs/0R9BupK1M2YIvivB90voUv3ykIFfY6mF2bmERdw0z7xZow9PSRCPT366ZxgP3oEkN4jvNca5S/Lr5soCGVTW4VrO/LrpLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by KL1PR0401MB6242.apcprd04.prod.outlook.com (2603:1096:820:c2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20; Wed, 2 Nov 2022 07:11:20 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222%9]) with mapi id 15.20.5769.015; Wed, 2 Nov 2022 07:11:20 +0000 From: "Yuezhang.Mo@sony.com" To: Namjae Jeon , Sungjong Seo CC: linux-kernel , linux-fsdevel , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v2 1/2] exfat: simplify empty entry hint Thread-Topic: [PATCH v2 1/2] exfat: simplify empty entry hint Thread-Index: AdjuiYCKj4IPGKfeSPGqWj6Mqbkdzw== Date: Wed, 2 Nov 2022 07:11:20 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|KL1PR0401MB6242:EE_ x-ms-office365-filtering-correlation-id: 08e83b6e-756b-4af7-88e1-08dabca1718b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 64PnOna9/a52xZL2q9YtD+gyhrWM+q8YIEgRH3WEiCjOxrBUCYEaIRReFa1BlkdkxWphj0K2bmpcc8KKjmbKP4Fmz+WOUfJEX9T+By+YhmI4ouEl2Lf4Hchw+5x5VuJnEwq24tZZ2EJ8Z7AW6DA0pl3efwoa+jbonSeYOt62UxVctaidztL4mcfgIkx8+4XDLCc08W49mOsoiaAdzlDleZytdUKGiBrxLvZFoXC1rLqXO5Zrex7uezykXGhVOizYphX/d9mVhDIbLpPhtaoL2lJ2u1+CPrmAhb3CMLbvQkSD8Ioaq/1FQVV1xFp13hyScUDGnb0Y37GMBDFzq+ax+klKasPAMgkpmLDw4PLR3rqQvP0k/FCB4RqxbRwLtNzmZgpEQ2VLfHw3zVt7XqdrVU/RsARbCbT4lz4xtx0FY+FkVHYyfpRD7w8f6W4NZoeC1pZ2eY22lcvX5fFtE1pIAbvmOPmXby2Y1M+ODWRakw/Nj7lOAZoFHRym60UIvRRSu66MXJ6whdpJEXrgaF9Fmy3f2fCoTt9PyT7dLzFlTDTEmZVGPdmeTFRG8hqKWgXOGEgOWqtCOVVUkkfUZdORgYSZijPB7GXmwjH1JdTG3ZvSyMjJnPcXwZSp25RcbcV9TFwv28omFA/TDDAKk2SMVoHIWB0PfL73OlDqAVagidL1RvLVNDx1VfGmctTDm/lwg8RiDIZA/0vjujNKH80OSRjeKm5oSihobgl8QI3CqmUj8RL2hLCX5h1z6ZkAJaqykpVhGZxFpciWqd61lkLTDg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(9686003)(6506007)(186003)(107886003)(316002)(26005)(2906002)(83380400001)(7696005)(55016003)(54906003)(66476007)(478600001)(66446008)(41300700001)(5660300002)(64756008)(76116006)(71200400001)(8936002)(66946007)(4326008)(8676002)(66556008)(52536014)(110136005)(86362001)(33656002)(122000001)(82960400001)(38100700002)(38070700005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?geqQytCNlOpOYxk5X+DoLNnbP/LD?= =?utf-8?q?yyShll2OcBQ4T52vifRXm0UmBMzaxsTK1XcK1a6pKmQczbfsg8qNzUCuNSm88Q1a4?= =?utf-8?q?RLpz2guwhZD2rV9lhhvkHwMRplbfsec5uZNzKjEyGRRyR4wz/ul5KKLQJu+pFCi2z?= =?utf-8?q?05+9+xSm0dyBUJEqX5OHBtIWEPcZezPZBX6bOMD2JHswwNA7THynwLQDr03FoNH6/?= =?utf-8?q?87iDHWfH/MngyFjfcNG8NtWXLrIC3YRJDdp6vMh/0n2+3WViA9/jD5vrluu7+JuvF?= =?utf-8?q?u/yia4u+mYAygYOqXIWXnMNzFbbYW325jhPMwv4ydaCz8ftqKTm8JwGmFNF4naCEV?= =?utf-8?q?6t/+h8NYz7Hjs7PXDwsL0L5c/gHP9EgmzlzbWZILUUT5PNJ1l6zzGVPtm5pIQSkDj?= =?utf-8?q?ycC3Fs/JfvfTIO0dAeOG79fuy4xcKljCgyhE7B60/4nG0CtLvl4SMVRuwIeNpVdht?= =?utf-8?q?0/m58KqDaa0ys2cz0wjm+xuGZzB8V5dIf5kDvzLFi0QWHtacYzlYXaJ1uP30DblE8?= =?utf-8?q?DKdAg4QVh0y/yAvmtZpBa1tGZxdE8eJOF+W1HU+YZjM/i1WcFX0Kv3PxBvmMrXIF+?= =?utf-8?q?Mlbfjem0L9WaBYWhpJV57T48G4mitC9Qez+Xb1hPqJCBdirAc221LHPw6cB/Kg+Ti?= =?utf-8?q?Evau1BUaAeh4ybC70NUew8vVzXPkyBANRRGTI/Rt4g4LZ+PwgBKx+ZfoX5Sv/rzIO?= =?utf-8?q?SWBaMVghtjKCCGpz0t2XbHblMBvZ2BB0BC0cPtqrMhRUyHyrUpp29sGIeRF6+iYSD?= =?utf-8?q?V6vhgdZ/0rPmFYokni6VWqPGsSk7Ir4pkLPNZAMHFdCFP1rsW89qNib7tM0jQWqtI?= =?utf-8?q?PSA6lHlNyn351bmSMkZsRmA0CgFAZD+NrOsxzM2ySKRKaryd5Hacz51Mce0QtH6kb?= =?utf-8?q?fIl7ePTUoPr87nhKsM9qfqhNxsuH7m1+A2FvrUCig1wsKICqdLljGwEc2LhmVnajC?= =?utf-8?q?FufqhPPNKY+RsUZW60yqMofxsnyM97gPgtsqFqVG3TLBJcrbCVtkzC1vIo9kWM/y+?= =?utf-8?q?9YZ4iRqiL6askbYiSJ9rkzsxiWm+hxGGq4DU39+wrVwy31fvYFaVlie9kimwGX4xM?= =?utf-8?q?xSScXGQ5hSDqTWMThu6+QF5UEP3A9M9tISwz3s0Xuyka250QTvgLQWnyoNMtwfYnV?= =?utf-8?q?KyHICK5pSKcmHV9WJwLWBFHYDVFR63kcKAbGRRz/KhdGl/FqjRjfykgE4V37wJnRi?= =?utf-8?q?tH2vWc8ykjOgiI41SnjgNXsepXbRbM6ftRmAXT2pZV1xjqL4Ca0yqtg/r7blBtw4v?= =?utf-8?q?HrXIZbNFn9ypXaX3MqXDfub4EW617MQkmWbSdoR62lZnmFr49pXxzgyBYsE2EsXPf?= =?utf-8?q?6AlDC2vB5HRZbXJHX8uwKARSelBINYs/KH0M0Bt9pZv0ek9Lo4tQ6iEqsCQm0ufqf?= =?utf-8?q?my31VWTQ2ZPsum84CXRyd+O5L+4NjfvISnzNpNg5gzns7Dn21MKQo7IwM+3RS6s6M?= =?utf-8?q?GHclg46DeFyceOiif/NNWBcfrpSfcyWIqHozBX+/2KxT+w9NBjmGDDRM7Hp6bkeNV?= =?utf-8?q?wk7XwrOOKauw?= MIME-Version: 1.0 X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08e83b6e-756b-4af7-88e1-08dabca1718b X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Nov 2022 07:11:20.6760 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: cRA4Z5DmuCmQ+Zncaml4q2wtDu8op7DpypGciCXaixDF8YLD6nSZEueUBAuoq0xXU2LPosCB7sbnCClgENiUQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB6242 X-Proofpoint-ORIG-GUID: MGnxl7cr5Hs9xEG4IJl2V5VMcN96zIPl X-Proofpoint-GUID: MGnxl7cr5Hs9xEG4IJl2V5VMcN96zIPl X-Sony-Outbound-GUID: MGnxl7cr5Hs9xEG4IJl2V5VMcN96zIPl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-02_04,2022-11-01_02,2022-06-22_01 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748367923750493418?= X-GMAIL-MSGID: =?utf-8?q?1748367923750493418?= This commit adds exfat_set_empty_hint()/exfat_reset_empty_hint() to reduce code complexity and make code more readable. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru Reviewed-by: Sungjong Seo --- fs/exfat/dir.c | 58 +++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 27 deletions(-) -- 2.25.1 diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index a27b55ec060a..9f9b8435baca 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -897,6 +897,29 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, return NULL; } +static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) +{ + hint_femp->eidx = EXFAT_HINT_NONE; + hint_femp->count = 0; +} + +static inline void exfat_set_empty_hint(struct exfat_inode_info *ei, + struct exfat_hint_femp *candi_empty, struct exfat_chain *clu, + int dentry, int num_entries) +{ + if (ei->hint_femp.eidx == EXFAT_HINT_NONE || + ei->hint_femp.eidx > dentry) { + if (candi_empty->count == 0) { + candi_empty->cur = *clu; + candi_empty->eidx = dentry; + } + + candi_empty->count++; + if (candi_empty->count == num_entries) + ei->hint_femp = *candi_empty; + } +} + enum { DIRENT_STEP_FILE, DIRENT_STEP_STRM, @@ -921,7 +944,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, { int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len; int order, step, name_len = 0; - int dentries_per_clu, num_empty = 0; + int dentries_per_clu; unsigned int entry_type; unsigned short *uniname = NULL; struct exfat_chain clu; @@ -939,10 +962,13 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, end_eidx = dentry; } - candi_empty.eidx = EXFAT_HINT_NONE; + exfat_reset_empty_hint(&ei->hint_femp); + rewind: order = 0; step = DIRENT_STEP_FILE; + exfat_reset_empty_hint(&candi_empty); + while (clu.dir != EXFAT_EOF_CLUSTER) { i = dentry & (dentries_per_clu - 1); for (; i < dentries_per_clu; i++, dentry++) { @@ -962,26 +988,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, entry_type == TYPE_DELETED) { step = DIRENT_STEP_FILE; - num_empty++; - if (candi_empty.eidx == EXFAT_HINT_NONE && - num_empty == 1) { - exfat_chain_set(&candi_empty.cur, - clu.dir, clu.size, clu.flags); - } - - if (candi_empty.eidx == EXFAT_HINT_NONE && - num_empty >= num_entries) { - candi_empty.eidx = - dentry - (num_empty - 1); - WARN_ON(candi_empty.eidx < 0); - candi_empty.count = num_empty; - - if (ei->hint_femp.eidx == - EXFAT_HINT_NONE || - candi_empty.eidx <= - ei->hint_femp.eidx) - ei->hint_femp = candi_empty; - } + exfat_set_empty_hint(ei, &candi_empty, &clu, + dentry, num_entries); brelse(bh); if (entry_type == TYPE_UNUSED) @@ -989,8 +997,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, continue; } - num_empty = 0; - candi_empty.eidx = EXFAT_HINT_NONE; + exfat_reset_empty_hint(&candi_empty); if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) { step = DIRENT_STEP_FILE; @@ -1090,9 +1097,6 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, rewind = 1; dentry = 0; clu.dir = p_dir->dir; - /* reset empty hint */ - num_empty = 0; - candi_empty.eidx = EXFAT_HINT_NONE; goto rewind; } From patchwork Wed Nov 2 07:11:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 14049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3459392wru; Wed, 2 Nov 2022 00:26:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wcdRzDLZeX+E1e+j9DIK8poKHTXdmZllmjbzVqPZHN9kVWNpB/JlvzqZIfJXBnXJw56jj X-Received: by 2002:a17:907:6d1e:b0:7ad:b54a:442d with SMTP id sa30-20020a1709076d1e00b007adb54a442dmr19567846ejc.522.1667374005584; Wed, 02 Nov 2022 00:26:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667374005; cv=pass; d=google.com; s=arc-20160816; b=NiOuSml2ke0B/Z0pgIJc6hqe/5hI5Jca7oa67/deRM5ZaGEM9rTI+D722IxlwvhWEh 7v0nlzukuZGVBn3Nh4GyoKsl7HXfdbXgclk0h1xrs51oxfoxHxJW4+xOLOYee+o6pSga 7OYPANMMxgLSf7iD0ARCDFuD+js1yl/du2joUC2uOmZA8QD2a9P8h1IXlYTlrDBLeF86 uqt8KL1m6h58XqhJFuAePkT88esZEl0fl6G3zXFmLl+qIE/EPCy8im0b75QC4nzpXAWA JEr4pJ/Xcr9ZuJ0iD3sHgEXJ3HaoMGg6ame/UAbIpXNhKEl0YdQOt+tvckxOAw6XvfdG TNIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=/c3cjSPRqwHVra4d9X7i01IuM7bGyyLc7e6NF4y2d5g=; b=CKTQAwEOJnlVoS4Hd0TRrozYEfOP8ysZic6uXkkqyOMQuDiovUEKOt/y63qMM+ixd/ xRgCXFkLVynPG4NHeLSUsSKn7SlbqDEpP5XiDlPMnoLDLU3SbkC6Cs9fRyybalw8M/qv 2kxoEjDtdNkAxHEtkbmpfDNlH7txB9CP+Goj4IBcqNhP9Bd/L8iiFFM3Wf6NlPAsj3bv PcnqwpAfXFzm/R7hEWn15uk8VlWFnICkyRHvImvU0oAfPSLU6E5sVkBfsFTRby417lCV pjZpQ9CtKIBDjgN2w7GKIJb/e30p5kQDYMbpLr6f34aEmJeI0d0yjiiPm9HWfkVn/5yN sQ0g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sony.com header.s=S1 header.b=mLDv10tD; arc=pass (i=1 spf=pass spfdomain=sony.com dkim=pass dkdomain=sony.com dmarc=pass fromdomain=sony.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=pass (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr18-20020a170907721200b007ad8bd5b636si16074430ejc.377.2022.11.02.00.26.19; Wed, 02 Nov 2022 00:26:45 -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=@sony.com header.s=S1 header.b=mLDv10tD; arc=pass (i=1 spf=pass spfdomain=sony.com dkim=pass dkdomain=sony.com dmarc=pass fromdomain=sony.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=pass (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbiKBHLu (ORCPT + 99 others); Wed, 2 Nov 2022 03:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiKBHLk (ORCPT ); Wed, 2 Nov 2022 03:11:40 -0400 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16FA413F46; Wed, 2 Nov 2022 00:11:38 -0700 (PDT) Received: from pps.filterd (m0209320.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A25v8TR020360; Wed, 2 Nov 2022 07:11:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=S1; bh=/c3cjSPRqwHVra4d9X7i01IuM7bGyyLc7e6NF4y2d5g=; b=mLDv10tDZJ8Y0z/POGOwADjsqH2uHjMG09PvhtnJovHev71CCO4fkswFV912Q22qbVY3 8r4WoC6snX66NmrbJVsGJE0SaVcIgZNLyw2DKkLFfb00ZRsqt3+K/ZwW7aHMZOG4C+aE oNAxT50QclnZXzAo+51T5NiYce5U+68BXzoiwLLWndPU5+vggBw/myCiLhSJyGOlRPSW TzOazlWGmrH30FG94JIOjgqvA2FTLzhWq+oPTGscAj0lo3TkIhFBNAGXEtaXDsi2URuY B/ncdzzGJ9rUcT3SMWs3rBvYvxRVgLb6IiYfOY7Jp14mUFPat3oShWmDH0yoVVBzuBx3 0w== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2045.outbound.protection.outlook.com [104.47.26.45]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3kgt2p3yw5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Nov 2022 07:11:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bqajiaKUwueHlN92IDiVDUVWRJGveaL8OnCKqbXPnmlHEveLD088S1HX8DkJb3JzRL6VFgPRQX06vMouPeAbZb/anOHBX45yTLypUn6jyrt35dpEHu9bnOp13KbQTT2EjYhjmvNJDxNYhwuxgicvwEmEriD6D7Vxozc+9WrwSYdBwVkYOcQZu4jzURnNuP921CbxyaU2z67Rk29S+S1+i9kzatuQksi4ah/VtR8N75U0TJJbmibTLIK5yKSsrJo4SpHxomkTrYj9WKhjRXNeRnwFLrePJWkCchgqLZ2iQkKAMkGuVu3hFTFmW5gl34aiCY6bTR+ZWlk7rZoUxa40Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/c3cjSPRqwHVra4d9X7i01IuM7bGyyLc7e6NF4y2d5g=; b=QinRVsC+/TvKZX9VAmVGkT1rtPE9oxwW1BUUWj9lXkIe1RizIJEtKSG/LrSMCAHFv/VfFDbp6FEvbyq07MeWxGDlT+A+n7Lz1E3BYMGGBI2kUJ50eifUIMLA1cBDfK/2km2dmmWZb2nvTXMBZNqYBChGcKq6Sva9kY68SgtZ/LlQKdRgtNYYV9IQtZp+NHhhrPLPOC22g5DRcmODQJR/HugDadP79yK4VreRQ23/bWfYFKYzn6ldmJUIIx10gkUP4TPddwo9acLiJHzBW0eEPJ81SE54ysIldZzOp0NXmKCIV6+t9ZB/VBQCXlKUcLpZ+6Lugg13ZD9KSWDRdOZUpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by KL1PR0401MB6242.apcprd04.prod.outlook.com (2603:1096:820:c2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20; Wed, 2 Nov 2022 07:11:23 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222%9]) with mapi id 15.20.5769.015; Wed, 2 Nov 2022 07:11:23 +0000 From: "Yuezhang.Mo@sony.com" To: Namjae Jeon , Sungjong Seo CC: linux-kernel , linux-fsdevel , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v2 2/2] exfat: hint the empty entry which at the end of cluster chain Thread-Topic: [PATCH v2 2/2] exfat: hint the empty entry which at the end of cluster chain Thread-Index: AdjuictTJa4khvd5R/iv8k3hEb/6ZQ== Date: Wed, 2 Nov 2022 07:11:23 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|KL1PR0401MB6242:EE_ x-ms-office365-filtering-correlation-id: b23799c8-c983-459e-3c32-08dabca17337 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uZG8KMDyQCEcljq3RIigvSHVdZXG8L79QYDWAfvbhTBsQ+kLLIxXTzmQcc+fQyhPCt82g08U2EswyAOMc+eyV26RdNeWm7QgzAD7SdOkVtx5bvEIhOcChNSuUWL58sy3aSDOFe9Y6I9vmYWprQ5p0+baUFvQgk9/MOKglRxupurQS0Pps9+pOivuXw+Qgm0MmKTgAgDbRvHV6cqO1kDiY7MhMJv/2gmBdakdGPIlHBmEQwJjWlIump7vnKjrOlcCsnNkEbDL4HFklGsO+C2UzA4VdQIWU8DPIJ8XYmhC8D3BfUXeSJHG6z57Rr46X2jhduYQifMRFXAESzWNHxaYcRIk8Jiago739v0JwxoDe43qkbJ6Vmaklvk8cIRyINUGNCEPurrutgtlb0s498/cPOejE8kdh41kw7mGRBBoGrKyjadimI9dj8Z9v5d0oMdp6Dl6Ai0nL+8lXRtGbPKSK7r5QK7JEaLF1rdtGe8LV9wOuzKOJC2NwEbiijWqn7fCIRNiJ0mWVKM3oIy4VbxkqxKX6+OqeorTyV77Roh2XxNLVuiXE84dhSlxVK+JCv9nMQ1PYiuGS679aB+a8v9eFMrcn41xbk3Zd93vVoWJDeixfKIT/bmvmHi1qrYMI88OnQGWSayqQpZPqgTwpWo11o5CmnDl8Kw+1IdKN5nmlxa5fn/4NM5u/kIZ96+t3DDjiQ2o2cChIfZ6Ym6h3HfqyYy0K0eDB2KmpmEQVBp4DaDrZy0iWMUSXI8IQxFkiXYmO5XI1raSssPO1RzBDDe+cA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(9686003)(6506007)(186003)(107886003)(316002)(26005)(2906002)(83380400001)(7696005)(55016003)(54906003)(66476007)(478600001)(66446008)(41300700001)(5660300002)(64756008)(76116006)(71200400001)(8936002)(66946007)(4326008)(8676002)(66556008)(52536014)(110136005)(86362001)(33656002)(122000001)(82960400001)(38100700002)(38070700005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?hTQoG5Zrul20pCPKLH57fZBpybS4?= =?utf-8?q?txh/8nEQIQ3uf2c5NRRnx/H4DR1ORK4PieWyNfsagf/cUHyBOpuwh3crF1Fkif7Bv?= =?utf-8?q?WL9wNaTwiv9FvCgRWZYL3SCAngBX4mag/Bzhh+0UudqTEev5Aru5e5d9ldT+YX9xT?= =?utf-8?q?IdgCRMqi4d/lM9orcReoqPnPPKh1SyU7qU9GOcovvqRCn/RsYAzKOdr8ipXWN77rW?= =?utf-8?q?Hd9MfTa9AkwFYiC6GggUVNt/AWMRuVtz7FUlIsQzhuGbpAolmOiCtSXIRPjPEOgGf?= =?utf-8?q?gI4+GvkDXmucef+t83d7PVl6TKi7QpCYj7fv0k9k74pqIw/9GImTKMXthS8nVmQWz?= =?utf-8?q?Qsj1uud2oZBSQ0IyatdoYoB0yqqH9kV6vCE/nFL1kNrjRWViYpf7ubH51Axxs+NF1?= =?utf-8?q?A+sSf9J+WnwwQaIjgrQIvs8yYVoL0kTi7lsoJ1AexHr9/XnbgnW0oCOTJucY5kggB?= =?utf-8?q?Ud5bo5xy1lrNLEm7713YBhvIBlvEEj2D7TVZPFIaZjSX/HFIqcFBsFwjoZlVT3kSp?= =?utf-8?q?xdSiJLrtagX/YMWtBXHKHLq3QY/kkx20MbG/RmqWo92D14rzkdiAy/fvlwvvkhIla?= =?utf-8?q?GeRHU3jG5O94u8nfOQgqR8X9+1EQ0OBJhZn5TYgpbcRYfFB1vJRteA0GyzcHbyAry?= =?utf-8?q?mFR3qoNBVz8rP5uEVYZuezGu+a4kD6wl/2BrCG2j5dFL/5Q8ViiVHm7RAJGje6xlp?= =?utf-8?q?lC5qoJiPpZLnjnhFp4DYQyomJjYPtY4WEhOu8mEthbqFC5zUfIHPovhmIauiWNDlI?= =?utf-8?q?94oMVETvVBd/b5LbJJka50MumiWLUqUwHOwwJGKUePvM1Gnwjf846PmsWWf4/mmo+?= =?utf-8?q?ngyW0RX6E8SxtnmQIjOrnAWm9tHnrJn9guvFa4XG7Qaf1kQYGEl0MZVyaeTnzC62J?= =?utf-8?q?rrTgy8kM/BWOeceOQWQpqgxpUyOIYgl9vtIHsg8IFRuJeBOLpt8qccmKIdrnrE5/F?= =?utf-8?q?vkPMDQ0S0LNE95wjHelFSXWwBWvZRNIadjnCAvaGcC0Sios7ox6GdDkLiNWwQvc0M?= =?utf-8?q?2kUugKoOqn+F0lWYTzxuuMq7sMF/qVnuZ3NXclrcgFN3eu3pe4LS3efetVj9JlEbQ?= =?utf-8?q?Ufw6q28YSWxff83ZsWtMnh1qGe8MqOBk+gGw9BOt0eg2T+bBpPnjUp5OYrQNI65Xi?= =?utf-8?q?7XuqxpPZFquJGnYDldzpkIaTBAiXmy2raKw5XCcg3HLD7UPbHcGpMb6W6CmUFvvGU?= =?utf-8?q?CU46U8y0b0zRQFN+Rg5EaFu7BCO97/DG/yA/8rUxqZXQo86ArUy29t86SBzAKgi5M?= =?utf-8?q?pfv/qdUqfO5L5djJTWTVv/1uZUxh3W+UnxlQ+X4PtRq89ILfngKdMmwxdxPKkjY3r?= =?utf-8?q?qqlbBxY51DcFy+1NaW7zjyhAzcUDTV1dK2Wixi1phLgCsuCPuxEL8YfxsBmaiuVEj?= =?utf-8?q?9pgHnKkPSzM+fY3OkVz5Io2QE6JvWsfBNSBsaJ6v1D+To41Tk4t8oQzwkOML+X7K4?= =?utf-8?q?piR+RxlD/HiWaISRVYkjICxFs+FYeCRSnYxyis8PYSF7X12AgzZHvxIRLfE9ygWDp?= =?utf-8?q?RM4dT0G6huy0?= MIME-Version: 1.0 X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b23799c8-c983-459e-3c32-08dabca17337 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Nov 2022 07:11:23.4477 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fhaV6uFf1W8g1N4W6Xp0tDFe5av6ThF+qePbnhUQY2rDTUPf46bZC5x6aJnGZ4zXiOJTxAtdhTOMU51+pPgYag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB6242 X-Proofpoint-GUID: LFJ-1iAV7aAGdwjZsWX4j3vieb_0kOGG X-Proofpoint-ORIG-GUID: LFJ-1iAV7aAGdwjZsWX4j3vieb_0kOGG X-Sony-Outbound-GUID: LFJ-1iAV7aAGdwjZsWX4j3vieb_0kOGG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-02_04,2022-11-01_02,2022-06-22_01 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748368365103794041?= X-GMAIL-MSGID: =?utf-8?q?1748368365103794041?= 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 Reviewed-by: Sungjong Seo --- fs/exfat/dir.c | 26 ++++++++++++++++++++++---- fs/exfat/namei.c | 33 +++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 16 deletions(-) -- 2.25.1 diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 9f9b8435baca..5497a610808d 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -905,17 +905,24 @@ static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) static inline void exfat_set_empty_hint(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.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; + else + candi_empty->count++; + + if (candi_empty->count == num_entries || + candi_empty->count + candi_empty->eidx == total_entries) ei->hint_femp = *candi_empty; } } @@ -989,7 +996,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, step = DIRENT_STEP_FILE; exfat_set_empty_hint(ei, &candi_empty, &clu, - dentry, num_entries); + dentry, num_entries, + entry_type); brelse(bh); if (entry_type == TYPE_UNUSED) @@ -1100,6 +1108,16 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, goto rewind; } + /* + * set the EXFAT_EOF_CLUSTER flag to avoid search + * from the beginning again when allocated a new cluster + */ + if (ei->hint_femp.eidx == EXFAT_HINT_NONE) { + ei->hint_femp.cur.dir = EXFAT_EOF_CLUSTER; + ei->hint_femp.eidx = p_dir->size * dentries_per_clu; + ei->hint_femp.count = 0; + } + /* initialized hint_stat */ hint_stat->clu = p_dir->dir; hint_stat->eidx = 0; diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index b617bebc3d0f..add4893711d3 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -224,11 +224,18 @@ static int exfat_search_empty_slot(struct super_block *sb, if (hint_femp->eidx != EXFAT_HINT_NONE) { dentry = hint_femp->eidx; - if (num_entries <= hint_femp->count) { - hint_femp->eidx = EXFAT_HINT_NONE; - return dentry; - } + /* + * If hint_femp->count is enough, it is needed to check if + * there are actual empty entries. + * Otherwise, and if "dentry + hint_famp->count" is also equal + * to "p_dir->size * dentries_per_clu", it means ENOSPC. + */ + if (dentry + hint_femp->count == p_dir->size * dentries_per_clu + && num_entries > hint_femp->count) + return -ENOSPC; + + hint_femp->eidx = EXFAT_HINT_NONE; exfat_chain_dup(&clu, &hint_femp->cur); } else { exfat_chain_dup(&clu, p_dir); @@ -293,6 +300,12 @@ static int exfat_search_empty_slot(struct super_block *sb, } } + hint_femp->eidx = p_dir->size * dentries_per_clu - num_empty; + hint_femp->count = num_empty; + if (num_empty == 0) + exfat_chain_set(&hint_femp->cur, EXFAT_EOF_CLUSTER, 0, + clu.flags); + return -ENOSPC; } @@ -369,15 +382,11 @@ static int exfat_find_empty_entry(struct inode *inode, if (exfat_ent_set(sb, last_clu, clu.dir)) return -EIO; - if (hint_femp.eidx == EXFAT_HINT_NONE) { - /* the special case that new dentry - * should be allocated from the start of new cluster - */ - hint_femp.eidx = EXFAT_B_TO_DEN_IDX(p_dir->size, sbi); - hint_femp.count = sbi->dentries_per_clu; - + if (hint_femp.cur.dir == EXFAT_EOF_CLUSTER) exfat_chain_set(&hint_femp.cur, clu.dir, 0, clu.flags); - } + + hint_femp.count += sbi->dentries_per_clu; + hint_femp.cur.size++; p_dir->size++; size = EXFAT_CLU_TO_B(p_dir->size, sbi);