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);