Skip to content

Commit db37a34

Browse files
Algodev-githubaxboe
authored andcommitted
block, bfq: get a ref to a group when adding it to a service tree
BFQ schedules generic entities, which may represent either bfq_queues or groups of bfq_queues. When an entity is inserted into a service tree, a reference must be taken, to make sure that the entity does not disappear while still referred in the tree. Unfortunately, such a reference is mistakenly taken only if the entity represents a bfq_queue. This commit takes a reference also in case the entity represents a group. Tested-by: Oleksandr Natalenko <[email protected]> Tested-by: Chris Evich <[email protected]> Signed-off-by: Paolo Valente <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4d8340d commit db37a34

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

block/bfq-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static void bfqg_put(struct bfq_group *bfqg)
332332
kfree(bfqg);
333333
}
334334

335-
static void bfqg_and_blkg_get(struct bfq_group *bfqg)
335+
void bfqg_and_blkg_get(struct bfq_group *bfqg)
336336
{
337337
/* see comments in bfq_bic_update_cgroup for why refcounting bfqg */
338338
bfqg_get(bfqg);

block/bfq-iosched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
985985
struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg);
986986
struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
987987
struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node);
988+
void bfqg_and_blkg_get(struct bfq_group *bfqg);
988989
void bfqg_and_blkg_put(struct bfq_group *bfqg);
989990

990991
#ifdef CONFIG_BFQ_GROUP_IOSCHED

block/bfq-wf2q.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ static void bfq_get_entity(struct bfq_entity *entity)
533533
bfqq->ref++;
534534
bfq_log_bfqq(bfqq->bfqd, bfqq, "get_entity: %p %d",
535535
bfqq, bfqq->ref);
536-
}
536+
} else
537+
bfqg_and_blkg_get(container_of(entity, struct bfq_group,
538+
entity));
537539
}
538540

539541
/**
@@ -647,8 +649,14 @@ static void bfq_forget_entity(struct bfq_service_tree *st,
647649

648650
entity->on_st_or_in_serv = false;
649651
st->wsum -= entity->weight;
650-
if (bfqq && !is_in_service)
652+
if (is_in_service)
653+
return;
654+
655+
if (bfqq)
651656
bfq_put_queue(bfqq);
657+
else
658+
bfqg_and_blkg_put(container_of(entity, struct bfq_group,
659+
entity));
652660
}
653661

654662
/**

0 commit comments

Comments
 (0)