Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1220184
| From | Oleg Nesterov <oleg@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH? v2] fput: don't abuse task_work_add() too much |
| Date | 2015-09-07 16:00 +0200 |
| Message-ID | <q657I-7lU-17@gated-at.bofh.it> (permalink) |
| References | <q2Enn-5vz-5@gated-at.bofh.it> <q2NTI-2fK-9@gated-at.bofh.it> <q5emJ-83l-3@gated-at.bofh.it> <q63Sj-5E0-49@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 09/07, Oleg Nesterov wrote:
>
> Oh, I disagree. But I guess I can't convince you/Eric/Linus, so I have
> to shut up.
>
>
> Damn. But I can't relax ;) Al, Linus, could you comment the patch below?
>
> Not for inclusion, lacks the changelog/testing, fput() can be simplified.
> But as you can see it is simple. With this patch task_work_add(____fput)
> will be called only once by (say) do_exit() path. ->fput_list does not
> need any serialization / atomic ops / etc. Probably we also need to move
> cond_resched() from task_work_run() to ____fput() after this patch.
>
> Again, it is not that I think this actually makes sense, but since you
> dislike these 275ms...
>
> What do you think?
Yes, task_struct->fput_list is ugly. We can avoid it, but then we need
another ->next pointer in struct file. Perhaps we can reuse ->f_version?
This way the change looks really simple and not too bad to me. Although
I am not sure you will agree.
Oleg.
---
diff --git a/fs/file_table.c b/fs/file_table.c
index 294174d..c34b666 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -241,7 +241,15 @@ static void delayed_fput(struct work_struct *unused)
static void ____fput(struct callback_head *work)
{
- __fput(container_of(work, struct file, f_u.fu_rcuhead));
+ struct file *file = container_of(work, struct file, f_u.fu_rcuhead);
+ struct file *next;
+
+ do {
+ next = file->f_next_put;
+ __fput(file);
+ file = next;
+
+ } while (file);
}
/*
@@ -267,9 +275,21 @@ void fput(struct file *file)
struct task_struct *task = current;
if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
+ struct callback_head *work = READ_ONCE(task->task_works);
+ struct file *prev;
+
+ if (work && work->func == ____fput) {
+ prev = container_of(work, struct file, f_u.fu_rcuhead);
+ file->f_next_put = prev->f_next_put;
+ prev->f_next_put = file;
+ return;
+ }
+
init_task_work(&file->f_u.fu_rcuhead, ____fput);
- if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
+ if (!task_work_add(task, &file->f_u.fu_rcuhead, true)) {
+ file->f_next_put = NULL;
return;
+ }
/*
* After this task has run exit_task_work(),
* task_work_add() will fail. Fall through to delayed
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0774487..9381527 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -849,7 +849,10 @@ struct file {
const struct cred *f_cred;
struct file_ra_state f_ra;
- u64 f_version;
+ union {
+ u64 f_version;
+ struct file *f_next_put;
+ };
#ifdef CONFIG_SECURITY
void *f_security;
#endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH] task_work: remove fifo ordering guarantee Eric Dumazet <eric.dumazet@gmail.com> - 2015-08-29 04:50 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Linus Torvalds <torvalds@linux-foundation.org> - 2015-08-29 05:20 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Ingo Molnar <mingo@kernel.org> - 2015-08-29 11:30 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Oleg Nesterov <oleg@redhat.com> - 2015-08-29 15:00 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Ingo Molnar <mingo@kernel.org> - 2015-08-31 08:10 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Oleg Nesterov <oleg@redhat.com> - 2015-08-31 15:00 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Oleg Nesterov <oleg@redhat.com> - 2015-08-29 15:00 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Eric Dumazet <eric.dumazet@gmail.com> - 2015-08-29 16:00 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Eric Dumazet <eric.dumazet@gmail.com> - 2015-08-29 16:20 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Linus Torvalds <torvalds@linux-foundation.org> - 2015-08-29 19:10 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee yalin wang <yalin.wang2010@gmail.com> - 2015-08-31 07:30 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-05 07:20 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Oleg Nesterov <oleg@redhat.com> - 2015-08-31 14:50 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-05 07:20 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-05 07:50 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-05 22:50 +0200
change filp_close() to use __fput_sync() ? (Was: [PATCH] task_work: remove fifo ordering guarantee) Oleg Nesterov <oleg@redhat.com> - 2015-08-31 14:10 +0200
Re: [PATCH] task_work: remove fifo ordering guarantee Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-05 07:40 +0200
[PATCH?] fput: don't abuse task_work_add() too much Oleg Nesterov <oleg@redhat.com> - 2015-09-07 14:40 +0200
[PATCH? v2] fput: don't abuse task_work_add() too much Oleg Nesterov <oleg@redhat.com> - 2015-09-07 16:00 +0200
csiph-web