Skip to contentSkip to conversation

mtip32xx: switch to vmalloc() to mitigate high order allocation failures

PATCH In review Sam Bradshaw 2 participants 2 messages Mar 13, 2014 – Mar 14, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtip32xx: switch to vmalloc() to mitigate high order allocation failures

The mtip_port kmalloc() allocation is relatively high order, in particular since the recent doubling of the size of the scatterlist container. The allocation has been shown to fail during SRSI under fragmented or low memory conditions. Switching to vmalloc() mitigates the problem. Converted both mtip_port and driver_data allocations for consistency.

drivers/block/mtip32xx/mtip32xx.c +7 -8
index 624e9d9..f55e3e5 100644
@@ -3116,7 +3116,7 @@ static int mtip_free_orphan(struct driver_data *dd)
 			dd->queue = NULL;
 		}
 	}
-	kfree(dd);
+	vfree(dd);
 	return 0;
 }
 
@@ -3495,8 +3495,7 @@ static int mtip_hw_init(struct driver_data *dd)
 
 	hba_setup(dd);
 
-	dd->port = kzalloc_node(sizeof(struct mtip_port), GFP_KERNEL,
-				dd->numa_node);
+	dd->port = vzalloc_node(sizeof(struct mtip_port), dd->numa_node);
 	if (!dd->port) {
 		dev_err(&dd->pdev->dev,
 			"Memory allocation: port structure\n");
@@ -3680,7 +3679,7 @@ out2:
 
 out1:
 	/* Free the memory allocated for the for structure. */
-	kfree(dd->port);
+	vfree(dd->port);
 
 	return rv;
 }
@@ -3724,7 +3723,7 @@ static int mtip_hw_exit(struct driver_data *dd)
 	mtip_dma_free(dd);
 
 	/* Free the memory allocated for the for structure. */
-	kfree(dd->port);
+	vfree(dd->port);
 	dd->port = NULL;
 
 	return 0;
@@ -4512,7 +4511,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
 		my_node, pcibus_to_node(pdev->bus), dev_to_node(&pdev->dev),
 		cpu_to_node(smp_processor_id()), smp_processor_id());
 
-	dd = kzalloc_node(sizeof(struct driver_data), GFP_KERNEL, my_node);
+	dd = vzalloc_node(sizeof(struct driver_data), my_node);
 	if (dd == NULL) {
 		dev_err(&pdev->dev,
 			"Unable to allocate memory for driver data\n");
@@ -4670,7 +4669,7 @@ setmask_err:
 	pcim_iounmap_regions(pdev, 1 << MTIP_ABAR);
 
 iomap_err:
-	kfree(dd);
+	vfree(dd);
 	pci_set_drvdata(pdev, NULL);
 	return rv;
 done:
@@ -4731,7 +4730,7 @@ static void mtip_pci_remove(struct pci_dev *pdev)
 	spin_unlock_irqrestore(&dev_lock, flags);
 
 	if (!dd->sr)
-		kfree(dd);
+		vfree(dd);
 	else
 		set_bit(MTIP_DDF_REMOVE_DONE_BIT, &dd->dd_flag);
 
#1 lore raw
Quoted 6 lines · Sam Bradshaw

The mtip_port kmalloc() allocation is relatively high order, in particular since the recent doubling of the size of the scatterlist container. The allocation has been shown to fail during SRSI under fragmented or low memory conditions. Switching to vmalloc() mitigates the problem. Converted both mtip_port and driver_data allocations for consistency.

It'd probably be better to use kmalloc and then
only if it fails use vmalloc.

See examples like net/sched/sch_hhf.c