Skip to content

Commit ee5a1db

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: esp: use sg helper to iterate over scatterlist
Unlike the legacy I/O path, scsi-mq preallocates a large array to hold the scatterlist for each request. This static allocation can consume substantial amounts of memory on modern controllers which support a large number of concurrently outstanding requests. To facilitate a switch to a smaller static allocation combined with a dynamic allocation for requests that need it, we need to make sure all SCSI drivers handle chained scatterlists correctly. Convert remaining drivers that directly dereference the scatterlist array to using the iterator functions. [mkp: clarified commit message] Cc: Christoph Hellwig <hch@lst.de> Cc: Bart Van Assche <bvanassche@acm.org> Cc: Ewan D. Milne <emilne@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Finn Thain <fthain@telegraphics.com.au> Cc: Guenter Roeck <linux@roeck-us.net> Reported-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Finn Thain <fthain@telegraphics.com.au> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 0e9fdd2 commit ee5a1db

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

drivers/scsi/esp_scsi.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
370370
struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd);
371371
struct scatterlist *sg = scsi_sglist(cmd);
372372
int total = 0, i;
373+
struct scatterlist *s;
373374

374375
if (cmd->sc_data_direction == DMA_NONE)
375376
return;
@@ -380,16 +381,18 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
380381
* a dma address, so perform an identity mapping.
381382
*/
382383
spriv->num_sg = scsi_sg_count(cmd);
383-
for (i = 0; i < spriv->num_sg; i++) {
384-
sg[i].dma_address = (uintptr_t)sg_virt(&sg[i]);
385-
total += sg_dma_len(&sg[i]);
384+
385+
scsi_for_each_sg(cmd, s, spriv->num_sg, i) {
386+
s->dma_address = (uintptr_t)sg_virt(s);
387+
total += sg_dma_len(s);
386388
}
387389
} else {
388390
spriv->num_sg = scsi_dma_map(cmd);
389-
for (i = 0; i < spriv->num_sg; i++)
390-
total += sg_dma_len(&sg[i]);
391+
scsi_for_each_sg(cmd, s, spriv->num_sg, i)
392+
total += sg_dma_len(s);
391393
}
392394
spriv->cur_residue = sg_dma_len(sg);
395+
spriv->prv_sg = NULL;
393396
spriv->cur_sg = sg;
394397
spriv->tot_residue = total;
395398
}
@@ -443,7 +446,8 @@ static void esp_advance_dma(struct esp *esp, struct esp_cmd_entry *ent,
443446
p->tot_residue = 0;
444447
}
445448
if (!p->cur_residue && p->tot_residue) {
446-
p->cur_sg++;
449+
p->prv_sg = p->cur_sg;
450+
p->cur_sg = sg_next(p->cur_sg);
447451
p->cur_residue = sg_dma_len(p->cur_sg);
448452
}
449453
}
@@ -464,6 +468,7 @@ static void esp_save_pointers(struct esp *esp, struct esp_cmd_entry *ent)
464468
return;
465469
}
466470
ent->saved_cur_residue = spriv->cur_residue;
471+
ent->saved_prv_sg = spriv->prv_sg;
467472
ent->saved_cur_sg = spriv->cur_sg;
468473
ent->saved_tot_residue = spriv->tot_residue;
469474
}
@@ -478,6 +483,7 @@ static void esp_restore_pointers(struct esp *esp, struct esp_cmd_entry *ent)
478483
return;
479484
}
480485
spriv->cur_residue = ent->saved_cur_residue;
486+
spriv->prv_sg = ent->saved_prv_sg;
481487
spriv->cur_sg = ent->saved_cur_sg;
482488
spriv->tot_residue = ent->saved_tot_residue;
483489
}
@@ -1646,7 +1652,7 @@ static int esp_msgin_process(struct esp *esp)
16461652
spriv = ESP_CMD_PRIV(ent->cmd);
16471653

16481654
if (spriv->cur_residue == sg_dma_len(spriv->cur_sg)) {
1649-
spriv->cur_sg--;
1655+
spriv->cur_sg = spriv->prv_sg;
16501656
spriv->cur_residue = 1;
16511657
} else
16521658
spriv->cur_residue++;

drivers/scsi/esp_scsi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
struct esp_cmd_priv {
252252
int num_sg;
253253
int cur_residue;
254+
struct scatterlist *prv_sg;
254255
struct scatterlist *cur_sg;
255256
int tot_residue;
256257
};
@@ -273,6 +274,7 @@ struct esp_cmd_entry {
273274
struct scsi_cmnd *cmd;
274275

275276
unsigned int saved_cur_residue;
277+
struct scatterlist *saved_prv_sg;
276278
struct scatterlist *saved_cur_sg;
277279
unsigned int saved_tot_residue;
278280

0 commit comments

Comments
 (0)