Received: by 10.213.65.68 with SMTP id h4csp1367943imn; Mon, 19 Mar 2018 02:04:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELuFMxOmRiS3sjNIgG7VpzPsNW9bIoSY/i72d8nYxPAev1HhuV3rBWtamCaOOyHfBxdq8Ta+ X-Received: by 2002:a17:902:d892:: with SMTP id b18-v6mr11808508plz.241.1521450256721; Mon, 19 Mar 2018 02:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521450256; cv=none; d=google.com; s=arc-20160816; b=XBlMLNQHcjQT8YaGQnFsEDjE6YJoXGTC/STWuckaC+LXHACNzld6Hv0cHwUPsSRPD8 YRcLU1wFZ2vEd9WKgGPC3kHLiOr4jayFiwNAfWEUOVrPyXPznF8HjenjttJNavV51fjU U8Ylg0lHJNVT2UEVUf9vGZr/72TBCp1Qr34G4qTRaUHsQMmHaIqeV7RaRUziokX9E+lf RUaO07bg+6aK5YdVEegeobn2VcZKB03BWwmKqmYjpdPcYTp7GwAWWBelgvV7Wsm0Ty/K 2QspiveIFoJb+4lBAsvoxYvCvqPu6RoGq15Kv50RVBS2/vr6Pxog/UqDI7Y0mbppFDyh qq/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=IiAaTnti+9I5aDbxyFLLfRJfnGyC32b7RXzGwFmLt7g=; b=LndZhRWLCX/IOb0eoyB1nOaSpSwqYIQAZjfo6R5UZJDThknZ6PhV0OWobsEQIY9/Zm 5jmzDLhI6uvNdQFcRsVx5zhkUE0a1OnjuvPVy+PPqmrk3nz/oJfCjn1LQMpgkfqnh9dA 1zivF4Pi+PETHr43e72uCu5USGSWMrcoy9zIuxeyC5IqUvcLeEmrcGrWxGi/K6AMGyM8 PWbtNT7Z5FyyLVTkRnnQktDlc3FCBM7RGhkSmHTgECTdVmiWlxj0vbpgiH/vChpmECSY QIv/4NW1kcYnN9GYBc6mSp/tNbl5FzTO1YqtLzHS9gmdy2tNU1r/OKLe2qH7iQ+JqqZ5 90Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si12253533plm.443.2018.03.19.02.04.03; Mon, 19 Mar 2018 02:04:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932706AbeCSI24 (ORCPT + 99 others); Mon, 19 Mar 2018 04:28:56 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:34646 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932696AbeCSI2s (ORCPT ); Mon, 19 Mar 2018 04:28:48 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7B1749C9339C6; Mon, 19 Mar 2018 16:28:44 +0800 (CST) Received: from [127.0.0.1] (10.177.219.49) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Mon, 19 Mar 2018 16:28:43 +0800 Subject: Re: [PATCH] jffs2: remove fd from the f->dents list immediately. To: David Woodhouse , Joakim Tjernlund CC: "viro@zeniv.linux.org.uk" , "linux-kernel@vger.kernel.org" , "linux-mtd@lists.infradead.org" References: <20180316110522.1120-1-yuyufen@huawei.com> <1521203963.4790.208.camel@infinera.com> <1521204767.20126.123.camel@infradead.org> From: yuyufen Message-ID: <8bce38ca-aa2e-1928-4807-5571f91ae1c8@huawei.com> Date: Mon, 19 Mar 2018 16:27:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1521204767.20126.123.camel@infradead.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.177.219.49] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, David On 2018/3/16 20:52, David Woodhouse wrote: > On Fri, 2018-03-16 at 12:39 +0000, Joakim Tjernlund wrote: >>> After reverting the commit, we test 'rm -r', which can remove all >>> files, and all seems OK! >> UHH, this is mine (and Davids work from 2007)! >> I cannot remember any details this long afterwards but I guess you cannot just >> revert that part as it triggers some other bug, David? > Right, the issue was with f_pos in the directory. > > The 'rm' we were testing with at the time would delete a bunch of > directory entries, then continue with its readdir() to work out what > else to delete. But when we were handling f_pos on directories merely > as the position on the list, and when we were *deleting* things from > that list as we went, some dirents ended up moving so that they were > *before* the position that 'rm' had got to with its readdir(). Thanks a for explaining in detail. And you are right. We have a directory, including 2000 files. After getdents and unlink as follow: for ( ; ; ) { nread = syscall(SYS_getdents, fd, buf, BUF_SIZE); //BUF_SIZE=1024 for (bpos = 0; bpos < nread;) { unlink(d->d_name); } } we found there is still 990 files! > But... the list we're traversing is *already* ordered by CRC, and that > could be a much saner thing to use as f_pos. We just have to make sure That's true. Our experiments also show that it can quicken traverse. However, when the list is very long (e.g. 1000000), the number of traverse times can reach thousands. What's more, a lot of memory space is occupying and will be more and more. I have no idea how to improve this. Do you have some good idea? Thanks, yufen > we cope with hash collisions. Shifting left by 4 bits and using the low > 4 bits would allow us to cope with 16 names with the same hash... but > I'm not sure that's good enough.