diff options
author | David Howells <dhowells@redhat.com> | 2009-04-03 11:42:35 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2009-04-03 11:42:35 -0400 |
commit | 07fe7cb7c7c179f473fd9c823348fd3eb5dad369 (patch) | |
tree | 516c959de929a4c39870629e550b3307601fa73f /include/linux/slow-work.h | |
parent | 8fe74cf053de7ad2124a894996f84fa890a81093 (diff) |
Create a dynamically sized pool of threads for doing very slow work items
Create a dynamically sized pool of threads for doing very slow work items, such
as invoking mkdir() or rmdir() - things that may take a long time and may
sleep, holding mutexes/semaphores and hogging a thread, and are thus unsuitable
for workqueues.
The number of threads is always at least a settable minimum, but more are
started when there's more work to do, up to a limit. Because of the nature of
the load, it's not suitable for a 1-thread-per-CPU type pool. A system with
one CPU may well want several threads.
This is used by FS-Cache to do slow caching operations in the background, such
as looking up, creating or deleting cache objects.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Steve Dickson <steved@redhat.com>
Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Tested-by: Daire Byrne <Daire.Byrne@framestore.com>
Diffstat (limited to 'include/linux/slow-work.h')
-rw-r--r-- | include/linux/slow-work.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/include/linux/slow-work.h b/include/linux/slow-work.h new file mode 100644 index 000000000000..4dd754af393e --- /dev/null +++ b/include/linux/slow-work.h | |||
@@ -0,0 +1,88 @@ | |||
1 | /* Worker thread pool for slow items, such as filesystem lookups or mkdirs | ||
2 | * | ||
3 | * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. | ||
4 | * Written by David Howells (dhowells@redhat.com) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public Licence | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the Licence, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef _LINUX_SLOW_WORK_H | ||
13 | #define _LINUX_SLOW_WORK_H | ||
14 | |||
15 | #ifdef CONFIG_SLOW_WORK | ||
16 | |||
17 | struct slow_work; | ||
18 | |||
19 | /* | ||
20 | * The operations used to support slow work items | ||
21 | */ | ||
22 | struct slow_work_ops { | ||
23 | /* get a ref on a work item | ||
24 | * - return 0 if successful, -ve if not | ||
25 | */ | ||
26 | int (*get_ref)(struct slow_work *work); | ||
27 | |||
28 | /* discard a ref to a work item */ | ||
29 | void (*put_ref)(struct slow_work *work); | ||
30 | |||
31 | /* execute a work item */ | ||
32 | void (*execute)(struct slow_work *work); | ||
33 | }; | ||
34 | |||
35 | /* | ||
36 | * A slow work item | ||
37 | * - A reference is held on the parent object by the thread pool when it is | ||
38 | * queued | ||
39 | */ | ||
40 | struct slow_work { | ||
41 | unsigned long flags; | ||
42 | #define SLOW_WORK_PENDING 0 /* item pending (further) execution */ | ||
43 | #define SLOW_WORK_EXECUTING 1 /* item currently executing */ | ||
44 | #define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */ | ||
45 | #define SLOW_WORK_VERY_SLOW 3 /* item is very slow */ | ||
46 | const struct slow_work_ops *ops; /* operations table for this item */ | ||
47 | struct list_head link; /* link in queue */ | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * slow_work_init - Initialise a slow work item | ||
52 | * @work: The work item to initialise | ||
53 | * @ops: The operations to use to handle the slow work item | ||
54 | * | ||
55 | * Initialise a slow work item. | ||
56 | */ | ||
57 | static inline void slow_work_init(struct slow_work *work, | ||
58 | const struct slow_work_ops *ops) | ||
59 | { | ||
60 | work->flags = 0; | ||
61 | work->ops = ops; | ||
62 | INIT_LIST_HEAD(&work->link); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * slow_work_init - Initialise a very slow work item | ||
67 | * @work: The work item to initialise | ||
68 | * @ops: The operations to use to handle the slow work item | ||
69 | * | ||
70 | * Initialise a very slow work item. This item will be restricted such that | ||
71 | * only a certain number of the pool threads will be able to execute items of | ||
72 | * this type. | ||
73 | */ | ||
74 | static inline void vslow_work_init(struct slow_work *work, | ||
75 | const struct slow_work_ops *ops) | ||
76 | { | ||
77 | work->flags = 1 << SLOW_WORK_VERY_SLOW; | ||
78 | work->ops = ops; | ||
79 | INIT_LIST_HEAD(&work->link); | ||
80 | } | ||
81 | |||
82 | extern int slow_work_enqueue(struct slow_work *work); | ||
83 | extern int slow_work_register_user(void); | ||
84 | extern void slow_work_unregister_user(void); | ||
85 | |||
86 | |||
87 | #endif /* CONFIG_SLOW_WORK */ | ||
88 | #endif /* _LINUX_SLOW_WORK_H */ | ||