@@ -1334,6 +1334,9 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
share_hotadd_m2p_table(&info);
transfer_pages_to_heap(&info);
+ /* Update the node's present pages (like the total_pages of the system) */
+ NODE_DATA(node)->node_present_pages += epfn - spfn;
+
return 0;
destroy_m2p:
@@ -499,15 +499,41 @@ int __init compute_hash_shift(const struct node *nodes,
return shift;
}
-/* Initialize NODE_DATA given nodeid and start/end */
+/**
+ * @brief Initialize a NUMA node's NODE_DATA given nodeid and start/end addrs.
+ *
+ * This function sets up the boot memory for a given NUMA node by calculating
+ * the node's start and end page frame numbers (PFNs) and determining
+ * the number of present RAM pages within the node's memory range.
+ *
+ * @param nodeid The identifier of the node to initialize.
+ * @param start The starting physical address of the node's memory range.
+ * @param end The ending physical address of the node's memory range.
+ */
void __init setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_t end)
{
unsigned long start_pfn = paddr_to_pfn(start);
unsigned long end_pfn = paddr_to_pfn(end);
+ unsigned long ram_start_pfn, ram_end_pfn;
+ unsigned int idx = 0;
+ int err;
+ paddr_t ram_start, ram_end;
NODE_DATA(nodeid)->node_start_pfn = start_pfn;
NODE_DATA(nodeid)->node_spanned_pages = end_pfn - start_pfn;
+ /* Calculate the numer of present RAM pages within the node: */
+ NODE_DATA(nodeid)->node_present_pages = 0;
+ while ( (err = arch_get_ram_range(idx++, &ram_start, &ram_end)) != -ENOENT )
+ {
+ if ( err || ram_start >= end || ram_end <= start )
+ continue; /* Not RAM (err != 0) or range is outside the node */
+
+ /* Add RAM that in the node's memory range (within start and end): */
+ ram_end_pfn = min(ram_end, end) >> PAGE_SHIFT;
+ ram_start_pfn = (PAGE_ALIGN(max(ram_start, start))) >> PAGE_SHIFT;
+ NODE_DATA(nodeid)->node_present_pages += ram_end_pfn - ram_start_pfn;
+ }
node_set_online(nodeid);
}
@@ -71,6 +71,7 @@ extern nodeid_t *memnodemap;
struct node_data {
unsigned long node_start_pfn;
unsigned long node_spanned_pages;
+ unsigned long node_present_pages;
};
extern struct node_data node_data[];
@@ -91,6 +92,7 @@ static inline nodeid_t mfn_to_nid(mfn_t mfn)
#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
#define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages)
+#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages)
#define node_end_pfn(nid) (NODE_DATA(nid)->node_start_pfn + \
NODE_DATA(nid)->node_spanned_pages)
@@ -123,6 +125,7 @@ extern void numa_set_processor_nodes_parsed(nodeid_t node);
extern mfn_t first_valid_mfn;
#define node_spanned_pages(nid) (max_page - mfn_x(first_valid_mfn))
+#define node_present_pages(nid) total_pages
#define node_start_pfn(nid) mfn_x(first_valid_mfn)
#define __node_distance(a, b) 20