projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
zbd: Avoid async I/O multi-job workload deadlock
[fio.git]
/
flow.c
diff --git
a/flow.c
b/flow.c
index e5c4a40462ceb5e6e94bebcf3534016ebf6091a4..a8dbfb9bb48e66a991953810d2c25d92eeeacb54 100644
(file)
--- a/
flow.c
+++ b/
flow.c
@@
-1,5
+1,5
@@
#include "fio.h"
#include "fio.h"
-#include "
mutex
.h"
+#include "
fio_sem
.h"
#include "smalloc.h"
#include "flist.h"
#include "smalloc.h"
#include "flist.h"
@@
-11,20
+11,27
@@
struct fio_flow {
};
static struct flist_head *flow_list;
};
static struct flist_head *flow_list;
-static struct fio_
mutex
*flow_lock;
+static struct fio_
sem
*flow_lock;
int flow_threshold_exceeded(struct thread_data *td)
{
struct fio_flow *flow = td->flow;
int flow_threshold_exceeded(struct thread_data *td)
{
struct fio_flow *flow = td->flow;
-
int sign
;
+
long long flow_counter
;
if (!flow)
return 0;
if (!flow)
return 0;
- sign = td->o.flow > 0 ? 1 : -1;
- if (sign * flow->flow_counter > td->o.flow_watermark) {
- if (td->o.flow_sleep)
+ if (td->o.flow > 0)
+ flow_counter = flow->flow_counter;
+ else
+ flow_counter = -flow->flow_counter;
+
+ if (flow_counter > td->o.flow_watermark) {
+ if (td->o.flow_sleep) {
+ io_u_quiesce(td);
usleep(td->o.flow_sleep);
usleep(td->o.flow_sleep);
+ }
+
return 1;
}
return 1;
}
@@
-36,10
+43,13
@@
int flow_threshold_exceeded(struct thread_data *td)
static struct fio_flow *flow_get(unsigned int id)
{
static struct fio_flow *flow_get(unsigned int id)
{
- struct fio_flow *flow;
+ struct fio_flow *flow
= NULL
;
struct flist_head *n;
struct flist_head *n;
- fio_mutex_down(flow_lock);
+ if (!flow_lock)
+ return NULL;
+
+ fio_sem_down(flow_lock);
flist_for_each(n, flow_list) {
flow = flist_entry(n, struct fio_flow, list);
flist_for_each(n, flow_list) {
flow = flist_entry(n, struct fio_flow, list);
@@
-51,6
+61,10
@@
static struct fio_flow *flow_get(unsigned int id)
if (!flow) {
flow = smalloc(sizeof(*flow));
if (!flow) {
flow = smalloc(sizeof(*flow));
+ if (!flow) {
+ fio_sem_up(flow_lock);
+ return NULL;
+ }
flow->refs = 0;
INIT_FLIST_HEAD(&flow->list);
flow->id = id;
flow->refs = 0;
INIT_FLIST_HEAD(&flow->list);
flow->id = id;
@@
-60,20
+74,23
@@
static struct fio_flow *flow_get(unsigned int id)
}
flow->refs++;
}
flow->refs++;
- fio_
mutex
_up(flow_lock);
+ fio_
sem
_up(flow_lock);
return flow;
}
static void flow_put(struct fio_flow *flow)
{
return flow;
}
static void flow_put(struct fio_flow *flow)
{
- fio_mutex_down(flow_lock);
+ if (!flow_lock)
+ return;
+
+ fio_sem_down(flow_lock);
if (!--flow->refs) {
flist_del(&flow->list);
sfree(flow);
}
if (!--flow->refs) {
flist_del(&flow->list);
sfree(flow);
}
- fio_
mutex
_up(flow_lock);
+ fio_
sem
_up(flow_lock);
}
void flow_init_job(struct thread_data *td)
}
void flow_init_job(struct thread_data *td)
@@
-92,13
+109,26
@@
void flow_exit_job(struct thread_data *td)
void flow_init(void)
{
void flow_init(void)
{
- flow_lock = fio_mutex_init(1);
flow_list = smalloc(sizeof(*flow_list));
flow_list = smalloc(sizeof(*flow_list));
+ if (!flow_list) {
+ log_err("fio: smalloc pool exhausted\n");
+ return;
+ }
+
+ flow_lock = fio_sem_init(FIO_SEM_UNLOCKED);
+ if (!flow_lock) {
+ log_err("fio: failed to allocate flow lock\n");
+ sfree(flow_list);
+ return;
+ }
+
INIT_FLIST_HEAD(flow_list);
}
void flow_exit(void)
{
INIT_FLIST_HEAD(flow_list);
}
void flow_exit(void)
{
- fio_mutex_remove(flow_lock);
- sfree(flow_list);
+ if (flow_lock)
+ fio_sem_remove(flow_lock);
+ if (flow_list)
+ sfree(flow_list);
}
}