[Devel] [RH7 PATCH 3/3] [fs] file_table: get rid of s_files and files_lock

Dmitry Monakhov dmonakhov at openvz.org
Tue Jun 23 08:14:55 PDT 2015


From: Al Viro <viro at zeniv.linux.org.uk>

backport: rh7/229.7.2/fs-file_table-get-rid-of-s_files-and-files_lock.patch
https://jira.sw.ru/browse/PSBM-34421

>From b95bd197b67d8be70a420bb08b87b816517d1935 Mon Sep 17 00:00:00 2001
[fs] file_table: get rid of s_files and files_lock

Message-id: <1415044849-10555-3-git-send-email-gduarte at redhat.com>
Patchwork-id: 99371
O-Subject: [RHEL7.1 PATCH BZ 1112805 2/2 v2] get rid of s_files and files_lock
Bugzilla: 1112805
RH-Acked-by: Mateusz Guzik <mguzik at redhat.com>
RH-Acked-by: Jeff Moyer <jmoyer at redhat.com>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1112805
Upstream Status: eee5cc2702929fd41cce28058dc6d6717f723f87

This version (v2) addresses Mateusz Guzik's comment:
"You leave now-unused fields unaltered which may lead to trouble in the future,
please rename them and properly ifdef with _GENKSYMS__ so that it still passes
abi checks (see s_files_deprecated in my patch, I messed up with
f_sb_list_cpu_deprecated)."

Mateusz Guzik's original patch description:

Fix a lockup of form:

<IRQ>
[<ffffffff811b1c61>] file_sb_list_del+0x21/0x50
[<ffffffff811b1cb5>] fput+0x25/0xc0
[<ffffffff811fbe1e>] aio_put_req+0x2e/0x80
[<ffffffff811fc020>] aio_complete+0x1b0/0x2b0
[.....]
<EOI>
[<ffffffff8108e13e>] ? lg_local_lock+0x1e/0x60
[<ffffffff811b1bfe>] file_sb_list_add+0x1e/0x60

Turns out the lock (and the list) are not needed, so just remove them.

Forceful read-only remount is already honored by mnt_want_write, so
there is no reason to go over all file pointers and change their open mode.

commit eee5cc2702929fd41cce28058dc6d6717f723f87
Author: Al Viro <viro at zeniv.linux.org.uk>
Date:   Fri Oct 4 11:06:42 2013 -0400

    get rid of s_files and files_lock

    The only thing we need it for is alt-sysrq-r (emergency remount r/o)
    and these days we can do just as well without going through the
    list of files.

    Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>

Signed-off-by: Jarod Wilson <jarod at redhat.com>
Signed-off-by: Dmitry Monakhov <dmonakhov at openvz.org>
---
 fs/file_table.c    |  122 ----------------------------------------------------
 fs/internal.h      |    3 -
 fs/open.c          |    2 -
 fs/super.c         |   23 +---------
 include/linux/fs.h |   14 ++++++
 5 files changed, 16 insertions(+), 148 deletions(-)

diff --git a/fs/file_table.c b/fs/file_table.c
index fa537c1..5a04306 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -40,8 +40,6 @@ struct files_stat_struct files_stat = {
 	.max_files = NR_FILE
 };
 
-DEFINE_STATIC_LGLOCK(files_lglock);
-
 /* SLAB cache for file structures */
 static struct kmem_cache *filp_cachep __read_mostly;
 
@@ -323,7 +321,6 @@ void fput(struct file *file)
 		struct task_struct *task = current;
 		unsigned long flags;
 
-		file_sb_list_del(file);
 		if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
 			init_task_work(&file->f_u.fu_rcuhead, ____fput);
 			if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
@@ -348,7 +345,6 @@ void __fput_sync(struct file *file)
 {
 	if (atomic_long_dec_and_test(&file->f_count)) {
 		struct task_struct *task = current;
-		file_sb_list_del(file);
 		BUG_ON(!(task->flags & PF_KTHREAD));
 		__fput(file);
 	}
@@ -360,127 +356,10 @@ void put_filp(struct file *file)
 {
 	if (atomic_long_dec_and_test(&file->f_count)) {
 		security_file_free(file);
-		file_sb_list_del(file);
 		file_free(file);
 	}
 }
 
-static inline int file_list_cpu(struct file *file)
-{
-#ifdef CONFIG_SMP
-	return file->f_sb_list_cpu;
-#else
-	return smp_processor_id();
-#endif
-}
-
-/* helper for file_sb_list_add to reduce ifdefs */
-static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
-{
-	struct list_head *list;
-#ifdef CONFIG_SMP
-	int cpu;
-	cpu = smp_processor_id();
-	file->f_sb_list_cpu = cpu;
-	list = per_cpu_ptr(sb->s_files, cpu);
-#else
-	list = &sb->s_files;
-#endif
-	list_add(&file->f_u.fu_list, list);
-}
-
-/**
- * file_sb_list_add - add a file to the sb's file list
- * @file: file to add
- * @sb: sb to add it to
- *
- * Use this function to associate a file with the superblock of the inode it
- * refers to.
- */
-void file_sb_list_add(struct file *file, struct super_block *sb)
-{
-	lg_local_lock(&files_lglock);
-	__file_sb_list_add(file, sb);
-	lg_local_unlock(&files_lglock);
-}
-
-/**
- * file_sb_list_del - remove a file from the sb's file list
- * @file: file to remove
- * @sb: sb to remove it from
- *
- * Use this function to remove a file from its superblock.
- */
-void file_sb_list_del(struct file *file)
-{
-	if (!list_empty(&file->f_u.fu_list)) {
-		lg_local_lock_cpu(&files_lglock, file_list_cpu(file));
-		list_del_init(&file->f_u.fu_list);
-		lg_local_unlock_cpu(&files_lglock, file_list_cpu(file));
-	}
-}
-
-#ifdef CONFIG_SMP
-
-/*
- * These macros iterate all files on all CPUs for a given superblock.
- * files_lglock must be held globally.
- */
-#define do_file_list_for_each_entry(__sb, __file)		\
-{								\
-	int i;							\
-	for_each_possible_cpu(i) {				\
-		struct list_head *list;				\
-		list = per_cpu_ptr((__sb)->s_files, i);		\
-		list_for_each_entry((__file), list, f_u.fu_list)
-
-#define while_file_list_for_each_entry				\
-	}							\
-}
-
-#else
-
-#define do_file_list_for_each_entry(__sb, __file)		\
-{								\
-	struct list_head *list;					\
-	list = &(sb)->s_files;					\
-	list_for_each_entry((__file), list, f_u.fu_list)
-
-#define while_file_list_for_each_entry				\
-}
-
-#endif
-
-/**
- *	mark_files_ro - mark all files read-only
- *	@sb: superblock in question
- *
- *	All files are marked read-only.  We don't care about pending
- *	delete files so this should be used in 'force' mode only.
- */
-void mark_files_ro(struct super_block *sb)
-{
-	struct file *f;
-
-	lg_global_lock(&files_lglock);
-	do_file_list_for_each_entry(sb, f) {
-		if (!S_ISREG(file_inode(f)->i_mode))
-		       continue;
-		if (!file_count(f))
-			continue;
-		if (!(f->f_mode & FMODE_WRITE))
-			continue;
-		spin_lock(&f->f_lock);
-		f->f_mode &= ~FMODE_WRITE;
-		spin_unlock(&f->f_lock);
-		if (file_check_writeable(f) != 0)
-			continue;
-		__mnt_drop_write(f->f_path.mnt);
-		file_release_write(f);
-	} while_file_list_for_each_entry;
-	lg_global_unlock(&files_lglock);
-}
-
 void __init files_init(unsigned long mempages)
 { 
 	unsigned long n;
@@ -496,6 +375,5 @@ void __init files_init(unsigned long mempages)
 	n = (mempages * (PAGE_SIZE / 1024)) / 10;
 	files_stat.max_files = max_t(unsigned long, n, NR_FILE);
 	files_defer_init();
-	lg_lock_init(&files_lglock, "files_lglock");
 	percpu_counter_init(&nr_files, 0);
 } 
diff --git a/fs/internal.h b/fs/internal.h
index fc66b23..86fb264 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -76,9 +76,6 @@ extern void chroot_fs_refs(const struct path *, const struct path *);
 /*
  * file_table.c
  */
-extern void file_sb_list_add(struct file *f, struct super_block *sb);
-extern void file_sb_list_del(struct file *f);
-extern void mark_files_ro(struct super_block *);
 extern struct file *get_empty_filp(void);
 
 /*
diff --git a/fs/open.c b/fs/open.c
index f0e659b..435794f 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -700,7 +700,6 @@ static int do_dentry_open(struct file *f,
 	}
 
 	f->f_mapping = inode->i_mapping;
-	file_sb_list_add(f, inode->i_sb);
 
 	if (unlikely(f->f_mode & FMODE_PATH)) {
 		f->f_op = &empty_fops;
@@ -735,7 +734,6 @@ static int do_dentry_open(struct file *f,
 
 cleanup_all:
 	fops_put(f->f_op);
-	file_sb_list_del(f);
 	if (f->f_mode & FMODE_WRITE) {
 		put_write_access(inode);
 		if (!special_file(inode->i_mode)) {
diff --git a/fs/super.c b/fs/super.c
index bf3a8c1..519e183 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -179,19 +179,6 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
 			s = NULL;
 			goto out;
 		}
-#ifdef CONFIG_SMP
-		s->s_files = alloc_percpu(struct list_head);
-		if (!s->s_files)
-			goto err_out;
-		else {
-			int i;
-
-			for_each_possible_cpu(i)
-				INIT_LIST_HEAD(per_cpu_ptr(s->s_files, i));
-		}
-#else
-		INIT_LIST_HEAD(&s->s_files);
-#endif
 		if (init_sb_writers(s, type))
 			goto err_out;
 		s->s_flags = flags;
@@ -249,10 +236,6 @@ err_out_dentry_lru:
 	list_lru_destroy(&s->s_dentry_lru);
 err_out:
 	security_sb_free(s);
-#ifdef CONFIG_SMP
-	if (s->s_files)
-		free_percpu(s->s_files);
-#endif
 	destroy_sb_writers(s);
 	kfree(s);
 	s = NULL;
@@ -269,9 +252,6 @@ static inline void destroy_super(struct super_block *s)
 {
 	list_lru_destroy(&s->s_dentry_lru);
 	list_lru_destroy(&s->s_inode_lru);
-#ifdef CONFIG_SMP
-	free_percpu(s->s_files);
-#endif
 	destroy_sb_writers(s);
 	security_sb_free(s);
 	WARN_ON(!list_empty(&s->s_mounts));
@@ -762,7 +742,8 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
 	   make sure there are no rw files opened */
 	if (remount_ro) {
 		if (force) {
-			mark_files_ro(sb);
+			sb->s_readonly_remount = 1;
+			smp_wmb();
 		} else {
 			retval = sb_prepare_remount_readonly(sb);
 			if (retval)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 845fb6c..908f9c3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -910,9 +910,15 @@ struct file {
 	 * Must not be taken from IRQ context.
 	 */
 	spinlock_t		f_lock;
+#ifdef __GENKSYMS__
 #ifdef CONFIG_SMP
 	int			f_sb_list_cpu;
 #endif
+#else
+#ifdef CONFIG_SMP
+	int			f_sb_list_cpu_deprecated;
+#endif
+#endif
 	atomic_long_t		f_count;
 	unsigned int 		f_flags;
 	fmode_t			f_mode;
@@ -1399,11 +1405,19 @@ struct super_block {
 
 	struct list_head	s_inodes;	/* all inodes */
 	struct hlist_bl_head	s_anon;		/* anonymous dentries for (nfs) exporting */
+#ifdef __GENKSYMS__
 #ifdef CONFIG_SMP
 	struct list_head __percpu *s_files;
 #else
 	struct list_head	s_files;
 #endif
+#else
+#ifdef CONFIG_SMP
+	struct list_head __percpu *s_files_deprecated;
+#else
+	struct list_head	s_files_deprecated;
+#endif
+#endif
 	struct list_head	s_mounts;	/* list of mounts; _not_ for fs use */
 	struct block_device	*s_bdev;
 	struct backing_dev_info *s_bdi;
-- 
1.7.1




More information about the Devel mailing list