Skip to content

Commit 9d2e59f

Browse files
Quinn TranNicholas Bellinger
Quinn Tran
authored and
Nicholas Bellinger
committed
target/rd: T10-Dif: RAM disk is allocating more space than required.
Ram disk is allocating 8x more space than required for diff data. For large RAM disk test, there is small potential for memory starvation. (Use block_size when calculating total_sg_needed - sagi + nab) Signed-off-by: Giridhar Malavali <[email protected]> Signed-off-by: Quinn Tran <[email protected]> Cc: <[email protected]> #3.14+ Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent d444edc commit 9d2e59f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/target/target_core_rd.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void rd_release_prot_space(struct rd_dev *rd_dev)
242242
rd_dev->sg_prot_count = 0;
243243
}
244244

245-
static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length)
245+
static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block_size)
246246
{
247247
struct rd_dev_sg_table *sg_table;
248248
u32 total_sg_needed, sg_tables;
@@ -252,8 +252,13 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length)
252252

253253
if (rd_dev->rd_flags & RDF_NULLIO)
254254
return 0;
255-
256-
total_sg_needed = rd_dev->rd_page_count / prot_length;
255+
/*
256+
* prot_length=8byte dif data
257+
* tot sg needed = rd_page_count * (PGSZ/block_size) *
258+
* (prot_length/block_size) + pad
259+
* PGSZ canceled each other.
260+
*/
261+
total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1;
257262

258263
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
259264

@@ -606,7 +611,8 @@ static int rd_init_prot(struct se_device *dev)
606611
if (!dev->dev_attrib.pi_prot_type)
607612
return 0;
608613

609-
return rd_build_prot_space(rd_dev, dev->prot_length);
614+
return rd_build_prot_space(rd_dev, dev->prot_length,
615+
dev->dev_attrib.block_size);
610616
}
611617

612618
static void rd_free_prot(struct se_device *dev)

0 commit comments

Comments
 (0)