Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2125162ybc; Wed, 20 Nov 2019 09:16:01 -0800 (PST) X-Google-Smtp-Source: APXvYqw4qEPMQ5Rea7jz+1PrIpcTdNBxrT7XLyF81CBrZ4ZCVeeQy2J2djXW515i+KFOIDkhpHfK X-Received: by 2002:a1c:22c6:: with SMTP id i189mr4772045wmi.51.1574270161531; Wed, 20 Nov 2019 09:16:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574270161; cv=none; d=google.com; s=arc-20160816; b=pwGGQpzCJhr7Wo+R3BDYFx/fe0kds/DWonkL4J7xyMv/rN/hdz8epPewQtYvbIeJxM oLQlGQCIIR3ntoOwy/0YbLla5sZMyK3cmTKIXbJx/QIlJlAixT9nb3VCPeqUwu0S26Ai 8uCdHW/nofWzGLjzFipRRoUxzNiIS+mKjf2VbTpS7l1+jwrznufehVjdqDz/82hmOzex 2MEWGNInJyQhJvEp0tHnU6O1IEa0F1FHhkxvGCaJuYtMGDNmSsu+QyRj+5qRKQcZgkqu hglogf9h3W7wnZZZFNcV0FMVHisA9KBMO7ynB8mPV3/PDQ8ZZHglLVrmP9tYN6Zoj7y/ AK/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=T1XjWmaAbbx/kbPu5/yzjuRzARGq7PoJAYWTVfiRrBU=; b=x2D1Gn2LIK/RCeBKzB6+ViFA5FsQSlwWA4j8qASBJfp/fFip/UrnVmNDZASkoD6Lav 4J5GXxlw/GME/Y31R1mfzFTzPibufsUDlbahUghyDDt6a/rWf04G7aVRKF3IrjyC/ZYU rsWuD0/wTDpchEDNXAc+HB6h0phnTuGcfdDSkq1oeUI7oXDKJgiZ2IdQTLweMSo3675X t5s5r7CyN+tOC+cLaXne7fhJB7SN8/JlyTy+1HvO39kIu9qo5SwZWkWmY4qO9CpfE9X3 r4F4cxVK2NDlwbeynZADcMUiruthZNMllSXIsRLh5qwPmMVdsf9ThX+r52PaAOEuAjLa y/pQ== 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 e22si21243158ede.163.2019.11.20.09.15.35; Wed, 20 Nov 2019 09:16:01 -0800 (PST) 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 S1731657AbfKTOQH (ORCPT + 99 others); Wed, 20 Nov 2019 09:16:07 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:45688 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730191AbfKTOQH (ORCPT ); Wed, 20 Nov 2019 09:16:07 -0500 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 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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; } -- 2.7.4