diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-11-06 22:03:00 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-11-06 22:03:00 -0500 |
commit | 4a69a41009c4ac691f7d9c289f5f37fabeddce46 (patch) | |
tree | 1dac90d2f8e4ad4114fb1f4c168925daf2769d28 /fs/btrfs/async-thread.h | |
parent | 537fb0671549a9a6457ce42a25ab34b29d97a256 (diff) |
Btrfs: Add ordered async work queues
Btrfs uses kernel threads to create async work queues for cpu intensive
operations such as checksumming and decompression. These work well,
but they make it difficult to keep IO order intact.
A single writepages call from pdflush or fsync will turn into a number
of bios, and each bio is checksummed in parallel. Once the checksum is
computed, the bio is sent down to the disk, and since we don't control
the order in which the parallel operations happen, they might go down to
the disk in almost any order.
The code deals with this somewhat by having deep work queues for a single
kernel thread, making it very likely that a single thread will process all
the bios for a single inode.
This patch introduces an explicitly ordered work queue. As work structs
are placed into the queue they are put onto the tail of a list. They have
three callbacks:
->func (cpu intensive processing here)
->ordered_func (order sensitive processing here)
->ordered_free (free the work struct, all processing is done)
The work struct has three callbacks. The func callback does the cpu intensive
work, and when it completes the work struct is marked as done.
Every time a work struct completes, the list is checked to see if the head
is marked as done. If so the ordered_func callback is used to do the
order sensitive processing and the ordered_free callback is used to do
any cleanup. Then we loop back and check the head of the list again.
This patch also changes the checksumming code to use the ordered workqueues.
One a 4 drive array, it increases streaming writes from 280MB/s to 350MB/s.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/async-thread.h')
-rw-r--r-- | fs/btrfs/async-thread.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index 4ec9a2ee0f9d..31be4ed8b63e 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h | |||
@@ -37,10 +37,16 @@ struct btrfs_worker_thread; | |||
37 | */ | 37 | */ |
38 | struct btrfs_work { | 38 | struct btrfs_work { |
39 | /* | 39 | /* |
40 | * only func should be set to the function you want called | 40 | * func should be set to the function you want called |
41 | * your work struct is passed as the only arg | 41 | * your work struct is passed as the only arg |
42 | * | ||
43 | * ordered_func must be set for work sent to an ordered work queue, | ||
44 | * and it is called to complete a given work item in the same | ||
45 | * order they were sent to the queue. | ||
42 | */ | 46 | */ |
43 | void (*func)(struct btrfs_work *work); | 47 | void (*func)(struct btrfs_work *work); |
48 | void (*ordered_func)(struct btrfs_work *work); | ||
49 | void (*ordered_free)(struct btrfs_work *work); | ||
44 | 50 | ||
45 | /* | 51 | /* |
46 | * flags should be set to zero. It is used to make sure the | 52 | * flags should be set to zero. It is used to make sure the |
@@ -51,6 +57,7 @@ struct btrfs_work { | |||
51 | /* don't touch these */ | 57 | /* don't touch these */ |
52 | struct btrfs_worker_thread *worker; | 58 | struct btrfs_worker_thread *worker; |
53 | struct list_head list; | 59 | struct list_head list; |
60 | struct list_head order_list; | ||
54 | }; | 61 | }; |
55 | 62 | ||
56 | struct btrfs_workers { | 63 | struct btrfs_workers { |
@@ -63,6 +70,9 @@ struct btrfs_workers { | |||
63 | /* once a worker has this many requests or fewer, it is idle */ | 70 | /* once a worker has this many requests or fewer, it is idle */ |
64 | int idle_thresh; | 71 | int idle_thresh; |
65 | 72 | ||
73 | /* force completions in the order they were queued */ | ||
74 | int ordered; | ||
75 | |||
66 | /* list with all the work threads. The workers on the idle thread | 76 | /* list with all the work threads. The workers on the idle thread |
67 | * may be actively servicing jobs, but they haven't yet hit the | 77 | * may be actively servicing jobs, but they haven't yet hit the |
68 | * idle thresh limit above. | 78 | * idle thresh limit above. |
@@ -70,6 +80,12 @@ struct btrfs_workers { | |||
70 | struct list_head worker_list; | 80 | struct list_head worker_list; |
71 | struct list_head idle_list; | 81 | struct list_head idle_list; |
72 | 82 | ||
83 | /* | ||
84 | * when operating in ordered mode, this maintains the list | ||
85 | * of work items waiting for completion | ||
86 | */ | ||
87 | struct list_head order_list; | ||
88 | |||
73 | /* lock for finding the next worker thread to queue on */ | 89 | /* lock for finding the next worker thread to queue on */ |
74 | spinlock_t lock; | 90 | spinlock_t lock; |
75 | 91 | ||