From patchwork Wed Nov 20 14:23:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Bin X-Patchwork-Id: 11254001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A84731390 for ; Wed, 20 Nov 2019 14:16:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2D5D224E9 for ; Wed, 20 Nov 2019 14:16:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2D5D224E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 15F596B0281; Wed, 20 Nov 2019 09:16:10 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1115D6B0282; Wed, 20 Nov 2019 09:16:10 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F41AE6B0283; Wed, 20 Nov 2019 09:16:09 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id DF21B6B0281 for ; Wed, 20 Nov 2019 09:16:09 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id A0B00180AD806 for ; Wed, 20 Nov 2019 14:16:09 +0000 (UTC) X-FDA: 76176855258.19.cook88_3586472a35610 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,zhengbin13@huawei.com,:willy@infradead.org:viro@zeniv.linux.org.uk:hughd@google.com::linux-kernel@vger.kernel.org:houtao1@huawei.com:yi.zhang@huawei.com:zhengbin13@huawei.com,RULES_HIT:30034:30054:30070:30074:30075:30085,0,RBL:45.249.212.35:@huawei.com:.lbl8.mailshell.net-62.18.2.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: cook88_3586472a35610 X-Filterd-Recvd-Size: 3857 Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Nov 2019 14:16:07 +0000 (UTC) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2BFB02E04DBF7C2534C7; Wed, 20 Nov 2019 22:16:03 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Wed, 20 Nov 2019 22:15:55 +0800 From: zhengbin To: , , , , CC: , , Subject: [PATCH] tmpfs: use ida to get inode number Date: Wed, 20 Nov 2019 22:23:18 +0800 Message-ID: <1574259798-144561-1-git-send-email-zhengbin13@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use a script to test tmpfs, after 10 days, there will be files share the same inode number, thus bug happens. The script is as follows: while(1) { create a file dlopen it ... remove it } I have tried to change last_ino type to unsigned long, while this was rejected, see details on https://patchwork.kernel.org/patch/11023915. Use ida to get inode number, from the fs_mark test, performance impact is small. CPU core: 128 memory: 8G Use fs_mark to create ten million files first in tmpfs. Then test performance in the following command(test five times): rm -rf /tmp/fsmark_test sync echo 3 > /proc/sys/vm/drop_caches sleep 10 fs_mark -t 20 -s 0 -n 102400 -D 64 -N 1600 -L 3 -d /tmp/fsmark_test result is file creation speed(Files/sec). get_next_ino | use ida 439506.7 | 423219.0 441453.0 | 406832.7 439868.0 | 441283.3 445642.3 | 428221.3 441776.7 | 438129.0 average: 441649.34 | 427537.06 Signed-off-by: zhengbin --- mm/shmem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/mm/shmem.c b/mm/shmem.c index 5b93877..6b5e01b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -258,6 +258,7 @@ static const struct inode_operations shmem_dir_inode_operations; static const struct inode_operations shmem_special_inode_operations; static const struct vm_operations_struct shmem_vm_ops; static struct file_system_type shmem_fs_type; +static DEFINE_IDA(shmem_inode_ida); bool vma_is_shmem(struct vm_area_struct *vma) { @@ -1138,6 +1139,7 @@ static void shmem_evict_inode(struct inode *inode) simple_xattrs_free(&info->xattrs); WARN_ON(inode->i_blocks); + ida_simple_remove(&shmem_inode_ida, inode->i_ino); shmem_free_inode(inode->i_sb); clear_inode(inode); } @@ -2213,13 +2215,20 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode struct inode *inode; struct shmem_inode_info *info; struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + int i_ino; if (shmem_reserve_inode(sb)) return NULL; + i_ino = ida_simple_get(&shmem_inode_ida, 0, 0, GFP_KERNEL); + if (i_ino < 0) { + shmem_free_inode(sb); + return NULL; + } + inode = new_inode(sb); if (inode) { - inode->i_ino = get_next_ino(); + inode->i_ino = i_ino; inode_init_owner(inode, dir, mode); inode->i_blocks = 0; inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); @@ -2263,8 +2272,11 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode } lockdep_annotate_inode_mutex_key(inode); - } else + } else { + ida_simple_remove(&shmem_inode_ida, i_ino); shmem_free_inode(sb); + } + return inode; }