diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index e4115a0d5ba6152852e43840eb56f702481d8bac..414c77299c7d8fbd3b2b49e6f6f39ba4284114f2 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "pci.h" /* @@ -163,6 +164,34 @@ const struct pci_device_id *pci_match_device(struct pci_driver *drv, return NULL; } +static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, + const struct pci_device_id *id) +{ + int error; +#ifdef CONFIG_NUMA + /* Execute driver initialization on node where the + device's bus is attached to. This way the driver likely + allocates its local memory on the right node without + 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)) + set_cpus_allowed(current, node_to_cpumask(node)); + /* And set default memory allocation policy */ + oldpol = current->mempolicy; + current->mempolicy = &default_policy; + mpol_get(current->mempolicy); +#endif + error = drv->probe(dev, id); +#ifdef CONFIG_NUMA + set_cpus_allowed(current, oldmask); + mpol_free(current->mempolicy); + current->mempolicy = oldpol; +#endif + return error; +} + /** * __pci_device_probe() * @@ -180,7 +209,7 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) id = pci_match_device(drv, pci_dev); if (id) - error = drv->probe(pci_dev, id); + error = pci_call_probe(drv, pci_dev, id); if (error >= 0) { pci_dev->driver = drv; error = 0; diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 94a46f38c5326f8a337c256e7ba6d209951e7a6b..58385ee1c0acc309aa862eab5f7b207110942f27 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -155,6 +155,7 @@ struct mempolicy *get_vma_policy(struct task_struct *task, extern void numa_default_policy(void); extern void numa_policy_init(void); +extern struct mempolicy default_policy; #else diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 13492d66b7c809ff603f6c996f5ea1aafbe51a34..afa06e184d88a93311708bdfb1e15077859e29c4 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -88,7 +88,7 @@ static kmem_cache_t *sn_cache; policied. */ static int policy_zone; -static struct mempolicy default_policy = { +struct mempolicy default_policy = { .refcnt = ATOMIC_INIT(1), /* never free it */ .policy = MPOL_DEFAULT, };