From patchwork Fri Mar 16 11:05:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yuyufen X-Patchwork-Id: 886722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TRUWuZ3e"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 402j8G5dZ3z9sPx for ; Fri, 16 Mar 2018 21:57:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=DOpmvscko4mOvseuk8fHLzh4oTwG+A6SSVtADARRmxc=; b=TRUWuZ3eZppkar fc6rhSkryU6LOV8pWS2ffPqWde+ZFtTQKsz4S1Kyx3x0Ti+CDqe2oOTJviaanU1R80xiKptez5oyD bTnqXlD+YqZr2WJ+wp6iPelDYUsXcWnK5Bywhzkhe09kh3UwLxEmR6JjypUSs1OeJTL3K5ytikNZP kTtRaQ3hvCi4ZopVIjTLRalSMfSgNLdSusL3aG4IiZjSPVHdL1PMIAXsXqz4moFx78/IHgFHgpps0 /rwwI+6YvBMIEnwbLkS7k0Sq0M1dqWiLmKujRZhmCeVzn6WdBvwbFAG1q/mmQjIVUTxfl9DEFus1B 3vXhADUq4TlX45bQkP/A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewn2b-00031y-9Z; Fri, 16 Mar 2018 10:56:53 +0000 Received: from [45.249.212.32] (helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewn2X-0002zD-Au for linux-mtd@lists.infradead.org; Fri, 16 Mar 2018 10:56:51 +0000 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2D3B718A6179A; Fri, 16 Mar 2018 18:56:25 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.361.1; Fri, 16 Mar 2018 18:56:16 +0800 From: Yufen Yu To: Subject: [PATCH] jffs2: remove fd from the f->dents list immediately. Date: Fri, 16 Mar 2018 19:05:22 +0800 Message-ID: <20180316110522.1120-1-yuyufen@huawei.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180316_035650_059123_4620A525 X-CRM114-Status: GOOD ( 12.21 ) X-Spam-Score: 1.3 (+) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (1.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, viro@zeniv.linux.org.uk, Yufen Yu , linux-kernel@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org commit 15953580e79b ("[JFFS2] Improve getdents vs. f_pos handling on NOR flash.") is introduced to resolve 'rm -r', which cannot remove all files: http://lists.infradead.org/pipermail/linux-mtd/2007-October/019658.html However, it can cause the following issues: 1. 'deletion' dirents is alway in the f->dents list, wasting memory resource. For example: There is a file named 'file1'. Then we rename it: mv file1 file2; mv file2 file3; ... mv file99999 file1000000 When CONFIG_JFFS2_SUMMARY is not set, file1~file1000000 always in the f->dents list. 2. Since the list become longer and longer, more CPU time is used to traverse it. After reverting the commit, we test 'rm -r', which can remove all files, and all seems OK! Signed-off-by: Yufen Yu --- fs/jffs2/write.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c index cda9a361368e..1deed35beb50 100644 --- a/fs/jffs2/write.c +++ b/fs/jffs2/write.c @@ -598,31 +598,32 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, jffs2_add_fd_to_list(c, fd, &dir_f->dents); mutex_unlock(&dir_f->sem); } else { + struct jffs2_full_dirent **prev = &dir_f->dents; uint32_t nhash = full_name_hash(NULL, name, namelen); - fd = dir_f->dents; /* We don't actually want to reserve any space, but we do want to be holding the alloc_sem when we write to flash */ mutex_lock(&c->alloc_sem); mutex_lock(&dir_f->sem); - for (fd = dir_f->dents; fd; fd = fd->next) { - if (fd->nhash == nhash && - !memcmp(fd->name, name, namelen) && - !fd->name[namelen]) { - - jffs2_dbg(1, "Marking old dirent node (ino #%u) @%08x obsolete\n", - fd->ino, ref_offset(fd->raw)); - jffs2_mark_node_obsolete(c, fd->raw); - /* We don't want to remove it from the list immediately, - because that screws up getdents()/seek() semantics even - more than they're screwed already. Turn it into a - node-less deletion dirent instead -- a placeholder */ - fd->raw = NULL; - fd->ino = 0; - break; + while ((*prev) && (*prev)->nhash <= nhash) { + if ((*prev)->nhash == nhash && + !memcmp((*prev)->name, name, namelen) && + !(*prev)->name[namelen]) { + + struct jffs2_full_dirent *this = *prev; + + jffs2_dbg(1, "Marking old dirent node (ino #%u) @%08x obsolete\n", + this->ino, ref_offset(this->raw)); + *prev = this->next; + jffs2_mark_node_obsolete(c, this->raw); + jffs2_free_full_dirent(this); + + break; } + prev = &((*prev)->next); } + mutex_unlock(&dir_f->sem); }