Skip to contentSkip to conversation

2.5.22 add __fput for aio

PATCH In review Benjamin LaHaise 4 participants 6 messages Jun 17, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.5.22 add __fput for aio

Hello Linus,

This patch splits fput into fput and __fput. __fput is needed by aio to construct a mechanism for performing fput during io completion, which typically occurs during interrupt context.

-ben

Signature · 74 lines
"You will be reincarnated as a toad; and you will be much happier."

diff -urN v2.5.22/fs/file_table.c fput-v2.5.22/fs/file_table.c
--- v2.5.22/fs/file_table.c	Thu Jun  6 00:35:32 2002
+++ fput-v2.5.22/fs/file_table.c	Mon Jun 17 15:43:10 2002
@@ -100,31 +100,38 @@
 
 void fput(struct file * file)
 {
+	if (atomic_dec_and_test(&file->f_count))
+		__fput(file);
+}
+
+/* __fput is needed for aio, which provides a mechanism for doing fput 
+ * from an interrupt handler.
+ */
+void __fput(struct file * file)
+{
 	struct dentry * dentry = file->f_dentry;
 	struct vfsmount * mnt = file->f_vfsmnt;
 	struct inode * inode = dentry->d_inode;
 
-	if (atomic_dec_and_test(&file->f_count)) {
-		locks_remove_flock(file);
+	locks_remove_flock(file);
 
-		if (file->f_iobuf)
-			free_kiovec(1, &file->f_iobuf);
+	if (file->f_iobuf)
+		free_kiovec(1, &file->f_iobuf);
 
-		if (file->f_op && file->f_op->release)
-			file->f_op->release(inode, file);
-		fops_put(file->f_op);
-		if (file->f_mode & FMODE_WRITE)
-			put_write_access(inode);
-		file_list_lock();
-		file->f_dentry = NULL;
-		file->f_vfsmnt = NULL;
-		list_del(&file->f_list);
-		list_add(&file->f_list, &free_list);
-		files_stat.nr_free_files++;
-		file_list_unlock();
-		dput(dentry);
-		mntput(mnt);
-	}
+	if (file->f_op && file->f_op->release)
+		file->f_op->release(inode, file);
+	fops_put(file->f_op);
+	if (file->f_mode & FMODE_WRITE)
+		put_write_access(inode);
+	file_list_lock();
+	file->f_dentry = NULL;
+	file->f_vfsmnt = NULL;
+	list_del(&file->f_list);
+	list_add(&file->f_list, &free_list);
+	files_stat.nr_free_files++;
+	file_list_unlock();
+	dput(dentry);
+	mntput(mnt);
 }
 
 struct file * fget(unsigned int fd)
diff -urN v2.5.22/include/linux/file.h fput-v2.5.22/include/linux/file.h
--- v2.5.22/include/linux/file.h	Thu Jun  6 00:35:16 2002
+++ fput-v2.5.22/include/linux/file.h	Mon Jun 17 15:43:11 2002
@@ -33,6 +33,7 @@
         struct file * fd_array[NR_OPEN_DEFAULT];
 };
 
+extern void FASTCALL(__fput(struct file *));
 extern void FASTCALL(fput(struct file *));
 extern struct file * FASTCALL(fget(unsigned int fd));
 extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag));
#1 lore raw
Quoted 4 lines · Benjamin LaHaise

This patch splits fput into fput and __fput. __fput is needed by aio to construct a mechanism for performing fput during io completion, which typically occurs during interrupt context.

Ehh. Since you _cannot_ do __fput() from an interrupt context, something is broken.

Possibly the comments.

If aio calls down to __fput() from an interrupt context, then aio is clearly broken. Yet that's what the comments seem to imply.

The other alternative is that aio only does the book-keeping from interrupt context, adds the "struct file * to be freed" to some list of freeable files, and then does __fput() from _non_interrupt_ context on those files.

Is that was aio actually _does_?

If so, the code may be fine, but the comments are misleading crap and should be fixed asap.

Linus

#2 lore raw
Quoted 6 lines · Linus Torvalds

The other alternative is that aio only does the book-keeping from interrupt context, adds the "struct file * to be freed" to some list of freeable files, and then does __fput() from _non_interrupt_ context on those files.

Is that was aio actually _does_?

Yes -- aio does the atomic_dec_and_test in the interrupt handler, and if that was the last user of the struct file *, it queues the io handle for cleanup from task context.

Quoted 2 lines

If so, the code may be fine, but the comments are misleading crap and should be fixed asap.

Sure. How's changing it to:

+/* __fput is called from task task when aio completion releases the last
+ * use of a struct file *. Do not use otherwise.
+ */

instead?

-ben

Signature · 1 line
"You will be reincarnated as a toad; and you will be much happier."
#3 lore raw
Quoted 8 lines · Benjamin LaHaise

Sure. How's changing it to:

+/* __fput is called from task task when aio completion releases the last
+ * use of a struct file *. Do not use otherwise.
+ */

instead?

Much better.

Linus

#4 lore raw

Dynamic Timer

I have two questions about dynamic timer in Linux:
1. Kernel space: After add_timer is used, where is the code used to poll the global 'struct timer_list' to activate the related functions on time? It's not in sched.c, is it in tasklet/bh?
2. User space: is there a way to set a dynamic timer in userspace as well, such as create_timer(posix, not in Linux)?

TIA

XH Xiao

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

#5 lore raw

Re: Dynamic Timer

Quoted 6 lines · X.Xiao

I have two questions about dynamic timer in Linux:
1. Kernel space: After add_timer is used, where is the code used to poll the global 'struct timer_list' to activate the related functions on time? It's not in sched.c, is it in tasklet/bh?

The "code" is in timer.c (same place you found "add_timer()) and is called run_timer_list(). It is called by timer_bh() also in timer.c, which is scheduled by do_timer() (also in timer.c) which is called each timer interrupt by code in the arch/kernel/ area (in i386 it is time.c) which, in turn is called by the interrupt code.

Quoted 3 lines

2. User space: is there a way to set a dynamic timer in userspace as well, such as create_timer(posix, not in Linux)?

The tried and true way is the setitimer() call. The POSIX calls are also available as a patch from the high-res-timers project (see signature).

Signature · 6 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml