-
Notifications
You must be signed in to change notification settings - Fork 4
/
block-comment-for-block-and-drivers-for-linux-block-for-5.1-block-20190302.patch
5765 lines (5461 loc) · 260 KB
/
block-comment-for-block-and-drivers-for-linux-block-for-5.1-block-20190302.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 c3cd53437b91ea6ca8cbe1fff3e4c1a9629e4561 Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Thu, 25 Jul 2019 13:05:44 +0800
Subject: [PATCH 1/1] block comment for block and drivers for linux-5.2
Signed-off-by: Dongli Zhang <[email protected]>
---
block/blk-core.c | 75 ++++
block/blk-exec.c | 30 ++
block/blk-flush.c | 79 ++++
block/blk-lib.c | 28 ++
block/blk-merge.c | 16 +
block/blk-mq-cpumap.c | 28 ++
block/blk-mq-debugfs-zoned.c | 4 +
block/blk-mq-debugfs.c | 9 +
block/blk-mq-pci.c | 22 +
block/blk-mq-rdma.c | 5 +
block/blk-mq-sched.c | 269 ++++++++++++
block/blk-mq-sched.h | 50 +++
block/blk-mq-sysfs.c | 25 ++
block/blk-mq-tag.c | 141 +++++++
block/blk-mq-tag.h | 52 +++
block/blk-mq-virtio.c | 14 +
block/blk-mq.c | 846 +++++++++++++++++++++++++++++++++++++
block/blk-mq.h | 61 +++
block/blk-settings.c | 65 +++
block/blk-stat.c | 5 +
block/blk-sysfs.c | 5 +
block/blk.h | 13 +
block/bounce.c | 5 +
block/genhd.c | 256 +++++++++++
block/partition-generic.c | 25 ++
drivers/base/core.c | 7 +
drivers/block/null_blk_main.c | 11 +
drivers/block/virtio_blk.c | 277 ++++++++++++
drivers/nvme/host/core.c | 31 ++
drivers/nvme/host/nvme.h | 11 +
drivers/nvme/host/pci.c | 18 +
drivers/scsi/scsi.c | 6 +
drivers/scsi/scsi_lib.c | 10 +
drivers/virtio/virtio_pci_common.c | 5 +
drivers/virtio/virtio_ring.c | 8 +
fs/block_dev.c | 92 ++++
fs/direct-io.c | 13 +
include/linux/blk-mq.h | 205 +++++++++
include/linux/blk_types.h | 5 +
include/linux/blkdev.h | 203 +++++++++
include/linux/fs.h | 12 +
include/linux/genhd.h | 40 ++
lib/sbitmap.c | 5 +
43 files changed, 3087 insertions(+)
diff --git a/block/blk-core.c b/block/blk-core.c
index 8340f69..4dabe8a 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -66,6 +66,14 @@ struct kmem_cache *blk_requestq_cachep;
/*
* Controlling structure to kblockd
*/
+/*
+ * used by:
+ * - block/blk-core.c|1627| <<kblockd_schedule_work>> return queue_work(kblockd_workqueue, work);
+ * - block/blk-core.c|1633| <<kblockd_schedule_work_on>> return queue_work_on(cpu, kblockd_workqueue, work);
+ * - block/blk-core.c|1640| <<kblockd_mod_delayed_work_on>> return mod_delayed_work_on(cpu, kblockd_workqueue, dwork, delay);
+ * - block/blk-core.c|1790| <<blk_dev_init>> kblockd_workqueue = alloc_workqueue("kblockd",
+ * - block/blk-core.c|1792| <<blk_dev_init>> if (!kblockd_workqueue)
+ */
static struct workqueue_struct *kblockd_workqueue;
/**
@@ -528,6 +536,18 @@ EXPORT_SYMBOL(blk_get_queue);
* @op: operation (REQ_OP_*) and REQ_* flags, e.g. REQ_SYNC.
* @flags: BLK_MQ_REQ_* flags, e.g. BLK_MQ_REQ_NOWAIT.
*/
+/*
+ * 部分调用的例子:
+ * - block/scsi_ioctl.c|310| <<sg_io>> rq = blk_get_request(q, writing ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, 0);
+ * - block/scsi_ioctl.c|437| <<sg_scsi_ioctl>> rq = blk_get_request(q, in_len ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, 0);
+ * - block/scsi_ioctl.c|525| <<__blk_send_generic>> rq = blk_get_request(q, REQ_OP_SCSI_OUT, 0);
+ * - drivers/block/virtio_blk.c|463| <<virtblk_get_id>> req = blk_get_request(q, REQ_OP_DRV_IN, 0);
+ * - drivers/scsi/osst.c|373| <<osst_execute>> req = blk_get_request(SRpnt->stp->device->request_queue,
+ * - drivers/scsi/scsi_error.c|1952| <<scsi_eh_lock_door>> req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0);
+ * - drivers/scsi/scsi_lib.c|246| <<__scsi_execute>> req = blk_get_request(sdev->request_queue,
+ * - drivers/scsi/sg.c|1736| <<sg_start_req>> rq = blk_get_request(q, hp->dxfer_direction == SG_DXFER_TO_DEV ?
+ * - drivers/scsi/st.c|549| <<st_scsi_execute>> req = blk_get_request(SRpnt->stp->device->request_queue,
+ */
struct request *blk_get_request(struct request_queue *q, unsigned int op,
blk_mq_req_flags_t flags)
{
@@ -795,6 +815,10 @@ static inline int bio_check_eod(struct bio *bio, sector_t maxsector)
/*
* Remap block n of partition p to block n+start(p) of the disk.
*/
+/*
+ * called by:
+ * - block/blk-core.c|880| <<generic_make_request_checks>> if (unlikely(blk_partition_remap(bio)))
+ */
static inline int blk_partition_remap(struct bio *bio)
{
struct hd_struct *p;
@@ -827,6 +851,11 @@ static inline int blk_partition_remap(struct bio *bio)
return ret;
}
+/*
+ * called by:
+ * - block/blk-core.c|995| <<generic_make_request>> if (!generic_make_request_checks(bio))
+ * - block/blk-core.c|1091| <<direct_make_request>> if (!generic_make_request_checks(bio))
+ */
static noinline_for_stack bool
generic_make_request_checks(struct bio *bio)
{
@@ -1062,6 +1091,11 @@ EXPORT_SYMBOL(generic_make_request);
* its make_request function. (Calling direct_make_request again from
* a workqueue is perfectly fine as that doesn't recurse).
*/
+/*
+ * called by:
+ * - drivers/md/dm.c|1294| <<__map_bio>> ret = direct_make_request(clone);
+ * - drivers/nvme/host/multipath.c|251| <<nvme_ns_head_make_request>> ret = direct_make_request(bio);
+ */
blk_qc_t direct_make_request(struct bio *bio)
{
struct request_queue *q = bio->bi_disk->queue;
@@ -1278,6 +1312,14 @@ void blk_account_io_done(struct request *req, u64 now)
}
}
+/*
+ * called by:
+ * - block/blk-core.c|570| <<bio_attempt_back_merge>> blk_account_io_start(req, false);
+ * - block/blk-core.c|593| <<bio_attempt_front_merge>> blk_account_io_start(req, false);
+ * - block/blk-core.c|613| <<bio_attempt_discard_merge>> blk_account_io_start(req, false);
+ * - block/blk-core.c|1191| <<blk_insert_cloned_request>> blk_account_io_start(rq, true);
+ * - block/blk-mq.c|2038| <<blk_mq_bio_to_request>> blk_account_io_start(rq, true);
+ */
void blk_account_io_start(struct request *rq, bool new_io)
{
struct hd_struct *part;
@@ -1361,6 +1403,14 @@ EXPORT_SYMBOL_GPL(blk_steal_bios);
* %false - this request doesn't have any more data
* %true - this request has more data
**/
+/*
+ * called by:
+ * - block/blk-mq.c|671| <<blk_mq_end_request>> if (blk_update_request(rq, error, blk_rq_bytes(rq)))
+ * - drivers/block/loop.c|479| <<lo_complete_rq>> blk_update_request(rq, BLK_STS_OK, cmd->ret);
+ * - drivers/ide/ide-io.c|70| <<ide_end_rq>> if (!blk_update_request(rq, error, nr_bytes)) {
+ * - drivers/md/dm-rq.c|123| <<end_clone_bio>> blk_update_request(tio->orig, BLK_STS_OK, tio->completed);
+ * - drivers/scsi/scsi_lib.c|571| <<scsi_end_request>> if (blk_update_request(req, error, bytes))
+ */
bool blk_update_request(struct request *req, blk_status_t error,
unsigned int nr_bytes)
{
@@ -1659,6 +1709,10 @@ void blk_start_plug(struct blk_plug *plug)
}
EXPORT_SYMBOL(blk_start_plug);
+/*
+ * called by:
+ * - block/blk-core.c|1730| <<blk_flush_plug_list>> flush_plug_callbacks(plug, from_schedule);
+ */
static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
{
LIST_HEAD(callbacks);
@@ -1676,6 +1730,15 @@ static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
}
}
+/*
+ * called by:
+ * - drivers/block/drbd/drbd_req.c|1302| <<drbd_check_plugged>> struct blk_plug_cb *cb = blk_check_plugged(drbd_unplug, resource, sizeof(*plug));
+ * - drivers/block/umem.c|519| <<mm_check_plugged>> return !!blk_check_plugged(mm_unplug, card, sizeof(struct blk_plug_cb));
+ * - drivers/md/raid1.c|1503| <<raid1_write_request>> cb = blk_check_plugged(raid1_unplug, mddev, sizeof(*plug));
+ * - drivers/md/raid10.c|1286| <<raid10_write_one_disk>> cb = blk_check_plugged(raid10_unplug, mddev, sizeof(*plug));
+ * - drivers/md/raid5.c|5458| <<release_stripe_plug>> struct blk_plug_cb *blk_cb = blk_check_plugged(
+ * - fs/btrfs/raid56.c|1773| <<raid56_parity_write>> cb = blk_check_plugged(btrfs_raid_unplug, fs_info, sizeof(*plug));
+ */
struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data,
int size)
{
@@ -1701,6 +1764,14 @@ struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data,
}
EXPORT_SYMBOL(blk_check_plugged);
+/*
+ * called by:
+ * - block/blk-core.c|1734| <<blk_finish_plug>> blk_flush_plug_list(plug, false);
+ * - block/blk-mq.c|2361| <<blk_mq_make_request>> blk_flush_plug_list(plug, false);
+ * - block/blk-mq.c|3947| <<blk_poll>> blk_flush_plug_list(current->plug, false);
+ * - include/linux/blkdev.h|1232| <<blk_flush_plug>> blk_flush_plug_list(plug, false);
+ * - include/linux/blkdev.h|1240| <<blk_schedule_flush_plug>> blk_flush_plug_list(plug, true);
+ */
void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
{
flush_plug_callbacks(plug, from_schedule);
@@ -1729,6 +1800,10 @@ void blk_finish_plug(struct blk_plug *plug)
}
EXPORT_SYMBOL(blk_finish_plug);
+/*
+ * called by:
+ * - block/genhd.c|1110| <<genhd_device_init>> blk_dev_init();
+ */
int __init blk_dev_init(void)
{
BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS));
diff --git a/block/blk-exec.c b/block/blk-exec.c
index 1db44ca..4788ad9 100644
--- a/block/blk-exec.c
+++ b/block/blk-exec.c
@@ -17,6 +17,10 @@
* @rq: request to complete
* @error: end I/O status of the request
*/
+/*
+ * called by:
+ * - block/blk-exec.c|84| <<blk_execute_rq>> blk_execute_rq_nowait(q, bd_disk, rq, at_head, blk_end_sync_rq);
+ */
static void blk_end_sync_rq(struct request *rq, blk_status_t error)
{
struct completion *waiting = rq->end_io_data;
@@ -45,6 +49,19 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
* Note:
* This function will invoke @done directly if the queue is dead.
*/
+/*
+ * 部分调用的例子:
+ * - block/blk-exec.c|84| <<blk_execute_rq>> blk_execute_rq_nowait(q, bd_disk, rq, at_head, blk_end_sync_rq);
+ * - drivers/nvme/host/core.c|758| <<nvme_execute_rq_polled>> blk_execute_rq_nowait(q, bd_disk, rq, at_head, nvme_end_sync_rq);
+ * - drivers/nvme/host/core.c|943| <<nvme_keep_alive>> blk_execute_rq_nowait(rq->q, NULL, rq, 0, nvme_keep_alive_end_io);
+ * - drivers/nvme/host/lightnvm.c|688| <<nvme_nvm_submit_io>> blk_execute_rq_nowait(q, NULL, rq, 0, nvme_nvm_end_io);
+ * - drivers/nvme/host/pci.c|1352| <<nvme_timeout>> blk_execute_rq_nowait(abort_req->q, NULL, abort_req, 0, abort_endio);
+ * - drivers/nvme/host/pci.c|2217| <<nvme_delete_queue>> blk_execute_rq_nowait(q, NULL, req, false,
+ * - drivers/scsi/osst.c|422| <<osst_execute>> blk_execute_rq_nowait(req->q, NULL, req, 1, osst_end_async);
+ * - drivers/scsi/scsi_error.c|1969| <<scsi_eh_lock_door>> blk_execute_rq_nowait(req->q, NULL, req, 1, eh_lock_door_done);
+ * - drivers/scsi/sg.c|838| <<sg_common_write>> blk_execute_rq_nowait(sdp->device->request_queue, sdp->disk,
+ * - drivers/scsi/st.c|587| <<st_scsi_execute>> blk_execute_rq_nowait(req->q, NULL, req, 1, st_scsi_execute_end);
+ */
void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
struct request *rq, int at_head,
rq_end_io_fn *done)
@@ -74,6 +91,19 @@ EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
* Insert a fully prepared request at the back of the I/O scheduler queue
* for execution and wait for completion.
*/
+/*
+ * 调用的部分例子:
+ * - block/bsg.c|184| <<bsg_sg_io>> blk_execute_rq(q, NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL));
+ * - block/scsi_ioctl.c|357| <<sg_io>> blk_execute_rq(q, bd_disk, rq, at_head);
+ * - block/scsi_ioctl.c|493| <<sg_scsi_ioctl>> blk_execute_rq(q, disk, rq, 0);
+ * - block/scsi_ioctl.c|532| <<__blk_send_generic>> blk_execute_rq(q, bd_disk, rq, 0);
+ * - drivers/block/virtio_blk.c|381| <<virtblk_get_id>> blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
+ * - drivers/nvme/host/core.c|793| <<__nvme_submit_sync_cmd>> blk_execute_rq(req->q, NULL, req, at_head);
+ * - drivers/nvme/host/core.c|886| <<nvme_submit_user_cmd>> blk_execute_rq(req->q, disk, req, 0);
+ * - drivers/nvme/host/lightnvm.c|709| <<nvme_nvm_submit_io_sync>> blk_execute_rq(q, NULL, rq, 0);
+ * - drivers/nvme/host/lightnvm.c|838| <<nvme_nvm_submit_user_cmd>> blk_execute_rq(q, NULL, rq, 0);
+ * - drivers/scsi/scsi_lib.c|267| <<__scsi_execute>> blk_execute_rq(req->q, NULL, req, 1);
+ */
void blk_execute_rq(struct request_queue *q, struct gendisk *bd_disk,
struct request *rq, int at_head)
{
diff --git a/block/blk-flush.c b/block/blk-flush.c
index aedd932..e28e094 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -75,6 +75,27 @@
#include "blk-mq-tag.h"
#include "blk-mq-sched.h"
+/*
+ * 硬盘在控制器上的一块内存芯片,其类型一般以SDRAM为主,具有极快的存取速度,
+ * 它是硬盘内部存储和外界接口之间的缓冲器.由于硬盘的内部数据传输速度和外界
+ * 介面传输速度不同,缓存在其中起到一个缓冲的作用.缓存的大小与速度是直接关
+ * 系到硬盘的传输速度的重要因素,能够大幅度地提高硬盘整体性能.
+ *
+ * 如果硬盘的cache启用了,那么很有可能写入的数据是写到了硬盘的cache中,而没
+ * 有真正写到磁盘介质上.
+ *
+ * 在linux下,查看磁盘cache是否开启可通过hdparm命令:
+ *
+ * #hdparm -W /dev/sdx //是否开启cache,1为enable
+ * #hdparm -W 0 /dev/sdx //关闭cache
+ * #hdparm -W 1 /dev/sdx //enable cache
+ *
+ * REQ_FUA : forced unit access,绕过磁盘cache,直接把数据写到磁盘介质中.
+ * REQ_PREFLUSH: request for cache flush, 表示把磁盘cache中的data刷新到磁盘介质中,防止掉电丢失
+ *
+ * blk_insert_flush()是非常重要的入口!
+ */
+
/* PREFLUSH/FUA sequences */
enum {
REQ_FSEQ_PREFLUSH = (1 << 0), /* pre-flushing in progress */
@@ -254,6 +275,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|203| <<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)
{
@@ -313,6 +338,22 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
blk_flush_queue_rq(flush_rq, false);
}
+/*
+ * called by:
+ * - block/blk-mq.c|729| <<__blk_mq_end_request>> rq->end_io(rq, error);
+ * - drivers/lightnvm/core.c|785| <<nvm_end_io>> rqd->end_io(rqd);
+ * - drivers/md/dm-bufio.c|526| <<dmio_complete>> b->end_io(b, unlikely(error != 0) ? BLK_STS_IOERR : 0);
+ * - drivers/md/dm-bufio.c|556| <<use_dmio>> b->end_io(b, errno_to_blk_status(r));
+ * - drivers/md/dm-bufio.c|564| <<bio_complete>> b->end_io(b, status);
+ * - drivers/md/dm-mpath.c|559| <<multipath_release_clone>> pgpath->pg->ps.type->end_io(&pgpath->pg->ps,
+ * - drivers/md/dm-mpath.c|1596| <<multipath_end_io>> ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes);
+ * - drivers/md/dm-mpath.c|1640| <<multipath_end_io_bio>> ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes);
+ * - fs/direct-io.c|292| <<dio_complete>> err = dio->end_io(dio->iocb, offset, ret, dio->private);
+ * - fs/iomap.c|1507| <<iomap_dio_complete>> ret = dio->end_io(iocb,
+ *
+ * used by:
+ * - block/blk-flush.c|434| <<blk_insert_flush>> rq->end_io = mq_flush_data_end_io;
+ */
static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
{
struct request_queue *q = rq->q;
@@ -346,6 +387,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|488| <<blk_mq_sched_insert_request>> blk_insert_flush(rq);
+ * - block/blk-mq.c|2281| <<blk_mq_make_request>> blk_insert_flush(rq);
+ */
void blk_insert_flush(struct request *rq)
{
struct request_queue *q = rq->q;
@@ -419,6 +465,31 @@ 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-integrity.c|2519| <<bitmap_flush_work>> blkdev_issue_flush(ic->dev->bdev, GFP_NOIO, NULL);
+ * - 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|1040| <<ppl_recover>> ret = blkdev_issue_flush(rdev->bdev, GFP_KERNEL, NULL);
+ * - drivers/nvme/target/io-cmd-bdev.c|182| <<nvmet_bdev_flush>> if (blkdev_issue_flush(req->ns->bdev, GFP_KERNEL, NULL))
+ * - fs/block_dev.c|687| <<blkdev_fsync>> error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
+ * - fs/ext4/fsync.c|157| <<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|5142| <<ext4_sync_fs>> err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/fat/file.c|207| <<fat_file_fsync>> return blkdev_issue_flush(inode->i_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|242| <<hfsplus_sync_fs>> blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
+ * - fs/jbd2/checkpoint.c|417| <<jbd2_cleanup_journal_tail>> blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
+ * - fs/jbd2/commit.c|770| <<jbd2_journal_commit_transaction>> blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
+ * - fs/jbd2/commit.c|874| <<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|1024| <<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|197| <<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|671| <<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)
{
@@ -461,6 +532,10 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
}
EXPORT_SYMBOL(blkdev_issue_flush);
+/*
+ * called by:
+ * - block/blk-mq.c|2703| <<blk_mq_alloc_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)
{
@@ -490,6 +565,10 @@ struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
return NULL;
}
+/*
+ * called by only:
+ * - block/blk-mq-sysfs.c|43| <<blk_mq_hw_sysfs_release>> blk_free_flush_queue(hctx->fq);
+ */
void blk_free_flush_queue(struct blk_flush_queue *fq)
{
/* bio based request queue hasn't flush queue */
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 5f2c429..44c389d 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -22,6 +22,16 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)
return new;
}
+/*
+ * called by:
+ * - block/blk-lib.c|105| <<blkdev_issue_discard>> ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, flags,
+ * - drivers/md/dm-thin.c|401| <<issue_discard>> return __blkdev_issue_discard(tc->pool_dev->bdev, s, len,
+ * - drivers/md/raid0.c|532| <<raid0_handle_discard>> if (__blkdev_issue_discard(rdev->bdev,
+ * - drivers/nvme/target/io-cmd-bdev.c|193| <<nvmet_bdev_discard_range>> ret = __blkdev_issue_discard(ns->bdev,
+ * - fs/ext4/mballoc.c|2770| <<ext4_issue_discard>> return __blkdev_issue_discard(sb->s_bdev,
+ * - fs/f2fs/segment.c|1148| <<__submit_discard_cmd>> err = __blkdev_issue_discard(bdev,
+ * - fs/xfs/xfs_log_cil.c|548| <<xlog_discard_busy_extents>> error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
+ */
int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp_mask, int flags,
struct bio **biop)
@@ -94,6 +104,24 @@ EXPORT_SYMBOL(__blkdev_issue_discard);
* Description:
* Issue a discard request for the sectors in question.
*/
+/*
+ * called by:
+ * - block/blk-lib.c|97| <<blkdev_issue_discard>> int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
+ * - block/ioctl.c|230| <<blk_ioctl_discard>> return blkdev_issue_discard(bdev, start >> 9, len >> 9,
+ * - drivers/block/xen-blkback/blkback.c|1034| <<dispatch_discard_io>> err = blkdev_issue_discard(bdev, req->u.discard.sector_number,
+ * - drivers/md/bcache/alloc.c|338| <<bch_allocator_thread>> blkdev_issue_discard(ca->bdev,
+ * - drivers/md/raid5-cache.c|1347| <<r5l_write_super_and_discard_space>> blkdev_issue_discard(bdev,
+ * - drivers/md/raid5-cache.c|1351| <<r5l_write_super_and_discard_space>> blkdev_issue_discard(bdev,
+ * - drivers/md/raid5-cache.c|1355| <<r5l_write_super_and_discard_space>> blkdev_issue_discard(bdev, log->rdev->data_offset, end,
+ * - fs/block_dev.c|2070| <<blkdev_fallocate>> error = blkdev_issue_discard(bdev, start >> 9, len >> 9,
+ * - fs/btrfs/extent-tree.c|1957| <<btrfs_issue_discard>> ret = blkdev_issue_discard(bdev, start >> 9, size >> 9,
+ * - fs/btrfs/extent-tree.c|1974| <<btrfs_issue_discard>> ret = blkdev_issue_discard(bdev, start >> 9, bytes_left >> 9,
+ * - fs/xfs/xfs_discard.c|114| <<xfs_trim_extents>> error = blkdev_issue_discard(bdev, dbno, dlen, GFP_NOFS, 0);
+ * - include/linux/blkdev.h|1276| <<sb_issue_discard>> return blkdev_issue_discard(sb->s_bdev,
+ * - mm/swapfile.c|171| <<discard_swap>> err = blkdev_issue_discard(si->bdev, start_block,
+ * - mm/swapfile.c|182| <<discard_swap>> err = blkdev_issue_discard(si->bdev, start_block,
+ * - mm/swapfile.c|219| <<discard_swap_cluster>> if (blkdev_issue_discard(si->bdev, start_block,
+ */
int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp_mask, unsigned long flags)
{
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 17713d7..b0df023 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -144,6 +144,11 @@ static inline unsigned get_max_io_size(struct request_queue *q,
return sectors;
}
+/*
+ * called by:
+ * - block/blk-merge.c|176| <<bvec_split_segs>> seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
+ * - block/blk-merge.c|389| <<blk_bvec_map_sg>> unsigned len = min(get_max_segment_size(q, offset), nbytes);
+ */
static unsigned get_max_segment_size(struct request_queue *q,
unsigned offset)
{
@@ -194,6 +199,10 @@ static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
return !!len;
}
+/*
+ * called by:
+ * - block/blk-merge.c|278| <<blk_queue_split>> split = blk_bio_segment_split(q, *bio, &q->bio_split, &nsegs);
+ */
static struct bio *blk_bio_segment_split(struct request_queue *q,
struct bio *bio,
struct bio_set *bs,
@@ -258,6 +267,13 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
return do_split ? new : NULL;
}
+/*
+ * 部分调用的例子:
+ * - block/blk-mq.c|2246| <<blk_mq_make_request>> blk_queue_split(q, &bio);
+ * - drivers/md/dm.c|1765| <<dm_process_bio>> blk_queue_split(md->queue, &bio);
+ * - drivers/md/md.c|307| <<md_make_request>> blk_queue_split(q, &bio);
+ * - drivers/nvme/host/multipath.c|241| <<nvme_ns_head_make_request>> blk_queue_split(q, &bio);
+ */
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 f945621..33df8dc 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -15,12 +15,21 @@
#include "blk.h"
#include "blk-mq.h"
+/*
+ * called by:
+ * - block/blk-mq-cpumap.c|49| <<blk_mq_map_queues>> map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
+ * - block/blk-mq-cpumap.c|53| <<blk_mq_map_queues>> map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
+ */
static int cpu_to_queue_index(struct blk_mq_queue_map *qmap,
unsigned int nr_queues, const int cpu)
{
return qmap->queue_offset + (cpu % nr_queues);
}
+/*
+ * called by:
+ * - block/blk-mq-cpumap.c|51| <<blk_mq_map_queues>> first_sibling = get_first_sibling(cpu);
+ */
static int get_first_sibling(unsigned int cpu)
{
unsigned int ret;
@@ -32,6 +41,19 @@ static int get_first_sibling(unsigned int cpu)
return cpu;
}
+/*
+ * called by:
+ * - block/blk-mq-rdma.c|42| <<blk_mq_rdma_map_queues>> return blk_mq_map_queues(map);
+ * - block/blk-mq-virtio.c|44| <<blk_mq_virtio_map_queues>> return blk_mq_map_queues(qmap);
+ * - block/blk-mq.c|3077| <<blk_mq_update_queue_map>> return blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
+ * - block/blk-mq.c|3349| <<__blk_mq_update_nr_hw_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
+ * - drivers/nvme/host/pci.c|470| <<nvme_pci_map_queues>> blk_mq_map_queues(map);
+ * - drivers/nvme/host/rdma.c|1827| <<nvme_rdma_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]);
+ * - drivers/nvme/host/tcp.c|2144| <<nvme_tcp_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
+ * - drivers/nvme/host/tcp.c|2145| <<nvme_tcp_map_queues>> blk_mq_map_queues(&set->map[HCTX_TYPE_READ]);
+ * - drivers/scsi/qla2xxx/qla_os.c|7116| <<qla2xxx_map_queues>> rc = blk_mq_map_queues(qmap);
+ * - drivers/scsi/scsi_lib.c|1750| <<scsi_map_queues>> return blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
+ */
int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
{
unsigned int *map = qmap->mq_map;
@@ -68,6 +90,12 @@ 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.
*/
+/*
+ * called by:
+ * - block/blk-mq.c|2142| <<blk_mq_alloc_rq_map>> node = blk_mq_hw_queue_to_node(&set->map[HCTX_TYPE_DEFAULT], hctx_idx);
+ * - block/blk-mq.c|2198| <<blk_mq_alloc_rqs>> node = blk_mq_hw_queue_to_node(&set->map[HCTX_TYPE_DEFAULT], hctx_idx);
+ * - block/blk-mq.c|2843| <<blk_mq_realloc_hw_ctxs>> node = blk_mq_hw_queue_to_node(&set->map[HCTX_TYPE_DEFAULT], i);
+ */
int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
{
int i;
diff --git a/block/blk-mq-debugfs-zoned.c b/block/blk-mq-debugfs-zoned.c
index 038cb62..ac46d52 100644
--- a/block/blk-mq-debugfs-zoned.c
+++ b/block/blk-mq-debugfs-zoned.c
@@ -6,6 +6,10 @@
#include <linux/blkdev.h>
#include "blk-mq-debugfs.h"
+/*
+ * used by:
+ * - block/blk-mq-debugfs.c|207| <<global>> { "zone_wlock", 0400, queue_zone_wlock_show, NULL },
+ */
int queue_zone_wlock_show(void *data, struct seq_file *m)
{
struct request_queue *q = data;
diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 3afe327..ce471da 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -834,6 +834,10 @@ static void debugfs_create_files(struct dentry *parent, void *data,
(void *)attr, &blk_mq_debugfs_fops);
}
+/*
+ * called only by:
+ * - block/blk-sysfs.c|992| <<blk_register_queue>> blk_mq_debugfs_register(q);
+ */
void blk_mq_debugfs_register(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
@@ -985,6 +989,11 @@ void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
q->rqos_debugfs_dir = NULL;
}
+/*
+ * called by:
+ * - block/blk-mq-debugfs.c|860| <<blk_mq_debugfs_register>> blk_mq_debugfs_register_sched_hctx(q, hctx);
+ * - block/blk-mq-sched.c|536| <<blk_mq_init_sched>> blk_mq_debugfs_register_sched_hctx(q, hctx);
+ */
void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx)
{
diff --git a/block/blk-mq-pci.c b/block/blk-mq-pci.c
index b595a94..818d826 100644
--- a/block/blk-mq-pci.c
+++ b/block/blk-mq-pci.c
@@ -23,6 +23,12 @@
* that maps a queue to the CPUs that have irq affinity for the corresponding
* vector.
*/
+/*
+ * called by:
+ * - drivers/nvme/host/pci.c|468| <<nvme_pci_map_queues>> blk_mq_pci_map_queues(map, to_pci_dev(dev->dev), offset);
+ * - drivers/scsi/qla2xxx/qla_os.c|7118| <<qla2xxx_map_queues>> rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
+ * - drivers/scsi/smartpqi/smartpqi_init.c|5806| <<pqi_map_queues>> return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT],
+ */
int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
int offset)
{
@@ -30,10 +36,26 @@ int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
unsigned int queue, cpu;
for (queue = 0; queue < qmap->nr_queues; queue++) {
+ /* return the affinity of a particular msi vector */
mask = pci_irq_get_affinity(pdev, queue + offset);
if (!mask)
goto fallback;
+ /*
+ * queue_offset设置的地方:
+ * - drivers/nvme/host/pci.c|466| <<nvme_pci_map_queues>> map->queue_offset = qoff;
+ * - drivers/nvme/host/rdma.c|1801| <<nvme_rdma_map_queues>> set->map[HCTX_TYPE_DEFAULT].queue_offset = 0;
+ * - drivers/nvme/host/rdma.c|1804| <<nvme_rdma_map_queues>> set->map[HCTX_TYPE_READ].queue_offset =
+ * - drivers/nvme/host/rdma.c|1810| <<nvme_rdma_map_queues>> set->map[HCTX_TYPE_DEFAULT].queue_offset = 0;
+ * - drivers/nvme/host/rdma.c|1813| <<nvme_rdma_map_queues>> set->map[HCTX_TYPE_READ].queue_offset = 0;
+ * - drivers/nvme/host/rdma.c|1824| <<nvme_rdma_map_queues>> set->map[HCTX_TYPE_POLL].queue_offset =
+ * - drivers/nvme/host/tcp.c|2130| <<nvme_tcp_map_queues>> set->map[HCTX_TYPE_DEFAULT].queue_offset = 0;
+ * - drivers/nvme/host/tcp.c|2133| <<nvme_tcp_map_queues>> set->map[HCTX_TYPE_READ].queue_offset =
+ * - drivers/nvme/host/tcp.c|2139| <<nvme_tcp_map_queues>> set->map[HCTX_TYPE_DEFAULT].queue_offset = 0;
+ * - drivers/nvme/host/tcp.c|2142| <<nvme_tcp_map_queues>> set->map[HCTX_TYPE_READ].queue_offset = 0;
+ *
+ * mq_map[cpu]记录着当前的sw queue对应的hw queue
+ */
for_each_cpu(cpu, mask)
qmap->mq_map[cpu] = qmap->queue_offset + queue;
}
diff --git a/block/blk-mq-rdma.c b/block/blk-mq-rdma.c
index 14f968e..4643058 100644
--- a/block/blk-mq-rdma.c
+++ b/block/blk-mq-rdma.c
@@ -21,6 +21,11 @@
* @set->nr_hw_queues, or @dev does not provide an affinity mask for a
* vector, we fallback to the naive mapping.
*/
+/*
+ * called by:
+ * - drivers/nvme/host/rdma.c|1815| <<nvme_rdma_map_queues>> blk_mq_rdma_map_queues(&set->map[HCTX_TYPE_DEFAULT],
+ * - drivers/nvme/host/rdma.c|1817| <<nvme_rdma_map_queues>> blk_mq_rdma_map_queues(&set->map[HCTX_TYPE_READ],
+ */
int blk_mq_rdma_map_queues(struct blk_mq_queue_map *map,
struct ib_device *dev, int first_vec)
{
diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 2766066..96e37d5 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -17,6 +17,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 *))
{
@@ -32,6 +35,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|433| <<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;
@@ -62,8 +69,22 @@ 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|213| <<blk_mq_sched_dispatch_requests>> blk_mq_sched_mark_restart_hctx(hctx);
+ * - block/blk-mq.c|1197| <<blk_mq_mark_tag_wait>> blk_mq_sched_mark_restart_hctx(hctx);
+ * - block/mq-deadline.c|397| <<dd_dispatch_request>> blk_mq_sched_mark_restart_hctx(hctx);
+ */
void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
{
+ /*
+ * 使用BLK_MQ_S_SCHED_RESTART的地方:
+ * - block/blk-mq-sched.c|67| <<blk_mq_sched_mark_restart_hctx>> if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
+ * - block/blk-mq-sched.c|70| <<blk_mq_sched_mark_restart_hctx>> set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ * - block/blk-mq-sched.c|76| <<blk_mq_sched_restart>> if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
+ * - block/blk-mq-sched.c|78| <<blk_mq_sched_restart>> clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ * - block/blk-mq-sched.h|92| <<blk_mq_sched_needs_restart>> return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ */
if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
return;
@@ -71,8 +92,21 @@ 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-flush.c|337| <<mq_flush_data_end_io>> blk_mq_sched_restart(hctx);
+ * - block/blk-mq.c|524| <<__blk_mq_free_request>> blk_mq_sched_restart(hctx);
+ */
void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
{
+ /*
+ * 使用BLK_MQ_S_SCHED_RESTART的地方:
+ * - block/blk-mq-sched.c|67| <<blk_mq_sched_mark_restart_hctx>> if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
+ * - block/blk-mq-sched.c|70| <<blk_mq_sched_mark_restart_hctx>> set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ * - block/blk-mq-sched.c|76| <<blk_mq_sched_restart>> if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
+ * - block/blk-mq-sched.c|78| <<blk_mq_sched_restart>> clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ * - block/blk-mq-sched.h|92| <<blk_mq_sched_needs_restart>> return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
+ */
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
return;
clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
@@ -85,6 +119,16 @@ 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|229| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_sched(hctx);
+ * - block/blk-mq-sched.c|234| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_sched(hctx);
+ *
+ * 核心思想用scheduler的ops.dispatch_request(hctx)获取下一个request
+ * 使用queue_rq()下发
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -112,6 +156,13 @@ static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
* in blk_mq_dispatch_rq_list().
*/
list_add(&rq->queuelist, &rq_list);
+
+ /*
+ * blk_mq_dispatch_rq_list():
+ * 核心思想是为list的request调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
} while (blk_mq_dispatch_rq_list(q, &rq_list, true));
}
@@ -131,6 +182,16 @@ 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|240| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_ctx(hctx);
+ * - block/blk-mq-sched.c|246| <<blk_mq_sched_dispatch_requests>> blk_mq_do_dispatch_ctx(hctx);
+ *
+ * 在budget允许的范围内
+ * 从hctx所属的某一个ctx的ctx->rq_lists获得一个request, 然后调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -146,6 +207,9 @@ static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
if (!blk_mq_get_dispatch_budget(hctx))
break;
+ /*
+ * 从hctx所属的某一个ctx的ctx->rq_lists获得一个request
+ */
rq = blk_mq_dequeue_from_ctx(hctx, ctx);
if (!rq) {
blk_mq_put_dispatch_budget(hctx);
@@ -162,11 +226,25 @@ static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
/* round robin for fair dispatch */
ctx = blk_mq_next_ctx(hctx, rq->mq_ctx);
+ /*
+ * blk_mq_dispatch_rq_list():
+ * 核心思想是为list的request调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
} while (blk_mq_dispatch_rq_list(q, &rq_list, true));
WRITE_ONCE(hctx->dispatch_from, ctx);
}
+/*
+ * called by:
+ * - block/blk-mq.c|1478| <<__blk_mq_run_hw_queue>> blk_mq_sched_dispatch_requests(hctx);
+ *
+ * 核心思想优先下发hctx->dispatch
+ * 如果有scheduler就下发ctx中scheduler中的
+ * 否则根据情况下发部分(budget)或全部hctx所属ctx的request
+ */
void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
{
struct request_queue *q = hctx->queue;
@@ -178,12 +256,36 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
if (unlikely(blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q)))
return;
+ /*
+ * used only by:
+ * - block/blk-mq-debugfs.c|612| <<hctx_run_show>> seq_printf(m, "%lu\n", hctx->run);
+ * - block/blk-mq-debugfs.c|621| <<hctx_run_write>> hctx->run = 0;
+ * - block/blk-mq-sched.c|229| <<blk_mq_sched_dispatch_requests>> hctx->run++;
+ */
hctx->run++;
/*
* If we have previous entries on our dispatch list, grab them first for
* more fair dispatch.
*/
+ /*
+ * 往hctx->dispatch添加新元素的地方:
+ * - block/blk-mq-sched.c|425| <<blk_mq_sched_bypass_insert>> list_add(&rq->queuelist, &hctx->dispatch);
+ * - block/blk-mq.c|1391| <<blk_mq_dispatch_rq_list>> list_splice_init(list, &hctx->dispatch);
+ * - block/blk-mq.c|1779| <<blk_mq_request_bypass_insert>> list_add_tail(&rq->queuelist, &hctx->dispatch);
+ * - block/blk-mq.c|2364| <<blk_mq_hctx_notify_dead>> list_splice_tail_init(&tmp, &hctx->dispatch);
+ *
+ * 从hctx->dispatch移除元素的地方(下发):
+ * - block/blk-mq-sched.c|222| <<blk_mq_sched_dispatch_requests>> list_splice_init(&hctx->dispatch, &rq_list);
+ *
+ * 其他使用hctx->dispatch的地方:
+ * - block/blk-mq-debugfs.c|379| <<hctx_dispatch_start>> return seq_list_start(&hctx->dispatch, *pos);
+ * - block/blk-mq-debugfs.c|386| <<hctx_dispatch_next>> return seq_list_next(v, &hctx->dispatch, pos);
+ * - block/blk-mq-sched.c|219| <<blk_mq_sched_dispatch_requests>> if (!list_empty_careful(&hctx->dispatch)) {
+ * - block/blk-mq-sched.c|221| <<blk_mq_sched_dispatch_requests>> if (!list_empty(&hctx->dispatch))
+ * - block/blk-mq.c|72| <<blk_mq_hctx_has_pending>> return !list_empty_careful(&hctx->dispatch) ||
+ * - block/blk-mq.c|2474| <<blk_mq_alloc_hctx>> INIT_LIST_HEAD(&hctx->dispatch);
+ */
if (!list_empty_careful(&hctx->dispatch)) {
spin_lock(&hctx->lock);
if (!list_empty(&hctx->dispatch))
@@ -206,23 +308,81 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
*/
if (!list_empty(&rq_list)) {
blk_mq_sched_mark_restart_hctx(hctx);
+ /*
+ * 核心思想是为list的request调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
if (blk_mq_dispatch_rq_list(q, &rq_list, false)) {
+ /*
+ * 上面设置的has_sched_dispatch为true说明有io scheduler
+ *
+ *
+ * blk_mq_do_dispatch_sched():
+ * 核心思想用scheduler的ops.dispatch_request(hctx)获取下一个request
+ * 使用queue_rq()下发
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ *
+ *
+ * blk_mq_do_dispatch_ctx():
+ * 在budget允许的范围内
+ * 从hctx所属的某一个ctx的ctx->rq_lists获得一个request, 然后调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
if (has_sched_dispatch)
blk_mq_do_dispatch_sched(hctx);
else
blk_mq_do_dispatch_ctx(hctx);
}
} else if (has_sched_dispatch) {
+ /*
+ * 核心思想用scheduler的ops.dispatch_request(hctx)获取下一个request
+ * 使用queue_rq()下发
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
blk_mq_do_dispatch_sched(hctx);
} else if (hctx->dispatch_busy) {
+ /*
+ * 设置dispatch_busy的地方:
+ * - block/blk-mq.c|1445| <<blk_mq_update_dispatch_busy>> hctx->dispatch_busy = ewma;
+ *
+ * 使用dispatch_busy的地方:
+ * - block/blk-mq-debugfs.c|637| <<hctx_dispatch_busy_show>> seq_printf(m, "%u\n", hctx->dispatch_busy);
+ * - block/blk-mq-sched.c|338| <<blk_mq_sched_dispatch_requests>> } else if (hctx->dispatch_busy) {
+ * - block/blk-mq-sched.c|636| <<blk_mq_sched_insert_requests>> if (!hctx->dispatch_busy && !e && !run_queue_async) {
+ * - block/blk-mq.c|1435| <<blk_mq_update_dispatch_busy>> ewma = hctx->dispatch_busy;
+ * - block/blk-mq.c|2554| <<blk_mq_make_request>> !data.hctx->dispatch_busy)) {
+ */
/* dequeue request one by one from sw queue if queue is busy */
+ /*
+ * 在budget允许的范围内
+ * 从hctx所属的某一个ctx的ctx->rq_lists获得一个request, 然后调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
blk_mq_do_dispatch_ctx(hctx);
} else {
+ /*
+ * 把hctx所属的ctx的ctx->rq_lists的request放入参数的list
+ */
blk_mq_flush_busy_ctxs(hctx, &rq_list);
+ /*
+ * 核心思想是为list的request调用queue_rq()
+ * 如果有下发不了的放入hctx->dispatch
+ * 根据情况也许会直接或者间接blk_mq_run_hw_queue()
+ */
blk_mq_dispatch_rq_list(q, &rq_list, false);
}
}
+/*
+ * called by:
+ * - block/bfq-iosched.c|2053| <<bfq_bio_merge>> ret = blk_mq_sched_try_merge(q, bio, &free);
+ * - block/mq-deadline.c|480| <<dd_bio_merge>> ret = blk_mq_sched_try_merge(q, bio, &free);
+ */
bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
struct request **merged_request)
{
@@ -259,6 +419,11 @@ EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge);
* Iterate list of requests and see if we can merge this bio with any
* of them.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|340| <<blk_mq_attempt_merge>> if (blk_mq_bio_list_merge(q, &ctx->rq_lists[type], bio)) {
+ * - block/kyber-iosched.c|575| <<kyber_bio_merge>> merged = blk_mq_bio_list_merge(hctx->queue, rq_list, bio);
+ */
bool blk_mq_bio_list_merge(struct request_queue *q, struct list_head *list,
struct bio *bio)
{
@@ -302,6 +467,12 @@ 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.
*/
+/*
+ * called by:
+ * - block/blk-mq-sched.c|370| <<__blk_mq_sched_bio_merge>> ret = blk_mq_attempt_merge(q, hctx, ctx, bio);
+ *
+ * 尝试把bio给merge到ctx->rq_lists
+ */
static bool blk_mq_attempt_merge(struct request_queue *q,
struct blk_mq_hw_ctx *hctx,
struct blk_mq_ctx *ctx, struct bio *bio)
@@ -318,6 +489,13 @@ static bool blk_mq_attempt_merge(struct request_queue *q,
return false;
}
+/*
+ * called by:
+ * - block/blk-mq-sched.h|39| <<blk_mq_sched_bio_merge>> return __blk_mq_sched_bio_merge(q, bio);
+ *
+ * 如果支持scheduler就把bio用ops.bio_merge给merge了
+ * 否则尝试把bio给merge到ctx->rq_lists
+ */
bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
{
struct elevator_queue *e = q->elevator;
@@ -336,6 +514,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);
+ /*
+ * 尝试把bio给merge到ctx->rq_lists
+ */
ret = blk_mq_attempt_merge(q, hctx, ctx, bio);
spin_unlock(&ctx->lock);
}
@@ -344,6 +525,11 @@ bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
return ret;
}
+/*
+ * called by:
+ * - block/bfq-iosched.c|5052| <<bfq_insert_request>> if (blk_mq_sched_try_insert_merge(q, rq)) {
+ * - block/mq-deadline.c|505| <<dd_insert_request>> if (blk_mq_sched_try_insert_merge(q, rq))
+ */
bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq)
{
return rq_mergeable(rq) && elv_attempt_insert_merge(q, rq);
@@ -356,11 +542,24 @@ void blk_mq_sched_request_inserted(struct request *rq)
}
EXPORT_SYMBOL_GPL(blk_mq_sched_request_inserted);
+/*
+ * called by:
+ * - block/blk-mq-sched.c|420| <<blk_mq_sched_insert_request>> if (blk_mq_sched_bypass_insert(hctx, !!e, rq))
+ *
+ * 只有rq->rq_flags设置了RQF_FLUSH_SEQ才会添加到hctx->dispatch并且返回true,
+ * 否则返回false (不能bypass sched)
+ */
static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
bool has_sched,
struct request *rq)
{
/* dispatch flush rq directly */
+ /*
+ * 设置和取消RQF_FLUSH_SEQ的地方:
+ * - block/blk-flush.c|130| <<blk_flush_restore_request>> rq->rq_flags &= ~RQF_FLUSH_SEQ;
+ * - block/blk-flush.c|309| <<blk_kick_flush>> flush_rq->rq_flags |= RQF_FLUSH_SEQ;
+ * - block/blk-flush.c|401| <<blk_insert_flush>> rq->rq_flags |= RQF_FLUSH_SEQ;
+ */
if (rq->rq_flags & RQF_FLUSH_SEQ) {