Skip to contentSkip to conversation

make dev_to_node return online node or -1

PATCH In review Yinghai Lu 1 participant 7 messages Feb 20, 2008

Subsystems (4)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

cover make dev_to_node return online node or -1

Please check update on dev_to_node().

YH

author
#1 lore raw

PATCH 1/4 make dev_to_node return online node

some numa system ( with multi HT chains) may return node without ram. aka it is not online.
try to get one online node.

include/linux/device.h +6 -1
index 2258d89..7f1a4d7 100644
@@ -478,7 +478,12 @@ struct device {
 #ifdef CONFIG_NUMA
 static inline int dev_to_node(struct device *dev)
 {
-	return dev->numa_node;
+	int node;
+	node = dev->numa_node;
+
+	if (node != -1 && !node_online(node))
+		node = numa_node_id();
+	return node;
 }
 static inline void set_dev_node(struct device *dev, int node)
 {
author
#2 lore raw

Re: [PATCH 1/4] make dev_to_node return online node

please use this one instead. this one is less intrusive, and pcibus_to_node will work too and don't need other changes.

YH

---

[PATCH] make dev_to_node return online node v2

some numa system ( with multi HT chains) may return node without ram. aka it is not online.
try to get one online node, otherwise return -1

arch/x86/pci/acpi.c +3 -0
index c163ad1..2c1a651 100644
@@ -213,6 +213,9 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do
 		set_mp_bus_to_node(busnum, node);
 	else
 		node = get_mp_bus_to_node(busnum);
+
+	if (node != -1 && !node_online(node))
+		node = -1;
 #endif
 
 	/* Allocate per-root-bus (not per bus) arch-specific data.
author
#3 lore raw

PATCH 2/4 x86_64: fix dma_alloc_pages v2

In reply to Yinghai Lu

one system with two nodes and two ht links on every node. the bios already have _pxm for two links.

when no ram installed for node1 will have panic.

reason: the device on second chain will get node = 1 from dev_to_node...via pci_acpi_scan_root.
but node1 doesn't have ram installed.
in dma_alloc_pages it will pass check with first_node(node_online_map)... and will have problem with __alloc_pages in alloc_pages_node.

this patch will use updated dev_to node, so remove check about fist_node etc

arch/x86/kernel/pci-dma_64.c +0 -6
Index: linux-2.6/arch/x86/kernel/pci-dma_64.c
===================================================================
@@ -53,12 +53,6 @@ dma_alloc_pages(struct device *dev, gfp_
 	int node;
 
 	node = dev_to_node(dev);
-	if (node == -1)
-		node = numa_node_id();
-
-	if (node < first_node(node_online_map))
-		node = first_node(node_online_map);
-
 	page = alloc_pages_node(node, gfp, order);
 	return page ? page_address(page) : NULL;
 }
author
#4 lore raw

Re: [PATCH 2/4] x86_64: fix dma_alloc_pages v2

please use this one instead.

because v1 already in mm, and that doesn't depends on 1/4 here.

[PATCH 2/4] x86_64: fix dma_alloc_pages fix

this patch will use updated dev_to node, because dev_to_node already make sure it have node online

arch/x86/kernel/pci-dma_64.c +0 -2
index 931b51a..375cb2b 100644
@@ -53,8 +53,6 @@ dma_alloc_pages(struct device *dev, gfp_t gfp, unsigned order)
 	int node;
 
 	node = dev_to_node(dev);
-	if (node == -1 || !node_online(node))
-		node = numa_node_id();
 
 	page = alloc_pages_node(node, gfp, order);
 	return page ? page_address(page) : NULL;
author
#5 lore raw

PATCH 3/4 ide: use dev_to_node instead of pcibus_to_node

In reply to Yinghai Lu

when node0 doesn't have RAM, could have problem because pcibus_to_node may return 0. So use update dev_to_node to get online node.

include/linux/ide.h +1 -2
Index: linux-2.6/include/linux/ide.h
===================================================================
@@ -1294,8 +1294,7 @@ static inline void ide_dump_identify(u8 
 
 static inline int hwif_to_node(ide_hwif_t *hwif)
 {
-	struct pci_dev *dev = to_pci_dev(hwif->dev);
-	return hwif->dev ? pcibus_to_node(dev->bus) : -1;
+	return hwif->dev ? dev_to_node(hwif->dev) : -1;
 }
 
 static inline ide_drive_t *ide_get_paired_drive(ide_drive_t *drive)
author
#6 lore raw

PATCH 4/4 driver: use dev_to_node in pci_call_probe

In reply to Yinghai Lu

to make sure get one online node.

drivers/pci/pci-driver.c +2 -2
Index: linux-2.6/drivers/pci/pci-driver.c
===================================================================
@@ -181,8 +181,8 @@ static int pci_call_probe(struct pci_dri
 	   any need to change it. */
 	struct mempolicy *oldpol;
 	cpumask_t oldmask = current->cpus_allowed;
-	int node = pcibus_to_node(dev->bus);
-	if (node >= 0 && node_online(node))
+	int node = dev_to_node(&dev->dev);
+	if (node >= 0)
 	    set_cpus_allowed(current, node_to_cpumask(node));
 	/* And set default memory allocation policy */
 	oldpol = current->mempolicy;