-
Notifications
You must be signed in to change notification settings - Fork 4
/
block-comment-for-block-and-drivers-for-linux-5.0-rc4.patch
2929 lines (2718 loc) · 113 KB
/
block-comment-for-block-and-drivers-for-linux-5.0-rc4.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 67c41fd477356f6bae2968bda0b9a52123858773 Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Thu, 14 Feb 2019 06:26:02 +0800
Subject: [PATCH 1/1] block comment for block and drivers for linux-5.0-rc4
Signed-off-by: Dongli Zhang <[email protected]>
---
block/blk-flush.c | 45 ++++
block/blk-merge.c | 4 +
block/blk-mq-cpumap.c | 18 ++
block/blk-mq-debugfs.c | 16 ++
block/blk-mq-pci.c | 6 +
block/blk-mq-sched.c | 106 ++++++++
block/blk-mq-sched.h | 4 +
block/blk-mq-sysfs.c | 45 ++++
block/blk-mq-tag.c | 24 ++
block/blk-mq-tag.h | 34 +++
block/blk-mq-virtio.c | 5 +
block/blk-mq.c | 696 +++++++++++++++++++++++++++++++++++++++++++++++++
block/blk-mq.h | 68 +++++
block/blk-settings.c | 9 +
block/elevator.c | 16 ++
include/linux/blk-mq.h | 227 ++++++++++++++++
include/linux/blkdev.h | 80 ++++++
17 files changed, 1403 insertions(+)
diff --git a/block/blk-flush.c b/block/blk-flush.c
index a3fc719..acbd420 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -96,6 +96,10 @@ enum {
static void blk_kick_flush(struct request_queue *q,
struct blk_flush_queue *fq, unsigned int flags);
+/*
+ * called by:
+ * - block/blk-flush.c|354| <<blk_insert_flush>> unsigned int policy = blk_flush_policy(fflags, rq);
+ */
static unsigned int blk_flush_policy(unsigned long fflags, struct request *rq)
{
unsigned int policy = 0;
@@ -132,6 +136,11 @@ static void blk_flush_restore_request(struct request *rq)
rq->end_io = rq->flush.saved_end_io;
}
+/*
+ * called by:
+ * - block/blk-flush.c|184| <<blk_flush_complete_seq>> blk_flush_queue_rq(rq, true);
+ * - block/blk-flush.c|314| <<blk_kick_flush>> blk_flush_queue_rq(flush_rq, false);
+ */
static void blk_flush_queue_rq(struct request *rq, bool add_front)
{
blk_mq_add_to_requeue_list(rq, add_front, true);
@@ -255,6 +264,10 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
* spin_lock_irq(fq->mq_flush_lock)
*
*/
+/*
+ * called by:
+ * - block/blk-flush.c|204| <<blk_flush_complete_seq>> blk_kick_flush(q, fq, cmd_flags);
+ */
static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
unsigned int flags)
{
@@ -347,6 +360,11 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
* @rq is being submitted. Analyze what needs to be done and put it on the
* right queue.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|461| <<blk_mq_sched_insert_request>> blk_insert_flush(rq);
+ * - block/blk-mq.c|2260| <<blk_mq_make_request>> blk_insert_flush(rq);
+ */
void blk_insert_flush(struct request *rq)
{
struct request_queue *q = rq->q;
@@ -420,6 +438,29 @@ void blk_insert_flush(struct request *rq)
* room for storing the error offset in case of a flush error, if they
* wish to.
*/
+/*
+ * called by:
+ * - drivers/md/dm-zoned-metadata.c|647| <<dmz_write_sb>> ret = blkdev_issue_flush(zmd->dev->bdev, GFP_NOIO, NULL);
+ * - drivers/md/dm-zoned-metadata.c|681| <<dmz_write_dirty_mblocks>> ret = blkdev_issue_flush(zmd->dev->bdev, GFP_NOIO, NULL);
+ * - drivers/md/dm-zoned-metadata.c|745| <<dmz_flush_metadata>> ret = blkdev_issue_flush(zmd->dev->bdev, GFP_NOIO, NULL);
+ * - drivers/md/raid5-ppl.c|1045| <<ppl_recover>> ret = blkdev_issue_flush(rdev->bdev, GFP_KERNEL, NULL);
+ * - drivers/nvme/target/io-cmd-bdev.c|190| <<nvmet_bdev_flush>> if (blkdev_issue_flush(req->ns->bdev, GFP_KERNEL, NULL))
+ * - fs/block_dev.c|670| <<blkdev_fsync>> error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
+ * - fs/ext4/fsync.c|162| <<ext4_sync_file>> err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/ext4/ialloc.c|1427| <<ext4_init_inode_table>> blkdev_issue_flush(sb->s_bdev, GFP_NOFS, NULL);
+ * - fs/ext4/super.c|5052| <<ext4_sync_fs>> err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/hfsplus/inode.c|343| <<hfsplus_file_fsync>> blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/hfsplus/super.c|241| <<hfsplus_sync_fs>> blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/jbd2/checkpoint.c|405| <<jbd2_cleanup_journal_tail>> blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
+ * - fs/jbd2/commit.c|768| <<jbd2_journal_commit_transaction>> blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
+ * - fs/jbd2/commit.c|872| <<jbd2_journal_commit_transaction>> blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL);
+ * - fs/jbd2/recovery.c|289| <<jbd2_journal_recover>> err2 = blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
+ * - fs/libfs.c|1021| <<generic_file_fsync>> return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/nilfs2/the_nilfs.h|378| <<nilfs_flush_device>> err = blkdev_issue_flush(nilfs->ns_bdev, GFP_KERNEL, NULL);
+ * - fs/ocfs2/file.c|211| <<ocfs2_sync_file>> ret = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/reiserfs/file.c|168| <<reiserfs_sync_file>> blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/xfs/xfs_super.c|684| <<xfs_blkdev_issue_flush>> blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
+ */
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
sector_t *error_sector)
{
@@ -462,6 +503,10 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
}
EXPORT_SYMBOL(blkdev_issue_flush);
+/*
+ * called by:
+ * - block/blk-mq.c|2727| <<blk_mq_init_hctx>> hctx->fq = blk_alloc_flush_queue(q, hctx->numa_node, set->cmd_size,
+ */
struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
int node, int cmd_size, gfp_t flags)
{
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 71e9ac0..ea4c2d1 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -242,6 +242,10 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
return do_split ? new : NULL;
}
+/*
+ * 根据块设备请求队列的limits.max_sectors和limits.max_segmetns
+ * 来拆分bio,适应设备缓存.会在函数blk_set_default_limits中设置
+ */
void blk_queue_split(struct request_queue *q, struct bio **bio)
{
struct bio *split, *res;
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 03a5348..e55553f 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -31,6 +31,19 @@ static int get_first_sibling(unsigned int cpu)
return cpu;
}
+/*
+ * called by:
+ * - block/blk-mq-rdma.c|50| <<blk_mq_rdma_map_queues>> return blk_mq_map_queues(map);
+ * - block/blk-mq-virtio.c|52| <<blk_mq_virtio_map_queues>> return blk_mq_map_queues(qmap);
+ * - block/blk-mq.c|3223| <<blk_mq_update_queue_map>> return blk_mq_map_queues(&set->map[0]);
+ * - block/blk-mq.c|3526| <<__blk_mq_update_nr_hw_queues>> blk_mq_map_queues(&set->map[0]);
+ * - drivers/nvme/host/pci.c|512| <<nvme_pci_map_queues>> blk_mq_map_queues(map);
+ * - drivers/nvme/host/rdma.c|1830| <<nvme_rdma_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]);
+ * - drivers/nvme/host/tcp.c|2083| <<nvme_tcp_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
+ * - drivers/nvme/host/tcp.c|2084| <<nvme_tcp_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_READ]);
+ * - drivers/scsi/qla2xxx/qla_os.c|6940| <<qla2xxx_map_queues>> rc = blk_mq_map_queues(qmap);
+ * - drivers/scsi/scsi_lib.c|1818| <<scsi_map_queues>> return blk_mq_map_queues(&set->map[0]);
+ */
int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
{
unsigned int *map = qmap->mq_map;
@@ -63,11 +76,16 @@ EXPORT_SYMBOL_GPL(blk_mq_map_queues);
* We have no quick way of doing reverse lookups. This is only used at
* queue init time, so runtime isn't important.
*/
+/*
+ * 找到index代表的hw queue对应的cpu (sw queue)
+ * 返回这个cpu的node
+ */
int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
{
int i;
for_each_possible_cpu(i) {
+ /* 猜测是每一个sw queue对应的hw queue??? */
if (index == qmap->mq_map[i])
return local_memory_node(cpu_to_node(i));
}
diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index f812083..1767dcc 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -836,6 +836,15 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
{},
};
+/*
+ * called by:
+ * - block/blk-mq-debugfs.c|865| <<blk_mq_debugfs_register>> if (!debugfs_create_files(q->debugfs_dir, q,
+ * - block/blk-mq-debugfs.c|920| <<blk_mq_debugfs_register_ctx>> if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs))
+ * - block/blk-mq-debugfs.c|941| <<blk_mq_debugfs_register_hctx>> if (!debugfs_create_files(hctx->debugfs_dir, hctx,
+ * - block/blk-mq-debugfs.c|1000| <<blk_mq_debugfs_register_sched>> if (!debugfs_create_files(q->sched_debugfs_dir, q,
+ * - block/blk-mq-debugfs.c|1046| <<blk_mq_debugfs_register_rqos>> if (!debugfs_create_files(rqos->debugfs_dir, rqos,
+ * - block/blk-mq-debugfs.c|1077| <<blk_mq_debugfs_register_sched_hctx>> if (!debugfs_create_files(hctx->sched_debugfs_dir, hctx,
+ */
static bool debugfs_create_files(struct dentry *parent, void *data,
const struct blk_mq_debugfs_attr *attr)
{
@@ -849,6 +858,10 @@ static bool debugfs_create_files(struct dentry *parent, void *data,
return true;
}
+/*
+ * called by only:
+ * - block/blk-sysfs.c|944| <<blk_register_queue>> blk_mq_debugfs_register(q);
+ */
int blk_mq_debugfs_register(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -857,6 +870,9 @@ int blk_mq_debugfs_register(struct request_queue *q)
if (!blk_debugfs_root)
return -ENOENT;
+ /*
+ * 添加/sys/kernel/debug/block/vda
+ */
q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
blk_debugfs_root);
if (!q->debugfs_dir)
diff --git a/block/blk-mq-pci.c b/block/blk-mq-pci.c
index 1dce185..09e1ef4 100644
--- a/block/blk-mq-pci.c
+++ b/block/blk-mq-pci.c
@@ -31,6 +31,12 @@
* that maps a queue to the CPUs that have irq affinity for the corresponding
* vector.
*/
+/*
+ * called by:
+ * - drivers/nvme/host/pci.c|510| <<nvme_pci_map_queues>> blk_mq_pci_map_queues(map, to_pci_dev(dev->dev), offset);
+ * - drivers/scsi/qla2xxx/qla_os.c|6942| <<qla2xxx_map_queues>> rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
+ * - drivers/scsi/smartpqi/smartpqi_init.c|5792| <<pqi_map_queues>> return blk_mq_pci_map_queues(&shost->tag_set.map[0],
+ */
int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
int offset)
{
diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 140933e..4daad99 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -16,6 +16,9 @@
#include "blk-mq-tag.h"
#include "blk-wbt.h"
+/*
+ * 没人调用
+ */
void blk_mq_sched_free_hctx_data(struct request_queue *q,
void (*exit)(struct blk_mq_hw_ctx *))
{
@@ -31,6 +34,10 @@ void blk_mq_sched_free_hctx_data(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_mq_sched_free_hctx_data);
+/*
+ * called by:
+ * - block/blk-mq.c|432| <<blk_mq_get_request>> blk_mq_sched_assign_ioc(rq);
+ */
void blk_mq_sched_assign_ioc(struct request *rq)
{
struct request_queue *q = rq->q;
@@ -61,6 +68,10 @@ void blk_mq_sched_assign_ioc(struct request *rq)
* Mark a hardware queue as needing a restart. For shared queues, maintain
* a count of how many hardware queues are marked for restart.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|216| <<blk_mq_sched_dispatch_requests>> blk_mq_sched_mark_restart_hctx(hctx);
+ */
void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
{
if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
@@ -70,12 +81,23 @@ void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
}
EXPORT_SYMBOL_GPL(blk_mq_sched_mark_restart_hctx);
+/*
+ * called by:
+ * - block/blk-mq.c|527| <<__blk_mq_free_request>> blk_mq_sched_restart(hctx);
+ *
+ * 如果hctx->state设置了BLK_MQ_S_SCHED_RESTART, 清空BLK_MQ_S_SCHED_RESTART
+ * 并且调用blk_mq_run_hw_queue(hctx, true)
+ */
void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
{
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
return;
clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ /*
+ * 猜测是request(tag)不够的时候才mark成restart???
+ */
+
blk_mq_run_hw_queue(hctx, true);
}
@@ -84,6 +106,14 @@ void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
* its queue by itself in its completion handler, so we don't need to
* restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|219| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_sched(hctx);
+ * - block/blk-mq-sched.c|224| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_sched(hctx);
+ *
+ * 核心思想是用e->type->ops.dispatch_request()获取调度器中下一个request, 放入一个list
+ * 然后用blk_mq_dispatch_rq_list()下发list中的request
+ */
static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -130,6 +160,11 @@ static struct blk_mq_ctx *blk_mq_next_ctx(struct blk_mq_hw_ctx *hctx,
* its queue by itself in its completion handler, so we don't need to
* restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|212| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_ctx(hctx);
+ * - block/blk-mq-sched.c|218| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_ctx(hctx);
+ */
static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -166,6 +201,10 @@ static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
WRITE_ONCE(hctx->dispatch_from, ctx);
}
+/*
+ * called only by:
+ * - block/blk-mq.c|1425| <<__blk_mq_run_hw_queue>> blk_mq_sched_dispatch_requests(hctx);
+ */
void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -301,6 +340,9 @@ EXPORT_SYMBOL_GPL(blk_mq_bio_list_merge);
* merge with. Currently includes a hand-wavy stop count of 8, to not spend
* too much time checking for merges.
*/
+/*
+ * 尝试是否可以和ctx->rq_lists[type]的merge
+ */
static bool blk_mq_attempt_merge(struct request_queue *q,
struct blk_mq_hw_ctx *hctx,
struct blk_mq_ctx *ctx, struct bio *bio)
@@ -317,6 +359,10 @@ static bool blk_mq_attempt_merge(struct request_queue *q,
return false;
}
+/*
+ * 先尝试是否可以用e->type->ops.bio_merge进行merge
+ * 尝试是否可以和ctx->rq_lists[type]的merge
+ */
bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
{
struct elevator_queue *e = q->elevator;
@@ -335,6 +381,9 @@ bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
!list_empty_careful(&ctx->rq_lists[type])) {
/* default per sw-queue merge */
spin_lock(&ctx->lock);
+ /*
+ * 尝试是否可以和ctx->rq_lists[type]的merge
+ */
ret = blk_mq_attempt_merge(q, hctx, ctx, bio);
spin_unlock(&ctx->lock);
}
@@ -349,12 +398,22 @@ bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq)
}
EXPORT_SYMBOL_GPL(blk_mq_sched_try_insert_merge);
+/*
+ * called by:
+ * - block/bfq-iosched.c|4702| <<bfq_insert_request>> blk_mq_sched_request_inserted(rq);
+ * - block/kyber-iosched.c|616| <<kyber_insert_requests>> blk_mq_sched_request_inserted(rq);
+ * - block/mq-deadline.c|507| <<dd_insert_request>> blk_mq_sched_request_inserted(rq);
+ */
void blk_mq_sched_request_inserted(struct request *rq)
{
trace_block_rq_insert(rq->q, rq);
}
EXPORT_SYMBOL_GPL(blk_mq_sched_request_inserted);
+/*
+ * called by:
+ * - block/blk-mq-sched.c|431| <<blk_mq_sched_insert_request>> if (blk_mq_sched_bypass_insert(hctx, !!e, rq))
+ */
static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
bool has_sched,
struct request *rq)
@@ -373,6 +432,22 @@ static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
return false;
}
+/*
+ * 一个非常重要的函数!!!!!
+ *
+ * called by:
+ * - block/blk-exec.c|61| <<blk_execute_rq_nowait>> blk_mq_sched_insert_request(rq, at_head, true, false);
+ * - block/blk-mq.c|775| <<blk_mq_requeue_work>> blk_mq_sched_insert_request(rq, true, false, false);
+ * - block/blk-mq.c|781| <<blk_mq_requeue_work>> blk_mq_sched_insert_request(rq, false, false, false);
+ * - block/blk-mq.c|1922| <<blk_mq_try_issue_directly>> blk_mq_sched_insert_request(rq, false,
+ * - block/blk-mq.c|1955| <<blk_mq_try_issue_list_directly>> blk_mq_sched_insert_request(rq, false, true, false);
+ * - block/blk-mq.c|2089| <<blk_mq_make_request>> blk_mq_sched_insert_request(rq, false, true, true);
+ *
+ * 如果不能用e->type->ops.insert_requests,
+ * 就把list拼接到ctx->rq_lists[type], 其实就是把list中的request们放入ctx->rq_lists[type]
+ * 一个hctx可能对应多个ctx
+ * 把ctx在hctx中对应的hctx->ctx_map设置上
+ */
void blk_mq_sched_insert_request(struct request *rq, bool at_head,
bool run_queue, bool async)
{
@@ -399,6 +474,11 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
e->type->ops.insert_requests(hctx, &list, at_head);
} else {
spin_lock(&ctx->lock);
+ /*
+ * 把list拼接到ctx->rq_lists[type], 其实就是把list中的request们放入ctx->rq_lists[type]
+ * 一个hctx可能对应多个ctx
+ * 把ctx在hctx中对应的hctx->ctx_map设置上
+ */
__blk_mq_insert_request(hctx, rq, at_head);
spin_unlock(&ctx->lock);
}
@@ -408,6 +488,11 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
blk_mq_run_hw_queue(hctx, async);
}
+/*
+ * called by:
+ * - block/blk-mq.c|1780| <<blk_mq_flush_plug_list>> blk_mq_sched_insert_requests(this_hctx, this_ctx,
+ * - block/blk-mq.c|1801| <<blk_mq_flush_plug_list>> blk_mq_sched_insert_requests(this_hctx, this_ctx, &rq_list,
+ */
void blk_mq_sched_insert_requests(struct blk_mq_hw_ctx *hctx,
struct blk_mq_ctx *ctx,
struct list_head *list, bool run_queue_async)
@@ -443,6 +528,10 @@ static void blk_mq_sched_free_tags(struct blk_mq_tag_set *set,
}
}
+/*
+ * called only by:
+ * - block/blk-mq-sched.c|497| <<blk_mq_init_sched>> ret = blk_mq_sched_alloc_tags(q, hctx, i);
+ */
static int blk_mq_sched_alloc_tags(struct request_queue *q,
struct blk_mq_hw_ctx *hctx,
unsigned int hctx_idx)
@@ -450,11 +539,18 @@ static int blk_mq_sched_alloc_tags(struct request_queue *q,
struct blk_mq_tag_set *set = q->tag_set;
int ret;
+ /*
+ * 为hctx_idx代表的hw queue分配并初始化blk_mq_tags
+ */
hctx->sched_tags = blk_mq_alloc_rq_map(set, hctx_idx, q->nr_requests,
set->reserved_tags);
if (!hctx->sched_tags)
return -ENOMEM;
+ /*
+ * 核心思想是为blk_mq_tags->page_list分配页面
+ * 然后这些页面对应的位置被blk_mq_tags->static_rqs[i]所指向
+ */
ret = blk_mq_alloc_rqs(set, hctx->sched_tags, hctx_idx, q->nr_requests);
if (ret)
blk_mq_sched_free_tags(set, hctx, hctx_idx);
@@ -472,6 +568,11 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q)
blk_mq_sched_free_tags(set, hctx, i);
}
+/*
+ * called by:
+ * - block/elevator.c|577| <<elevator_switch_mq>> ret = blk_mq_init_sched(q, new_e);
+ * - block/elevator.c|623| <<elevator_init_mq>> err = blk_mq_init_sched(q, e);
+ */
int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
{
struct blk_mq_hw_ctx *hctx;
@@ -526,6 +627,11 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
return ret;
}
+/*
+ * called by:
+ * - block/blk-mq-sched.c|564| <<blk_mq_init_sched>> blk_mq_exit_sched(q, eq);
+ * - block/elevator.c|184| <<elevator_exit>> blk_mq_exit_sched(q, e);
+ */
void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e)
{
struct blk_mq_hw_ctx *hctx;
diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h
index c7bdb52..401c694 100644
--- a/block/blk-mq-sched.h
+++ b/block/blk-mq-sched.h
@@ -29,6 +29,10 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
+/*
+ * 先尝试是否可以用e->type->ops.bio_merge进行merge
+ * 尝试是否可以和ctx->rq_lists[type]的merge
+ */
static inline bool
blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
{
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index 3f9c3f4..c4b9dbf 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -224,6 +224,12 @@ static struct kobj_type blk_mq_hw_ktype = {
.release = blk_mq_hw_sysfs_release,
};
+/*
+ * called by:
+ * - block/blk-mq-sysfs.c|271| <<blk_mq_unregister_dev>> blk_mq_unregister_hctx(hctx);
+ * - block/blk-mq-sysfs.c|339| <<__blk_mq_register_dev>> blk_mq_unregister_hctx(q->queue_hw_ctx[i]);
+ * - block/blk-mq-sysfs.c|368| <<blk_mq_sysfs_unregister>> blk_mq_unregister_hctx(hctx);
+ */
static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx)
{
struct blk_mq_ctx *ctx;
@@ -238,6 +244,11 @@ static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx)
kobject_del(&hctx->kobj);
}
+/*
+ * called by:
+ * - block/blk-mq-sysfs.c|327| <<__blk_mq_register_dev>> ret = blk_mq_register_hctx(hctx);
+ * - block/blk-mq-sysfs.c|384| <<blk_mq_sysfs_register>> ret = blk_mq_register_hctx(hctx);
+ */
static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -247,6 +258,7 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
if (!hctx->nr_ctx)
return 0;
+ /* 第二个参数是parent */
ret = kobject_add(&hctx->kobj, q->mq_kobj, "%u", hctx->queue_num);
if (ret)
return ret;
@@ -260,6 +272,10 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
return ret;
}
+/*
+ * called by:
+ * - block/blk-sysfs.c|1003| <<blk_unregister_queue>> blk_mq_unregister_dev(disk_to_dev(disk), q);
+ */
void blk_mq_unregister_dev(struct device *dev, struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -277,11 +293,20 @@ void blk_mq_unregister_dev(struct device *dev, struct request_queue *q)
q->mq_sysfs_init_done = false;
}
+/*
+ * called by:
+ * - block/blk-mq.c|2986| <<blk_mq_alloc_and_init_hctx>> blk_mq_hctx_kobj_init(hctx);
+ */
void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx)
{
kobject_init(&hctx->kobj, &blk_mq_hw_ktype);
}
+/*
+ * called by:
+ * - block/blk-mq.c|2878| <<blk_mq_release>> blk_mq_sysfs_deinit(q);
+ * - block/blk-mq.c|3200| <<blk_mq_init_allocated_queue>> blk_mq_sysfs_deinit(q);
+ */
void blk_mq_sysfs_deinit(struct request_queue *q)
{
struct blk_mq_ctx *ctx;
@@ -294,6 +319,10 @@ void blk_mq_sysfs_deinit(struct request_queue *q)
kobject_put(q->mq_kobj);
}
+/*
+ * called by:
+ * - block/blk-mq.c|3114| <<blk_mq_init_allocated_queue>> blk_mq_sysfs_init(q);
+ */
void blk_mq_sysfs_init(struct request_queue *q)
{
struct blk_mq_ctx *ctx;
@@ -309,6 +338,11 @@ void blk_mq_sysfs_init(struct request_queue *q)
}
}
+/*
+ * called by:
+ * - block/blk-mq-sysfs.c|367| <<blk_mq_register_dev>> ret = __blk_mq_register_dev(dev, q); blk_mq_register_dev()没人调用!!!
+ * - block/blk-sysfs.c|943| <<blk_register_queue>> __blk_mq_register_dev(dev, q);
+ */
int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -344,6 +378,9 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
return ret;
}
+/*
+ * 没人调用
+ */
int blk_mq_register_dev(struct device *dev, struct request_queue *q)
{
int ret;
@@ -355,6 +392,10 @@ int blk_mq_register_dev(struct device *dev, struct request_queue *q)
return ret;
}
+/*
+ * called by:
+ * - block/blk-mq.c|3607| <<__blk_mq_update_nr_hw_queues>> blk_mq_sysfs_unregister(q);
+ */
void blk_mq_sysfs_unregister(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -371,6 +412,10 @@ void blk_mq_sysfs_unregister(struct request_queue *q)
mutex_unlock(&q->sysfs_lock);
}
+/*
+ * called by:
+ * - block/blk-mq.c|3627| <<__blk_mq_update_nr_hw_queues>> blk_mq_sysfs_register(q);
+ */
int blk_mq_sysfs_register(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 2089c6c..785bc4e 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -50,6 +50,10 @@ void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool include_reserve)
* If a previously busy queue goes inactive, potential waiters could now
* be allowed to queue. Wake them up and check.
*/
+/*
+ * called only by:
+ * - block/blk-mq-tag.h|83| <<blk_mq_tag_idle>> __blk_mq_tag_idle(hctx);
+ */
void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
{
struct blk_mq_tags *tags = hctx->tags;
@@ -96,6 +100,10 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
static int __blk_mq_get_tag(struct blk_mq_alloc_data *data,
struct sbitmap_queue *bt)
{
+ /*
+ * BLK_MQ_REQ_INTERNAL只在一个地方设置 (存在q->elevator的情况下):
+ * - block/blk-mq.c|378| <<blk_mq_get_request>> data->flags |= BLK_MQ_REQ_INTERNAL;
+ */
if (!(data->flags & BLK_MQ_REQ_INTERNAL) &&
!hctx_may_queue(data->hctx, bt))
return -1;
@@ -415,6 +423,11 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
node);
}
+/*
+ * 分配和初始化:
+ * blk_mq_tags->bitmap_tags
+ * blk_mq_tags->breserved_tags
+ */
static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
int node, int alloc_policy)
{
@@ -435,6 +448,12 @@ static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
return NULL;
}
+/*
+ * called only by:
+ * - block/blk-mq.c|2097| <<blk_mq_alloc_rq_map>> tags = blk_mq_init_tags(nr_tags, reserved_tags, node,
+ *
+ * 分配并初始化blk_mq_tags
+ */
struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
unsigned int reserved_tags,
int node, int alloc_policy)
@@ -453,6 +472,11 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
tags->nr_tags = total_tags;
tags->nr_reserved_tags = reserved_tags;
+ /*
+ * 分配和初始化:
+ * blk_mq_tags->bitmap_tags
+ * blk_mq_tags->breserved_tags
+ */
return blk_mq_init_bitmap_tags(tags, node, alloc_policy);
}
diff --git a/block/blk-mq-tag.h b/block/blk-mq-tag.h
index 61deab0..088f43b 100644
--- a/block/blk-mq-tag.h
+++ b/block/blk-mq-tag.h
@@ -7,16 +7,40 @@
/*
* Tag address space map.
*/
+/*
+ * 每一个hw queue一个
+ */
struct blk_mq_tags {
unsigned int nr_tags;
unsigned int nr_reserved_tags;
+ /*
+ * 在以下使用:
+ * - block/blk-mq-debugfs.c|480| <<blk_mq_debugfs_tags_show>> atomic_read(&tags->active_queues));
+ * - block/blk-mq-tag.c|34| <<__blk_mq_tag_busy>> atomic_inc(&hctx->tags->active_queues);
+ * - block/blk-mq-tag.c|60| <<__blk_mq_tag_idle>> atomic_dec(&tags->active_queues);
+ * - block/blk-mq-tag.c|85| <<hctx_may_queue>> users = atomic_read(&hctx->tags->active_queues);
+ */
atomic_t active_queues;
struct sbitmap_queue bitmap_tags;
struct sbitmap_queue breserved_tags;
+ /*
+ * 在blk_mq_alloc_rq_map()分配set->queue_depth个一维指针
+ *
+ * 在以下被实际使用(分配或者临时分配):
+ * - block/blk-mq-tag.h|86| <<blk_mq_tag_set_rq>> hctx->tags->rqs[tag] = rq;
+ * - block/blk-mq.c|313| <<blk_mq_rq_ctx_init>> data->hctx->tags->rqs[rq->tag] = rq
+ * - block/blk-mq.c|1062| <<blk_mq_get_driver_tag>> data.hctx->tags->rqs[rq->tag] = rq;
+ */
struct request **rqs;
+ /*
+ * 在blk_mq_alloc_rq_map()分配set->queue_depth个一维指针
+ *
+ * 指针真正的元素在blk_mq_alloc_rqs()分配:
+ * - block/blk-mq.c|2307| <<blk_mq_alloc_rqs>> tags->static_rqs[i] = rq;
+ */
struct request **static_rqs;
struct list_head page_list;
};
@@ -61,6 +85,11 @@ static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
return __blk_mq_tag_busy(hctx);
}
+/*
+ * called by:
+ * - block/blk-mq.c|951| <<blk_mq_timeout_work>> blk_mq_tag_idle(hctx);
+ * - block/blk-mq.c|2343| <<blk_mq_exit_hctx>> blk_mq_tag_idle(hctx);
+ */
static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
{
if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
@@ -75,6 +104,11 @@ static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
* in flight at the same time. The caller has to make sure the tag
* can't be freed.
*/
+/*
+ * called by:
+ * - block/blk-flush.c|220| <<flush_end_io>> blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq);
+ * - block/blk-flush.c|303| <<blk_kick_flush>> blk_mq_tag_set_rq(flush_rq->mq_hctx, first_rq->tag, flush_rq);
+ */
static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
unsigned int tag, struct request *rq)
{
diff --git a/block/blk-mq-virtio.c b/block/blk-mq-virtio.c
index 3708271..0abb2ed 100644
--- a/block/blk-mq-virtio.c
+++ b/block/blk-mq-virtio.c
@@ -29,6 +29,11 @@
* that maps a queue to the CPUs that have irq affinity for the corresponding
* vector.
*/
+/*
+ * called by:
+ * - drivers/block/virtio_blk.c|694| <<virtblk_map_queues>> return blk_mq_virtio_map_queues(&set->map[0], vblk->vdev, 0);
+ * - drivers/scsi/virtio_scsi.c|674| <<virtscsi_map_queues>> return blk_mq_virtio_map_queues(qmap, vscsi->vdev, 2);
+ */
int blk_mq_virtio_map_queues(struct blk_mq_queue_map *qmap,
struct virtio_device *vdev, int first_vec)
{
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8f5b533..2c9fd96 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -38,6 +38,28 @@
#include "blk-mq-sched.h"
#include "blk-rq-qos.h"
+/*
+ * 一共两处对queue_rq()的调用:
+ * - blk_mq_try_issue_directly()-->__blk_mq_issue_directly()
+ * - blk_mq_dispatch_rq_list()
+ *
+ *
+ *
+ * BLK_MQ_F_xxx只被blk_mq_tag_set->flags和blk_mq_hw_hctx->flags使用
+ * blk_mq_init_hctx()中把blk_mq_tag_set->flags拷贝到blk_mq_hw_hctx->flags:
+ * - block/blk-mq.c|2402| <<blk_mq_init_hctx>> hctx->flags = set->flags & ~BLK_MQ_F_TAG_SHARED;
+ *
+ * BLK_MQ_S_xxx只用在blk_mq_hw_ctx->state
+ *
+ * BLK_MQ_REQ_xxx只被blk_mq_alloc_data->flags使用
+ *
+ * RQF_xxx用在request->rq_flags
+ *
+ * MQ_RQ_xxx用在request->state
+ *
+ * QUEUE_FLAG_xxx在request_queue->queue_flags中使用
+ */
+
static void blk_mq_poll_stats_start(struct request_queue *q);
static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb);
@@ -71,11 +93,34 @@ static bool blk_mq_hctx_has_pending(struct blk_mq_hw_ctx *hctx)
/*
* Mark this ctx as having pending work in this hardware queue
*/
+/*
+ * 一个hctx可能对应多个ctx
+ * 把ctx在hctx中对应的hctx->ctx_map设置上
+ */
static void blk_mq_hctx_mark_pending(struct blk_mq_hw_ctx *hctx,
struct blk_mq_ctx *ctx)
{
+ /*
+ * index_hw在以下初始化:
+ * - block/blk-mq.c|2627| <<blk_mq_map_swqueue>> ctx->index_hw[hctx->type] = hctx->nr_ctx;
+ */
const int bit = ctx->index_hw[hctx->type];
+ /*
+ * ctx_map在以下被使用:
+ * - block/blk-mq-debugfs.c|470| <<hctx_ctx_map_show>> sbitmap_bitmap_show(&hctx->ctx_map, m);
+ * - block/blk-mq-sched.c|177| <<blk_mq_do_dispatch_ctx>> if (!sbitmap_any_bit_set(&hctx->ctx_map))
+ * - block/blk-mq.c|89| <<blk_mq_hctx_has_pending>> sbitmap_any_bit_set(&hctx->ctx_map) ||
+ * - block/blk-mq.c|101| <<blk_mq_hctx_mark_pending>> if (!sbitmap_test_bit(&hctx->ctx_map, bit))
+ * - block/blk-mq.c|102| <<blk_mq_hctx_mark_pending>> sbitmap_set_bit(&hctx->ctx_map, bit);
+ * - block/blk-mq.c|110| <<blk_mq_hctx_clear_pending>> sbitmap_clear_bit(&hctx->ctx_map, bit);
+ * - block/blk-mq.c|1011| <<blk_mq_flush_busy_ctxs>> sbitmap_for_each_set(&hctx->ctx_map, flush_busy_ctx, &data);
+ * - block/blk-mq.c|1057| <<blk_mq_dequeue_from_ctx>> __sbitmap_for_each_set(&hctx->ctx_map, off,
+ * - block/blk-mq.c|2395| <<blk_mq_exit_hctx>> sbitmap_free(&hctx->ctx_map);
+ * - block/blk-mq.c|2457| <<blk_mq_init_hctx>> if (sbitmap_init_node(&hctx->ctx_map, nr_cpu_ids, ilog2(8),
+ * - block/blk-mq.c|2490| <<blk_mq_init_hctx>> sbitmap_free(&hctx->ctx_map);
+ * - block/blk-mq.c|2710| <<blk_mq_map_swqueue>> sbitmap_resize(&hctx->ctx_map, hctx->nr_ctx);
+ */
if (!sbitmap_test_bit(&hctx->ctx_map, bit))
sbitmap_set_bit(&hctx->ctx_map, bit);
}
@@ -131,6 +176,10 @@ static bool blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx,
return true;
}
+/*
+ * called only by:
+ * - block/genhd.c|94| <<part_in_flight_rw>> blk_mq_in_flight_rw(q, part, inflight);
+ */
void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2])
{
@@ -262,6 +311,10 @@ void blk_mq_unquiesce_queue(struct request_queue *q)
}
EXPORT_SYMBOL_GPL(blk_mq_unquiesce_queue);
+/*
+ * called only by:
+ * - block/blk-core.c|286| <<blk_set_queue_dying>> blk_mq_wake_waiters(q);
+ */
void blk_mq_wake_waiters(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -287,16 +340,35 @@ static inline bool blk_mq_need_time_stamp(struct request *rq)
return (rq->rq_flags & RQF_IO_STAT) || rq->q->elevator;
}
+/*
+ * called only by:
+ * - block/blk-mq.c|456| <<blk_mq_get_request>> rq = blk_mq_rq_ctx_init(data, tag, data->cmd_flags);
+ *
+ * 在根据tag获取request的时候
+ * 如果data->flags设置了BLK_MQ_REQ_INTERNAL, 使用data->hctx->sched_tags
+ * 否则使用data->hctx->tags
+ */
static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
unsigned int tag, unsigned int op)
{
+ /*
+ * 如果data->flags设置了BLK_MQ_REQ_INTERNAL, 使用data->hctx->sched_tags
+ * 否则使用data->hctx->tags
+ */
struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
struct request *rq = tags->static_rqs[tag];
req_flags_t rq_flags = 0;
+ /*
+ * BLK_MQ_REQ_INTERNAL只在一个地方设置 (存在q->elevator的情况下):
+ * - block/blk-mq.c|378| <<blk_mq_get_request>> data->flags |= BLK_MQ_REQ_INTERNAL;
+ */
if (data->flags & BLK_MQ_REQ_INTERNAL) {
rq->tag = -1;
rq->internal_tag = tag;
+ /*
+ * 到了blk_mq_get_driver_tag()再设置data->hctx->tags->rqs[rq->tag]
+ */
} else {
if (data->hctx->flags & BLK_MQ_F_TAG_SHARED) {
rq_flags = RQF_MQ_INFLIGHT;
@@ -369,6 +441,10 @@ static struct request *blk_mq_get_request(struct request_queue *q,
data->flags |= BLK_MQ_REQ_NOWAIT;
if (e) {
+ /*
+ * BLK_MQ_REQ_INTERNAL只在一个地方设置 (存在q->elevator的情况下):
+ * - block/blk-mq.c|378| <<blk_mq_get_request>> data->flags |= BLK_MQ_REQ_INTERNAL;
+ */
data->flags |= BLK_MQ_REQ_INTERNAL;
/*
@@ -384,6 +460,12 @@ static struct request *blk_mq_get_request(struct request_queue *q,
blk_mq_tag_busy(data->hctx);
}
+ /*
+ * 获得的tag用来索引tags->static_rqs???
+ * 这里的tags可能是:
+ * 1. data->hctx->sched_tags
+ * 2. data->hctx->tags
+ */
tag = blk_mq_get_tag(data);
if (tag == BLK_MQ_TAG_FAIL) {
if (put_ctx_on_error) {
@@ -394,6 +476,11 @@ static struct request *blk_mq_get_request(struct request_queue *q,
return NULL;
}
+ /*
+ * 在根据tag获取request的时候
+ * 如果data->flags设置了BLK_MQ_REQ_INTERNAL, 使用data->hctx->sched_tags
+ * 否则使用data->hctx->tags
+ */
rq = blk_mq_rq_ctx_init(data, tag, data->cmd_flags);
if (!op_is_flush(data->cmd_flags)) {
rq->elv.icq = NULL;
@@ -409,6 +496,16 @@ static struct request *blk_mq_get_request(struct request_queue *q,
return rq;
}
+/*
+ * called by:
+ * - block/blk-core.c|579| <<blk_get_request>> req = blk_mq_alloc_request(q, op, flags);
+ * - drivers/block/mtip32xx/mtip32xx.c|994| <<mtip_exec_internal_command>> rq = blk_mq_alloc_request(dd->queue, REQ_OP_DRV_IN, BLK_MQ_REQ_RESERVED);
+ * - drivers/block/sx8.c|511| <<carm_array_info>> rq = blk_mq_alloc_request(host->oob_q, REQ_OP_DRV_OUT, 0);
+ * - drivers/block/sx8.c|564| <<carm_send_special>> rq = blk_mq_alloc_request(host->oob_q, REQ_OP_DRV_OUT, 0);
+ * - drivers/ide/ide-atapi.c|201| <<ide_prep_sense>> sense_rq = blk_mq_alloc_request(drive->queue, REQ_OP_DRV_IN,
+ * - drivers/nvme/host/core.c|438| <<nvme_alloc_request>> req = blk_mq_alloc_request(q, op, flags);
+ * - drivers/scsi/fnic/fnic_scsi.c|2272| <<fnic_scsi_host_start_tag>> dummy = blk_mq_alloc_request(q, REQ_OP_WRITE, BLK_MQ_REQ_NOWAIT);
+ */
struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
blk_mq_req_flags_t flags)
{
@@ -435,6 +532,10 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
}
EXPORT_SYMBOL(blk_mq_alloc_request);
+/*
+ * called by:
+ * - drivers/nvme/host/core.c|440| <<nvme_alloc_request>> req = blk_mq_alloc_request_hctx(q, op, flags,
+ */
struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
unsigned int op, blk_mq_req_flags_t flags, unsigned int hctx_idx)
{
@@ -481,6 +582,11 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
+/*
+ * called by:
+ * - block/blk-mq.c|587| <<blk_mq_free_request>> __blk_mq_free_request(rq);
+ * - block/blk-mq.c|961| <<blk_mq_check_expired>> __blk_mq_free_request(rq);
+ */
static void __blk_mq_free_request(struct request *rq)
{
struct request_queue *q = rq->q;
@@ -498,6 +604,28 @@ static void __blk_mq_free_request(struct request *rq)
blk_queue_exit(q);
}
+/*
+ * called by:
+ * - block/bfq-iosched.c|1866| <<bfq_bio_merge>> blk_mq_free_request(free);
+ * - block/blk-core.c|589| <<blk_put_request>> blk_mq_free_request(req);
+ * - block/blk-mq.c|613| <<__blk_mq_end_request>> blk_mq_free_request(rq->next_rq);
+ * - block/blk-mq.c|614| <<__blk_mq_end_request>> blk_mq_free_request(rq);
+ * - block/mq-deadline.c|483| <<dd_bio_merge>> blk_mq_free_request(free);
+ * - drivers/block/mtip32xx/mtip32xx.c|1011| <<mtip_exec_internal_command>> blk_mq_free_request(rq);
+ * - drivers/block/mtip32xx/mtip32xx.c|1057| <<mtip_exec_internal_command>> blk_mq_free_request(rq);
+ * - drivers/ide/ide-atapi.c|217| <<ide_prep_sense>> blk_mq_free_request(sense_rq);
+ * - drivers/ide/ide-cd.c|272| <<ide_cd_free_sense>> blk_mq_free_request(drive->sense_rq);
+ * - drivers/ide/ide-probe.c|983| <<drive_release_dev>> blk_mq_free_request(drive->sense_rq);
+ * - drivers/nvme/host/core.c|787| <<__nvme_submit_sync_cmd>> blk_mq_free_request(req);
+ * - drivers/nvme/host/core.c|888| <<nvme_submit_user_cmd>> blk_mq_free_request(req);
+ * - drivers/nvme/host/core.c|898| <<nvme_keep_alive_end_io>> blk_mq_free_request(rq);
+ * - drivers/nvme/host/lightnvm.c|658| <<nvme_nvm_end_io>> blk_mq_free_request(rq);
+ * - drivers/nvme/host/lightnvm.c|730| <<nvme_nvm_submit_io_sync>> blk_mq_free_request(rq);
+ * - drivers/nvme/host/lightnvm.c|877| <<nvme_nvm_submit_user_cmd>> blk_mq_free_request(rq);
+ * - drivers/nvme/host/pci.c|1226| <<abort_endio>> blk_mq_free_request(req);
+ * - drivers/nvme/host/pci.c|2247| <<nvme_del_queue_end>> blk_mq_free_request(req);
+ * - drivers/scsi/fnic/fnic_scsi.c|2291| <<fnic_scsi_host_end_tag>> blk_mq_free_request(dummy);
+ */
void blk_mq_free_request(struct request *rq)