Skip to content

Commit b2ca916

Browse files
committed
ACPI: NUMA: Up-level "map to online node" functionality
The acpi_map_pxm_to_online_node() helper is used to find the closest online node to a given proximity domain. This is used to map devices in a proximity domain with no online memory or cpus to the closest online node and populate a device's 'numa_node' property. The numa_node property allows applications to be migrated "close" to a resource. In preparation for providing a generic facility to optionally map an address range to its closest online node, or the node the range would represent were it to be onlined (target_node), up-level the core of acpi_map_pxm_to_online_node() to a generic mm/numa helper. Cc: Michal Hocko <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Signed-off-by: Dan Williams <[email protected]> Link: https://lore.kernel.org/r/158188324802.894464.13128795207831894206.stgit@dwillia2-desk3.amr.corp.intel.com
1 parent bb6d3fb commit b2ca916

File tree

4 files changed

+61
-42
lines changed

4 files changed

+61
-42
lines changed

drivers/acpi/numa/srat.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,6 @@ int acpi_map_pxm_to_node(int pxm)
7272
}
7373
EXPORT_SYMBOL(acpi_map_pxm_to_node);
7474

75-
/**
76-
* acpi_map_pxm_to_online_node - Map proximity ID to online node
77-
* @pxm: ACPI proximity ID
78-
*
79-
* This is similar to acpi_map_pxm_to_node(), but always returns an online
80-
* node. When the mapped node from a given proximity ID is offline, it
81-
* looks up the node distance table and returns the nearest online node.
82-
*
83-
* ACPI device drivers, which are called after the NUMA initialization has
84-
* completed in the kernel, can call this interface to obtain their device
85-
* NUMA topology from ACPI tables. Such drivers do not have to deal with
86-
* offline nodes. A node may be offline when a device proximity ID is
87-
* unique, SRAT memory entry does not exist, or NUMA is disabled, ex.
88-
* "numa=off" on x86.
89-
*/
90-
int acpi_map_pxm_to_online_node(int pxm)
91-
{
92-
int node, min_node;
93-
94-
node = acpi_map_pxm_to_node(pxm);
95-
96-
if (node == NUMA_NO_NODE)
97-
node = 0;
98-
99-
min_node = node;
100-
if (!node_online(node)) {
101-
int min_dist = INT_MAX, dist, n;
102-
103-
for_each_online_node(n) {
104-
dist = node_distance(node, n);
105-
if (dist < min_dist) {
106-
min_dist = dist;
107-
min_node = n;
108-
}
109-
}
110-
}
111-
112-
return min_node;
113-
}
114-
EXPORT_SYMBOL(acpi_map_pxm_to_online_node);
115-
11675
static void __init
11776
acpi_table_print_srat_entry(struct acpi_subtable_header *header)
11877
{

include/linux/acpi.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,30 @@ extern void acpi_osi_setup(char *str);
416416
extern bool acpi_osi_is_win8(void);
417417

418418
#ifdef CONFIG_ACPI_NUMA
419-
int acpi_map_pxm_to_online_node(int pxm);
420419
int acpi_map_pxm_to_node(int pxm);
421420
int acpi_get_node(acpi_handle handle);
421+
422+
/**
423+
* acpi_map_pxm_to_online_node - Map proximity ID to online node
424+
* @pxm: ACPI proximity ID
425+
*
426+
* This is similar to acpi_map_pxm_to_node(), but always returns an online
427+
* node. When the mapped node from a given proximity ID is offline, it
428+
* looks up the node distance table and returns the nearest online node.
429+
*
430+
* ACPI device drivers, which are called after the NUMA initialization has
431+
* completed in the kernel, can call this interface to obtain their device
432+
* NUMA topology from ACPI tables. Such drivers do not have to deal with
433+
* offline nodes. A node may be offline when a device proximity ID is
434+
* unique, SRAT memory entry does not exist, or NUMA is disabled, ex.
435+
* "numa=off" on x86.
436+
*/
437+
static inline int acpi_map_pxm_to_online_node(int pxm)
438+
{
439+
int node = acpi_map_pxm_to_node(pxm);
440+
441+
return numa_map_to_online_node(node);
442+
}
422443
#else
423444
static inline int acpi_map_pxm_to_online_node(int pxm)
424445
{

include/linux/numa.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@
1313

1414
#define NUMA_NO_NODE (-1)
1515

16+
#ifdef CONFIG_NUMA
17+
int numa_map_to_online_node(int node);
18+
#else
19+
static inline int numa_map_to_online_node(int node)
20+
{
21+
return NUMA_NO_NODE;
22+
}
23+
#endif
24+
1625
#endif /* _LINUX_NUMA_H */

mm/mempolicy.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ static struct mempolicy default_policy = {
127127

128128
static struct mempolicy preferred_node_policy[MAX_NUMNODES];
129129

130+
/**
131+
* numa_map_to_online_node - Find closest online node
132+
* @nid: Node id to start the search
133+
*
134+
* Lookup the next closest node by distance if @nid is not online.
135+
*/
136+
int numa_map_to_online_node(int node)
137+
{
138+
int min_node;
139+
140+
if (node == NUMA_NO_NODE)
141+
node = 0;
142+
143+
min_node = node;
144+
if (!node_online(node)) {
145+
int min_dist = INT_MAX, dist, n;
146+
147+
for_each_online_node(n) {
148+
dist = node_distance(node, n);
149+
if (dist < min_dist) {
150+
min_dist = dist;
151+
min_node = n;
152+
}
153+
}
154+
}
155+
156+
return min_node;
157+
}
158+
EXPORT_SYMBOL_GPL(numa_map_to_online_node);
159+
130160
struct mempolicy *get_task_policy(struct task_struct *p)
131161
{
132162
struct mempolicy *pol = p->mempolicy;

0 commit comments

Comments
 (0)