diff options
author | Dan Williams <dan.j.williams@intel.com> | 2015-10-05 20:35:55 -0400 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2015-10-09 17:00:33 -0400 |
commit | 7c683941f30a977c10ec6be174ec5f16939c7ce5 (patch) | |
tree | d63025ea6a08b89a9bcc0db8a5a256e70610d4ec | |
parent | b36f47617f6ce7c5e8e7c264b9d9ea0654d9f20a (diff) |
devm: make allocations numa aware by default
Given we already have a device just use dev_to_node() to provide hint
allocations for devres. However, current devres_alloc() users will need
to explicitly opt-in with devres_alloc_node().
Reviewed-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r-- | drivers/base/devres.c | 19 | ||||
-rw-r--r-- | include/linux/device.h | 16 |
2 files changed, 22 insertions, 13 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 875464690117..8fc654f0807b 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c | |||
@@ -82,12 +82,12 @@ static struct devres_group * node_to_group(struct devres_node *node) | |||
82 | } | 82 | } |
83 | 83 | ||
84 | static __always_inline struct devres * alloc_dr(dr_release_t release, | 84 | static __always_inline struct devres * alloc_dr(dr_release_t release, |
85 | size_t size, gfp_t gfp) | 85 | size_t size, gfp_t gfp, int nid) |
86 | { | 86 | { |
87 | size_t tot_size = sizeof(struct devres) + size; | 87 | size_t tot_size = sizeof(struct devres) + size; |
88 | struct devres *dr; | 88 | struct devres *dr; |
89 | 89 | ||
90 | dr = kmalloc_track_caller(tot_size, gfp); | 90 | dr = kmalloc_node_track_caller(tot_size, gfp, nid); |
91 | if (unlikely(!dr)) | 91 | if (unlikely(!dr)) |
92 | return NULL; | 92 | return NULL; |
93 | 93 | ||
@@ -106,24 +106,25 @@ static void add_dr(struct device *dev, struct devres_node *node) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | #ifdef CONFIG_DEBUG_DEVRES | 108 | #ifdef CONFIG_DEBUG_DEVRES |
109 | void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp, | 109 | void * __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, |
110 | const char *name) | 110 | const char *name) |
111 | { | 111 | { |
112 | struct devres *dr; | 112 | struct devres *dr; |
113 | 113 | ||
114 | dr = alloc_dr(release, size, gfp | __GFP_ZERO); | 114 | dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid); |
115 | if (unlikely(!dr)) | 115 | if (unlikely(!dr)) |
116 | return NULL; | 116 | return NULL; |
117 | set_node_dbginfo(&dr->node, name, size); | 117 | set_node_dbginfo(&dr->node, name, size); |
118 | return dr->data; | 118 | return dr->data; |
119 | } | 119 | } |
120 | EXPORT_SYMBOL_GPL(__devres_alloc); | 120 | EXPORT_SYMBOL_GPL(__devres_alloc_node); |
121 | #else | 121 | #else |
122 | /** | 122 | /** |
123 | * devres_alloc - Allocate device resource data | 123 | * devres_alloc - Allocate device resource data |
124 | * @release: Release function devres will be associated with | 124 | * @release: Release function devres will be associated with |
125 | * @size: Allocation size | 125 | * @size: Allocation size |
126 | * @gfp: Allocation flags | 126 | * @gfp: Allocation flags |
127 | * @nid: NUMA node | ||
127 | * | 128 | * |
128 | * Allocate devres of @size bytes. The allocated area is zeroed, then | 129 | * Allocate devres of @size bytes. The allocated area is zeroed, then |
129 | * associated with @release. The returned pointer can be passed to | 130 | * associated with @release. The returned pointer can be passed to |
@@ -132,16 +133,16 @@ EXPORT_SYMBOL_GPL(__devres_alloc); | |||
132 | * RETURNS: | 133 | * RETURNS: |
133 | * Pointer to allocated devres on success, NULL on failure. | 134 | * Pointer to allocated devres on success, NULL on failure. |
134 | */ | 135 | */ |
135 | void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp) | 136 | void * devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid) |
136 | { | 137 | { |
137 | struct devres *dr; | 138 | struct devres *dr; |
138 | 139 | ||
139 | dr = alloc_dr(release, size, gfp | __GFP_ZERO); | 140 | dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid); |
140 | if (unlikely(!dr)) | 141 | if (unlikely(!dr)) |
141 | return NULL; | 142 | return NULL; |
142 | return dr->data; | 143 | return dr->data; |
143 | } | 144 | } |
144 | EXPORT_SYMBOL_GPL(devres_alloc); | 145 | EXPORT_SYMBOL_GPL(devres_alloc_node); |
145 | #endif | 146 | #endif |
146 | 147 | ||
147 | /** | 148 | /** |
@@ -776,7 +777,7 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) | |||
776 | struct devres *dr; | 777 | struct devres *dr; |
777 | 778 | ||
778 | /* use raw alloc_dr for kmalloc caller tracing */ | 779 | /* use raw alloc_dr for kmalloc caller tracing */ |
779 | dr = alloc_dr(devm_kmalloc_release, size, gfp); | 780 | dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev)); |
780 | if (unlikely(!dr)) | 781 | if (unlikely(!dr)) |
781 | return NULL; | 782 | return NULL; |
782 | 783 | ||
diff --git a/include/linux/device.h b/include/linux/device.h index 5d7bc6349930..b8f411b57dcb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -604,13 +604,21 @@ typedef void (*dr_release_t)(struct device *dev, void *res); | |||
604 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); | 604 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); |
605 | 605 | ||
606 | #ifdef CONFIG_DEBUG_DEVRES | 606 | #ifdef CONFIG_DEBUG_DEVRES |
607 | extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, | 607 | extern void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
608 | const char *name); | 608 | int nid, const char *name); |
609 | #define devres_alloc(release, size, gfp) \ | 609 | #define devres_alloc(release, size, gfp) \ |
610 | __devres_alloc(release, size, gfp, #release) | 610 | __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) |
611 | #define devres_alloc_node(release, size, gfp, nid) \ | ||
612 | __devres_alloc_node(release, size, gfp, nid, #release) | ||
611 | #else | 613 | #else |
612 | extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); | 614 | extern void *devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
615 | int nid); | ||
616 | static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp) | ||
617 | { | ||
618 | return devres_alloc_node(release, size, gfp, NUMA_NO_NODE); | ||
619 | } | ||
613 | #endif | 620 | #endif |
621 | |||
614 | extern void devres_for_each_res(struct device *dev, dr_release_t release, | 622 | extern void devres_for_each_res(struct device *dev, dr_release_t release, |
615 | dr_match_t match, void *match_data, | 623 | dr_match_t match, void *match_data, |
616 | void (*fn)(struct device *, void *, void *), | 624 | void (*fn)(struct device *, void *, void *), |