Skip to content

Commit

Permalink
block:fix for 4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabug123 authored and acuicultor committed Aug 30, 2021
1 parent 1f623e0 commit b69eef3
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions block/tripndroid-iosched.c
Expand Up @@ -24,14 +24,13 @@

enum { ASYNC, SYNC };

static const int sync_read_expire = 1 * HZ; /* max time before a sync read is submitted. */
static const int sync_write_expire = 1 * HZ; /* max time before a sync write is submitted. */
static const int async_read_expire = 2 * HZ; /* ditto for async, these limits are SOFT! */
static const int async_write_expire = 2 * HZ; /* ditto for async, these limits are SOFT! */
static const int sync_read_expire = HZ / 3; /* max time before a sync read is submitted. */
static const int sync_write_expire = 2 * HZ; /* max time before a sync write is submitted. */
static const int async_read_expire = HZ / 6; /* ditto for async, these limits are SOFT! */
static const int async_write_expire = 4 * HZ; /* ditto for async, these limits are SOFT! */

static const int writes_starved = 1; /* max times reads can starve a write */
static const int fifo_batch = 1; /* # of sequential requests treated as one
by the above parameters. For throughput. */
static const int fifo_batch = 3; /* sequential requests treated as one, for throughput. */

struct tripndroid_data {

Expand All @@ -53,9 +52,9 @@ static void tripndroid_merged_requests(struct request_queue *q, struct request *
* and move into next position (next will be deleted) in fifo.
*/
if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist)) {
if (time_before(rq_fifo_time(next), rq_fifo_time(rq))) {
if (time_before((unsigned long)next->fifo_time, (unsigned long)rq->fifo_time)) {
list_move(&rq->queuelist, &next->queuelist);
rq_set_fifo_time(rq, rq_fifo_time(next));
rq->fifo_time = next->fifo_time;
}
}

Expand All @@ -68,7 +67,7 @@ static void tripndroid_add_request(struct request_queue *q, struct request *rq)
const int sync = rq_is_sync(rq);
const int data_dir = rq_data_dir(rq);

rq_set_fifo_time(rq, jiffies + td->fifo_expire[sync][data_dir]);
rq->fifo_time = jiffies + td->fifo_expire[sync][data_dir];
list_add(&rq->queuelist, &td->fifo_list[sync][data_dir]);
}

Expand All @@ -82,7 +81,7 @@ static struct request *tripndroid_expired_request(struct tripndroid_data *td, in

rq = rq_entry_fifo(list->next);

if (time_after_eq(jiffies, rq_fifo_time(rq)))
if (time_after_eq(jiffies, (unsigned long)rq->fifo_time))
return rq;

return NULL;
Expand All @@ -92,20 +91,18 @@ static struct request *tripndroid_choose_expired_request(struct tripndroid_data
{
struct request *rq;

/* Asynchronous requests have priority over synchronous.
* Write requests have priority over read. */

rq = tripndroid_expired_request(td, ASYNC, WRITE);
/* synchronous priority over asynchronous, write priority over read. */
rq = tripndroid_expired_request(td, SYNC, WRITE);
if (rq)
return rq;
rq = tripndroid_expired_request(td, ASYNC, READ);
rq = tripndroid_expired_request(td, SYNC, READ);
if (rq)
return rq;

rq = tripndroid_expired_request(td, SYNC, WRITE);
rq = tripndroid_expired_request(td, ASYNC, WRITE);
if (rq)
return rq;
rq = tripndroid_expired_request(td, SYNC, READ);
rq = tripndroid_expired_request(td, ASYNC, READ);
if (rq)
return rq;

Expand Down Expand Up @@ -193,13 +190,21 @@ static struct request *tripndroid_latter_request(struct request_queue *q, struct
return list_entry(rq->queuelist.next, struct request, queuelist);
}

static void *tripndroid_init_queue(struct request_queue *q)
static int tripndroid_init_queue(struct request_queue *q, struct elevator_type *e)
{
struct tripndroid_data *td;
struct elevator_queue *eq;

td = kmalloc_node(sizeof(*td), GFP_KERNEL, q->node);
if (!td)
return NULL;
eq = elevator_alloc(q, e);
if (!eq)
return -ENOMEM;

td = kzalloc_node(sizeof(*td), GFP_KERNEL | __GFP_ZERO, q->node);
if (!td) {
kobject_put(&eq->kobj);
return -ENOMEM;
}
eq->elevator_data = td;

INIT_LIST_HEAD(&td->fifo_list[SYNC][READ]);
INIT_LIST_HEAD(&td->fifo_list[SYNC][WRITE]);
Expand All @@ -213,7 +218,11 @@ static void *tripndroid_init_queue(struct request_queue *q)
td->fifo_expire[ASYNC][WRITE] = async_write_expire;
td->fifo_batch = fifo_batch;

return td;
spin_lock_irq(q->queue_lock);
q->elevator = eq;
spin_unlock_irq(q->queue_lock);

return 0;
}

static void tripndroid_exit_queue(struct elevator_queue *e)
Expand All @@ -229,7 +238,7 @@ static void tripndroid_exit_queue(struct elevator_queue *e)
}

static struct elevator_type iosched_tripndroid = {
.ops = {
.ops.sq = {
.elevator_merge_req_fn = tripndroid_merged_requests,
.elevator_dispatch_fn = tripndroid_dispatch_requests,
.elevator_add_req_fn = tripndroid_add_request,
Expand Down

0 comments on commit b69eef3

Please sign in to comment.