Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1224163 > unrolled thread
| Started by | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| First post | 2015-09-14 15:50 +0200 |
| Last post | 2015-09-14 17:30 +0200 |
| Articles | 10 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 15:50 +0200
[PATCH 1/4] fs: have flush_delayed_fput flush the workqueue job Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 15:50 +0200
[PATCH 4/4] fs: export flush_delayed_fput Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 15:50 +0200
[PATCH 3/4] fs: add fput_queue Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 16:00 +0200
Re: [PATCH 3/4] fs: add fput_queue Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 16:20 +0200
Re: [PATCH 3/4] fs: add fput_queue Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-14 18:50 +0200
Re: [PATCH 3/4] fs: add fput_queue Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 19:40 +0200
Re: [PATCH 3/4] fs: add fput_queue Al Viro <viro@ZenIV.linux.org.uk> - 2015-09-14 16:20 +0200
Re: [PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure "J. Bruce Fields" <bfields@fieldses.org> - 2015-09-14 16:50 +0200
Re: [PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure Jeff Layton <jlayton@poochiereds.net> - 2015-09-14 17:30 +0200
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 15:50 +0200 |
| Subject | [PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure |
| Message-ID | <q8CiS-7Pp-15@gated-at.bofh.it> |
I'm breaking this piece out of the open file cache work for nfsd to see if we can get this piece settled before I re-post the whole set. If this looks like a reasonable approach we can sort out how it should be merged (either by you directly, or via Bruce's tree with the rest of the open file cache patches). For those just joining in, some background: We want to add an open file cache for nfsd to reduce the open/close overhead on READ/WRITE RPCs, and so we can eliminate the raparm cache. The basic idea is to keep a cache of open files, and close them down on certain sorts of activity -- primarily, after an unlink that takes the link count to 0, or before setting a lease. The setlease part is problematic though. The plan is to have a notifier callback into nfsd from vfs_setlease that will tell nfsd to close any open files that are associated with the inode so we don't block lease attempts solely due to cached but otherwise idle nfsd files. That means that we need to be able to close out the files and ensure that the final __fput runs before we try to set a lease. My latest pass involved making __fput_sync available to userland tasks, but Al had concerns that that could lead to stack blowouts. This patchset is an alternative approach that allows userland tasks to use the delayed_fput infrastructure instead. The idea is that we'd have the pre-setlease notifier do a fput_queue() and then call flush_delayed_fput to ensure that any queued __fput() calls complete before setting the lease. There's also a fix for a potential race in flush_delayed_fput in here and some doc comment cleanups. Al, does this look more acceptable than using __fput_sync? Jeff Layton (4): fs: have flush_delayed_fput flush the workqueue job fs: add a kerneldoc header to fput fs: add fput_queue fs: export flush_delayed_fput fs/file_table.c | 57 +++++++++++++++++++++++++++++++++++++++++----------- include/linux/file.h | 1 + 2 files changed, 46 insertions(+), 12 deletions(-) -- 2.4.3 -- 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/
[toc] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 15:50 +0200 |
| Subject | [PATCH 1/4] fs: have flush_delayed_fput flush the workqueue job |
| Message-ID | <q8CiT-7Pp-29@gated-at.bofh.it> |
| In reply to | #1224163 |
I think there's a potential race in flush_delayed_fput. A kthread does
an fput() and that file gets added to the list and the delayed work is
scheduled. More than 1 jiffy passes, and the workqueue thread picks up
the work and starts running it. Then the kthread calls
flush_delayed_work. It sees that the list is empty and returns
immediately, even though the __fput for its file may not have run yet.
Close this by making flush_delayed_fput use flush_delayed_work instead,
which should immediately schedule the work to run if it's not already,
and block until the workqueue job completes.
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
---
fs/file_table.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/file_table.c b/fs/file_table.c
index 7f9d407c7595..f4833af62eae 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -243,6 +243,8 @@ static void ____fput(struct callback_head *work)
__fput(container_of(work, struct file, f_u.fu_rcuhead));
}
+static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
+
/*
* If kernel thread really needs to have the final fput() it has done
* to complete, call this. The only user right now is the boot - we
@@ -255,11 +257,9 @@ static void ____fput(struct callback_head *work)
*/
void flush_delayed_fput(void)
{
- delayed_fput(NULL);
+ flush_delayed_work(&delayed_fput_work);
}
-static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
-
void fput(struct file *file)
{
if (atomic_long_dec_and_test(&file->f_count)) {
--
2.4.3
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 15:50 +0200 |
| Subject | [PATCH 4/4] fs: export flush_delayed_fput |
| Message-ID | <q8CiT-7Pp-43@gated-at.bofh.it> |
| In reply to | #1224163 |
...and clean up the comments over it a bit.
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
---
fs/file_table.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/file_table.c b/fs/file_table.c
index 1ad2e3fd2064..2b145b513274 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -246,19 +246,19 @@ static void ____fput(struct callback_head *work)
static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
/*
- * If kernel thread really needs to have the final fput() it has done
- * to complete, call this. The only user right now is the boot - we
- * *do* need to make sure our writes to binaries on initramfs has
- * not left us with opened struct file waiting for __fput() - execve()
- * won't work without that. Please, don't add more callers without
- * very good reasons; in particular, never call that with locks
- * held and never call that from a thread that might need to do
- * some work on any kind of umount.
+ * If kernel thread or task that has used fput_queue really needs to have the
+ * final fput() it has done to complete, call this. The only user right now is
+ * the boot - we *do* need to make sure our writes to binaries on initramfs has
+ * not left us with opened struct file waiting for __fput() - execve() won't
+ * work without that. Please, don't add more callers without very good
+ * reasons; in particular, never call that with locks held and never call that
+ * from a thread that might need to do some work on any kind of umount.
*/
void flush_delayed_fput(void)
{
flush_delayed_work(&delayed_fput_work);
}
+EXPORT_SYMBOL(flush_delayed_fput);
/**
* fput - put a struct file reference
--
2.4.3
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 16:00 +0200 |
| Subject | [PATCH 3/4] fs: add fput_queue |
| Message-ID | <q8Csx-80G-3@gated-at.bofh.it> |
| In reply to | #1224163 |
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
---
fs/file_table.c | 18 ++++++++++++++++++
include/linux/file.h | 1 +
2 files changed, 19 insertions(+)
diff --git a/fs/file_table.c b/fs/file_table.c
index d63f4a399d39..1ad2e3fd2064 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -297,6 +297,24 @@ void fput(struct file *file)
}
EXPORT_SYMBOL(fput);
+/**
+ * fput_queue - do an fput without using task_work
+ * @file: file of which to put the reference
+ *
+ * If we need to ensure that the final __fput is done on a file before
+ * returning to userland, then we can't queue it to task_work. For that we
+ * borrow the infrastructure used by kthreads, and the task can then just
+ * called flush_delayed_fput to ensure that the final fput has completed.
+ */
+void fput_queue(struct file *file)
+{
+ if (atomic_long_dec_and_test(&file->f_count)) {
+ if (llist_add(&file->f_u.fu_llist, &delayed_fput_list))
+ schedule_delayed_work(&delayed_fput_work, 1);
+ }
+}
+EXPORT_SYMBOL(fput_queue);
+
/*
* synchronous analog of fput(); for kernel threads that might be needed
* in some umount() (and thus can't use flush_delayed_fput() without
diff --git a/include/linux/file.h b/include/linux/file.h
index f87d30882a24..543b0e2faf2c 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -12,6 +12,7 @@
struct file;
extern void fput(struct file *);
+extern void fput_queue(struct file *);
struct file_operations;
struct vfsmount;
--
2.4.3
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 16:20 +0200 |
| Subject | Re: [PATCH 3/4] fs: add fput_queue |
| Message-ID | <q8CLT-b7-7@gated-at.bofh.it> |
| In reply to | #1224174 |
On Mon, 14 Sep 2015 15:15:39 +0100
Al Viro <viro@ZenIV.linux.org.uk> wrote:
> On Mon, Sep 14, 2015 at 09:45:54AM -0400, Jeff Layton wrote:
> > +/**
> > + * fput_queue - do an fput without using task_work
> > + * @file: file of which to put the reference
> > + *
> > + * If we need to ensure that the final __fput is done on a file before
> > + * returning to userland, then we can't queue it to task_work. For that we
> ?????????
> > + * borrow the infrastructure used by kthreads, and the task can then just
> > + * called flush_delayed_fput to ensure that the final fput has completed.
>
> Are you sure that it's not a typo?
I don't think so, but it could be clearer. Something like this maybe?
"then we can't queue it via task_work_add."
--
Jeff Layton <jlayton@poochiereds.net>
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2015-09-14 18:50 +0200 |
| Subject | Re: [PATCH 3/4] fs: add fput_queue |
| Message-ID | <q8F75-3qM-55@gated-at.bofh.it> |
| In reply to | #1224190 |
On Mon, Sep 14, 2015 at 10:19:18AM -0400, Jeff Layton wrote: > > > + * borrow the infrastructure used by kthreads, and the task can then just > > > + * called flush_delayed_fput to ensure that the final fput has completed. > > > > Are you sure that it's not a typo? > > I don't think so, but it could be clearer. Something like this maybe? > > "then we can't queue it via task_work_add." Huh? task_work_add() callbacks *will* run before we return to userland -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 19:40 +0200 |
| Subject | Re: [PATCH 3/4] fs: add fput_queue |
| Message-ID | <q8FTs-4AL-19@gated-at.bofh.it> |
| In reply to | #1224336 |
On Mon, 14 Sep 2015 17:39:54 +0100 Al Viro <viro@ZenIV.linux.org.uk> wrote: > On Mon, Sep 14, 2015 at 10:19:18AM -0400, Jeff Layton wrote: > > > > + * borrow the infrastructure used by kthreads, and the task can then just > > > > + * called flush_delayed_fput to ensure that the final fput has completed. > > > > > > Are you sure that it's not a typo? > > > > I don't think so, but it could be clearer. Something like this maybe? > > > > "then we can't queue it via task_work_add." > > Huh? > > task_work_add() callbacks *will* run before we return to userland Right, but only just before. We need it to run before we try to set the lease in the context of a fcntl() call. How about this text instead then? I'll fix up the patch if this sounds reasonable: "When fput is called in the context of a userland process, it'll queue the actual work (__fput()) to be done just before returning to userland. In some cases however, we need to ensure that the __fput runs before that point. There is no safe way to flush work that has been queued via task_work_add however, so to do this we borrow the delayed_fput infrastructure that kthreads use. The userland process can use fput_queue() on one or more struct files and then call flush_delayed_fput() to ensure that they are completely closed." -- Jeff Layton <jlayton@poochiereds.net> -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2015-09-14 16:20 +0200 |
| Subject | Re: [PATCH 3/4] fs: add fput_queue |
| Message-ID | <q8CLT-b7-9@gated-at.bofh.it> |
| In reply to | #1224174 |
On Mon, Sep 14, 2015 at 09:45:54AM -0400, Jeff Layton wrote:
> +/**
> + * fput_queue - do an fput without using task_work
> + * @file: file of which to put the reference
> + *
> + * If we need to ensure that the final __fput is done on a file before
> + * returning to userland, then we can't queue it to task_work. For that we
?????????
> + * borrow the infrastructure used by kthreads, and the task can then just
> + * called flush_delayed_fput to ensure that the final fput has completed.
Are you sure that it's not a typo?
--
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/
[toc] | [prev] | [next] | [standalone]
| From | "J. Bruce Fields" <bfields@fieldses.org> |
|---|---|
| Date | 2015-09-14 16:50 +0200 |
| Subject | Re: [PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure |
| Message-ID | <q8DeX-Je-31@gated-at.bofh.it> |
| In reply to | #1224163 |
On Mon, Sep 14, 2015 at 09:45:51AM -0400, Jeff Layton wrote: > I'm breaking this piece out of the open file cache work for nfsd to see > if we can get this piece settled before I re-post the whole set. If this > looks like a reasonable approach we can sort out how it should be merged > (either by you directly, or via Bruce's tree with the rest of the open > file cache patches). > > For those just joining in, some background: > > We want to add an open file cache for nfsd to reduce the open/close > overhead on READ/WRITE RPCs, and so we can eliminate the raparm cache. > The basic idea is to keep a cache of open files, and close them down on > certain sorts of activity -- primarily, after an unlink that takes the > link count to 0, or before setting a lease. > > The setlease part is problematic though. The plan is to have a notifier > callback into nfsd from vfs_setlease that will tell nfsd to close any > open files that are associated with the inode so we don't block lease > attempts solely due to cached but otherwise idle nfsd files. That means > that we need to be able to close out the files and ensure that the final > __fput runs before we try to set a lease. I think I probably asked something similar before, but just to be sure I understand.... Do leases really need to be 100% reliable, or can we get away with saying "sorry, I don't feel like granting one right now". An entry in the filehandle cache suggests we're likely to recall the thing soon anyway. We use that option to get out of corner cases in the delegation case, but I don't know if it makes sense for oplocks. --b. > > My latest pass involved making __fput_sync available to userland tasks, > but Al had concerns that that could lead to stack blowouts. This > patchset is an alternative approach that allows userland tasks to use > the delayed_fput infrastructure instead. The idea is that we'd have the > pre-setlease notifier do a fput_queue() and then call flush_delayed_fput > to ensure that any queued __fput() calls complete before setting the > lease. > > There's also a fix for a potential race in flush_delayed_fput in here > and some doc comment cleanups. > > Al, does this look more acceptable than using __fput_sync? > > Jeff Layton (4): > fs: have flush_delayed_fput flush the workqueue job > fs: add a kerneldoc header to fput > fs: add fput_queue > fs: export flush_delayed_fput > > fs/file_table.c | 57 +++++++++++++++++++++++++++++++++++++++++----------- > include/linux/file.h | 1 + > 2 files changed, 46 insertions(+), 12 deletions(-) > > -- > 2.4.3 -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@poochiereds.net> |
|---|---|
| Date | 2015-09-14 17:30 +0200 |
| Subject | Re: [PATCH 0/4] fs: allow userland tasks to use delayed_fput infrastructure |
| Message-ID | <q8DRE-1Is-25@gated-at.bofh.it> |
| In reply to | #1224212 |
On Mon, 14 Sep 2015 10:48:37 -0400 "J. Bruce Fields" <bfields@fieldses.org> wrote: > On Mon, Sep 14, 2015 at 09:45:51AM -0400, Jeff Layton wrote: > > I'm breaking this piece out of the open file cache work for nfsd to see > > if we can get this piece settled before I re-post the whole set. If this > > looks like a reasonable approach we can sort out how it should be merged > > (either by you directly, or via Bruce's tree with the rest of the open > > file cache patches). > > > > For those just joining in, some background: > > > > We want to add an open file cache for nfsd to reduce the open/close > > overhead on READ/WRITE RPCs, and so we can eliminate the raparm cache. > > The basic idea is to keep a cache of open files, and close them down on > > certain sorts of activity -- primarily, after an unlink that takes the > > link count to 0, or before setting a lease. > > > > The setlease part is problematic though. The plan is to have a notifier > > callback into nfsd from vfs_setlease that will tell nfsd to close any > > open files that are associated with the inode so we don't block lease > > attempts solely due to cached but otherwise idle nfsd files. That means > > that we need to be able to close out the files and ensure that the final > > __fput runs before we try to set a lease. > > I think I probably asked something similar before, but just to be sure I > understand.... Do leases really need to be 100% reliable, or can we get > away with saying "sorry, I don't feel like granting one right now". An > entry in the filehandle cache suggests we're likely to recall the thing > soon anyway. We use that option to get out of corner cases in the > delegation case, but I don't know if it makes sense for oplocks. > They don't need to be 100% reliable, but with the current design nfsd will hold files open in the cache indefinitely, until one of the following events occurs: 1) the exports cache is flushed (which is always done after unexporting) 2) an unlink event occurs that drops the i_nlink count to zero 3) userland attempts to set a lease 4) the shrinker kicks in 5) nfsd is shut down So you could easily have a situation where a NFSv3 client does some WRITE activity, and then an hour later samba comes along and asks for a lease. I don't think we'd want to block the lease in that situation as there's no reason to believe that we'd end up recalling it anytime soon. The NFS client may be long gone at that point. We could implement some heuristic that proactively closes out open files that are idle for a certain amount of time. My first pass did just that actually, but Christoph didn't much care for it, and I think he was right. That's not as good a design as just keeping them open until there's a real reason to close them. -- Jeff Layton <jlayton@poochiereds.net> -- 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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web