Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934039AbcLHBac (ORCPT ); Wed, 7 Dec 2016 20:30:32 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37465 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932372AbcLHBab (ORCPT ); Wed, 7 Dec 2016 20:30:31 -0500 From: Rasmus Villemoes To: Tejun Heo , Andrew Morton Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , Jens Axboe , Greg Kroah-Hartman , Rasmus Villemoes Subject: [RFC 10/10] fs/devpts: use tida for id allocation Date: Thu, 8 Dec 2016 02:23:05 +0100 Message-Id: <1481160187-9652-11-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> References: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2863 Lines: 97 Using the newly introduced tida for allocating pty indexes saves around 16KB of runtime memory. Since tida does it's own internal locking, we don't need to protect it with the &allocated_ptys_lock and do the whole "preallocate outside lock, loop if we're extremely unlucky", thus allowing us simplify devpts_new_index somewhat. Signed-off-by: Rasmus Villemoes --- fs/devpts/inode.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 108df2e3602c..ea40437f246a 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -122,7 +122,7 @@ static const match_table_t tokens = { }; struct pts_fs_info { - struct ida allocated_ptys; + struct tida allocated_ptys; struct pts_mount_opts mount_opts; struct super_block *sb; struct dentry *ptmx_dentry; @@ -377,7 +377,7 @@ static void *new_pts_fs_info(struct super_block *sb) if (!fsi) return NULL; - ida_init(&fsi->allocated_ptys); + tida_init(&fsi->allocated_ptys); fsi->mount_opts.mode = DEVPTS_DEFAULT_MODE; fsi->mount_opts.ptmxmode = DEVPTS_DEFAULT_PTMX_MODE; fsi->sb = sb; @@ -453,7 +453,7 @@ static void devpts_kill_sb(struct super_block *sb) struct pts_fs_info *fsi = DEVPTS_SB(sb); if (fsi) - ida_destroy(&fsi->allocated_ptys); + tida_destroy(&fsi->allocated_ptys); kfree(fsi); kill_litter_super(sb); } @@ -473,29 +473,21 @@ static struct file_system_type devpts_fs_type = { int devpts_new_index(struct pts_fs_info *fsi) { int index; - int ida_ret; -retry: - if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL)) - return -ENOMEM; + index = tida_get(&fsi->allocated_ptys, GFP_KERNEL); + if (index < 0) + return index; mutex_lock(&allocated_ptys_lock); if (pty_count >= (pty_limit - (fsi->mount_opts.reserve ? 0 : pty_reserve))) { + tida_put(&fsi->allocated_ptys, index); mutex_unlock(&allocated_ptys_lock); return -ENOSPC; } - ida_ret = ida_get_new(&fsi->allocated_ptys, &index); - if (ida_ret < 0) { - mutex_unlock(&allocated_ptys_lock); - if (ida_ret == -EAGAIN) - goto retry; - return -EIO; - } - if (index >= fsi->mount_opts.max) { - ida_remove(&fsi->allocated_ptys, index); + tida_put(&fsi->allocated_ptys, index); mutex_unlock(&allocated_ptys_lock); return -ENOSPC; } @@ -507,7 +499,7 @@ int devpts_new_index(struct pts_fs_info *fsi) void devpts_kill_index(struct pts_fs_info *fsi, int idx) { mutex_lock(&allocated_ptys_lock); - ida_remove(&fsi->allocated_ptys, idx); + tida_put(&fsi->allocated_ptys, idx); pty_count--; mutex_unlock(&allocated_ptys_lock); } -- 2.1.4