pseries/drmem: don't cache node id in drmem_lmb struct
RFC PATCH 1/1 pseries/drmem: don't cache node id in drmem_lmb struct
At memory hot-remove time we can retrieve an LMB's nid from its corresponding memory_block. There is no need to store the nid in multiple locations.
---
The linear search in powerpc's memory_add_physaddr_to_nid() has become a bottleneck at boot on systems with many LMBs.
As described in this patch here:
https://lore.kernel.org/linuxppc-dev/[email protected]/
the linear search seriously cripples drmem_init().
The obvious solution (shown in that patch) is to just make the search in memory_add_physaddr_to_nid() faster. An XArray seems well-suited to the task of mapping an address range to an LMB object.
The less obvious approach is to just call memory_add_physaddr_to_nid() in fewer places.
I'm not sure which approach is correct, hence the RFC.
The attached patch is an example of how we could just eliminate the memory_add_physaddr_to_nid() calls during drmem_init(). Unless this is somehow an abuse of the memory_block I think retrieving the nid in this way deduplicates memoization.
There is another spot where we don't *need* to search by address to find the node id. In dlpar_memory_add() we're calling lmb_set_nid(), which is just memory_add_physaddr_to_nid(). But we could easily bypass the search and call of_drconf_to_nid_single() directly with the LMB we already have a pointer to.
Then again, I see callers like the xen balloon driver and probe_store() that seemingly need to do an address-to-nid lookup.
So, does memory_add_physaddr_to_nid() need to be fast? Should I bite the bullet and make it fast so we can leverage it without slowdown? Or is calling it in fewer places an acceptable approach?
arch/powerpc/include/asm/drmem.h | 21 ------------------- arch/powerpc/mm/drmem.c | 6 +----- .../platforms/pseries/hotplug-memory.c | 19 ++++++++++------- 3 files changed, 13 insertions(+), 33 deletions(-)
arch/powerpc/include/asm/drmem.h +0 -21
@@ -13,9 +13,6 @@ struct drmem_lmb {u32 drc_index;u32 aa_index;u32 flags; -#ifdef CONFIG_MEMORY_HOTPLUG -int nid; -#endif };struct drmem_lmb_info {
@@ -103,22 +100,4 @@ static inline void invalidate_lmb_associativity_index(struct drmem_lmb *lmb) lmb->aa_index = 0xffffffff; } -#ifdef CONFIG_MEMORY_HOTPLUG -static inline void lmb_set_nid (struct drmem_lmb *lmb) -{ - lmb->nid =memory_add_physaddr_to_nid (lmb->base_addr); -} -static inline void lmb_clear_nid (struct drmem_lmb *lmb) -{ - lmb->nid =-1 ; -} -#else -static inline void lmb_set_nid (struct drmem_lmb *lmb) -{ -} -static inline void lmb_clear_nid (struct drmem_lmb *lmb) -{ -} -#endif -#endif /* _ASM_POWERPC_LMB_H */
arch/powerpc/mm/drmem.c +1 -5
@@ -362,10 +362,8 @@ static void __init init_drmem_v1_lmbs(const __be32 *prop)if (!drmem_info->lmbs)return ; -for_each_drmem_lmb (lmb) { +for_each_drmem_lmb (lmb)read_drconf_v1_cell (lmb, &prop); -lmb_set_nid (lmb); - } }static void __init init_drmem_v2_lmbs (const __be32 *prop)
@@ -410,8 +408,6 @@ static void __init init_drmem_v2_lmbs(const __be32 *prop) lmb->aa_index = dr_cell.aa_index; lmb->flags = dr_cell.flags; - -lmb_set_nid (lmb); } } }
arch/powerpc/platforms/pseries/hotplug-memory.c +12 -7
@@ -376,25 +376,29 @@ static int dlpar_add_lmb(struct drmem_lmb *);static int dlpar_remove_lmb (struct drmem_lmb *lmb) { +struct memory_block *mem_block;unsigned long block_sz;int rc;if (!lmb_is_removable (lmb))return -EINVAL ; + mem_block =lmb_to_memblock (lmb); +if (mem_block ==NULL ) +return -EINVAL ; + rc =dlpar_offline_lmb (lmb);if (rc)return rc; block_sz =pseries_memory_block_size (); -__remove_memory (lmb->nid, lmb->base_addr, block_sz); +__remove_memory (mem_block->nid, lmb->base_addr, block_sz);/* Update memory regions for memory remove */ memblock_remove (lmb->base_addr, block_sz);invalidate_lmb_associativity_index (lmb); -lmb_clear_nid (lmb); lmb->flags &= ~DRCONF_MEM_ASSIGNED ;return 0 ;
@@ -651,7 +655,7 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index)static int dlpar_add_lmb (struct drmem_lmb *lmb) {unsigned long block_sz; -int rc; +int nid, rc;if (lmb->flags &DRCONF_MEM_ASSIGNED )return -EINVAL ;
@@ -662,11 +666,13 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)return rc; } -lmb_set_nid (lmb); block_sz =memory_block_size_bytes (); +/* Find the node id for this address. */ + nid =memory_add_physaddr_to_nid (lmb->base_addr); +/* Add the memory */ - rc =__add_memory (lmb->nid, lmb->base_addr, block_sz); + rc =__add_memory (nid, lmb->base_addr, block_sz);if (rc) {invalidate_lmb_associativity_index (lmb);return rc;
@@ -674,9 +680,8 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb) rc =dlpar_online_lmb (lmb);if (rc) { -__remove_memory (lmb->nid, lmb->base_addr, block_sz); +__remove_memory (nid, lmb->base_addr, block_sz);invalidate_lmb_associativity_index (lmb); -lmb_clear_nid (lmb); }else { lmb->flags |=DRCONF_MEM_ASSIGNED ; }
Signature · 1 line
2.24.1
Quoted 15 lines · Scott Cheloha
At memory hot-remove time we can retrieve an LMB's nid from its corresponding
memory_block. There is no need to store the nid in multiple locations.Signed-off-by Scott Cheloha <[email protected]>---
The linear search in powerpc'smemory_add_physaddr_to_nid()has become a bottleneck at boot on systems with many LMBs.As described in this patch here:
https://lore.kernel.org/linuxppc-dev/[email protected]/
the linear search seriously cripples
drmem_init().
Quoted 8 lines
The obvious solution (shown in that patch) is to just make the search in
memory_add_physaddr_to_nid()faster. An XArray seems well-suited to the task of mapping an address range to an LMB object.The less obvious approach is to just call
memory_add_physaddr_to_nid()in fewer places.I'm not sure which approach is correct, hence the RFC.
You basically revert the below which will likely cause the very error that was fixed there:
commit b2d3b5ee66f2a04a918cc043cec0c9ed3de58f40
Author: Nathan Fontenot <[email protected]> Date: Tue Oct 2 10:35:59 2018 -0500
powerpc/pseries: Track LMB nid instead of using device tree
When removing memory we need to remove the memory from the node it was added to instead of looking up the node it should be in in the device tree.
During testing we have seen scenarios where the affinity for a LMB changes due to a partition migration or PRRN event. In these cases the node the LMB exists in may not match the node the device tree indicates it belongs in. This can lead to a system crash when trying to DLPAR remove the LMB after a migration or PRRN event. The current code looks up the node in the device tree to remove the LMB from, the crash occurs when we try to offline this node and it does not have any data, i.e. node_data[nid] == NULL.
Thanks
Michal
Hi Michal,
Quoted 38 lines · Michal Suchánek
Quoted 15 lines · Scott Cheloha
At memory hot-remove time we can retrieve an LMB's nid from its corresponding
memory_block. There is no need to store the nid in multiple locations.Signed-off-by Scott Cheloha <[email protected]>---
The linear search in powerpc'smemory_add_physaddr_to_nid()has become a bottleneck at boot on systems with many LMBs.As described in this patch here:
https://lore.kernel.org/linuxppc-dev/[email protected]/
the linear search seriously cripples
drmem_init().Quoted 8 lines
The obvious solution (shown in that patch) is to just make the search in
memory_add_physaddr_to_nid()faster. An XArray seems well-suited to the task of mapping an address range to an LMB object.The less obvious approach is to just call
memory_add_physaddr_to_nid()in fewer places.I'm not sure which approach is correct, hence the RFC.
You basically revert the below which will likely cause the very error that was fixed there:
commit
b2d3b5ee66f2a04a918cc043cec0c9ed3de58f40Author: Nathan Fontenot <[email protected]> Date: Tue Oct 2 10:35:59 2018 -0500powerpc/pseries: Track LMB nid instead of using device tree
When removing memory we need to remove the memory from the node it was added to instead of looking up the node it should be in in the device tree.
Quoted 8 lines
During testing we have seen scenarios where the affinity for a LMB changes due to a partition migration or PRRN event. In these cases the node the LMB exists in may not match the node the device tree indicates it belongs in. This can lead to a system crash when trying to DLPAR remove the LMB after a migration or PRRN event. The current code looks up the node in the device tree to remove the LMB from, the crash occurs when we try to offline this node and it does not have any data, i.e. node_data[nid] == NULL.
I'm aware of this patch and that this is a near-total revert.
I'm not reintroducing the original behavior, though. Instead of going to the device tree to recompute the expected node id I'm retrieving it from the LMB's corresponding memory_block.
That crucial difference is this chunk:
arch/powerpc/platforms/pseries/hotplug-memory.c +6 -2
@@ -376,25 +376,29 @@ static int dlpar_add_lmb(struct drmem_lmb *);static int dlpar_remove_lmb (struct drmem_lmb *lmb) { +struct memory_block *mem_block;unsigned long block_sz;int rc;if (!lmb_is_removable (lmb))return -EINVAL ; + mem_block =lmb_to_memblock (lmb); +if (mem_block ==NULL ) +return -EINVAL ; + rc =dlpar_offline_lmb (lmb);if (rc)return rc; block_sz =pseries_memory_block_size (); -__remove_memory (lmb->nid, lmb->base_addr, block_sz); +__remove_memory (mem_block->nid, lmb->base_addr, block_sz);/* Update memory regions for memory remove */ memblock_remove (lmb->base_addr, block_sz);invalidate_lmb_associativity_index (lmb); -lmb_clear_nid (lmb); lmb->flags &= ~DRCONF_MEM_ASSIGNED ;return 0 ;
---
Unless it's possible that the call:
__add_memory(my_nid, my_addr, my_size);
does not yield the following:
memory_block.nid == my_nid
on success, then I think the solution in my patch is equivalent to and simpler than the one introduced in the patch you quote.
Can you see a way the above would not hold?
Then again, maybe there's a good reason not to retrieve the node id in this way. I'm thinking David Hildenbrand and/or Nathan Fontenont may have some insight on that.
Quoted 41 lines · Scott Cheloha
Hi Michal,
Quoted 14 lines · Michal Suchánek
You basically revert the below which will likely cause the very error that was fixed there:
commit
b2d3b5ee66f2a04a918cc043cec0c9ed3de58f40Author: Nathan Fontenot <[email protected]> Date: Tue Oct 2 10:35:59 2018 -0500powerpc/pseries: Track LMB nid instead of using device tree
When removing memory we need to remove the memory from the node it was added to instead of looking up the node it should be in in the device tree.
Quoted 8 lines
During testing we have seen scenarios where the affinity for a LMB changes due to a partition migration or PRRN event. In these cases the node the LMB exists in may not match the node the device tree indicates it belongs in. This can lead to a system crash when trying to DLPAR remove the LMB after a migration or PRRN event. The current code looks up the node in the device tree to remove the LMB from, the crash occurs when we try to offline this node and it does not have any data, i.e. node_data[nid] == NULL.
I'm aware of this patch and that this is a near-total revert.
I'm not reintroducing the original behavior, though. Instead of going to the device tree to recompute the expected node id I'm retrieving it from the LMB's corresponding
memory_block.That crucial difference is this chunk:
arch/powerpc/platforms/pseries/hotplug-memory.c +1
-0@@ -376,25 +376,29 @@ static int dlpar_add_lmb(struct drmem_lmb *);static int dlpar_remove_lmb (struct drmem_lmb *lmb) { +struct memory_block *mem_block;
arch/powerpc/platforms/pseries/hotplug-memory.c static int dlpar_add_lmb(struct drmem_lmb *); · line 389
Quoted 10 lines
arch/powerpc/platforms/pseries/hotplug-memory.c +4
-0unsigned long block_sz;int rc;if (!lmb_is_removable (lmb))return -EINVAL ; + mem_block =lmb_to_memblock (lmb); +if (mem_block ==NULL ) +return -EINVAL ; +
Assuming lmb_to_memblock() -> find_memory_block() isn't engaging in O(n) behavior or worse (which is the case in linux-next), then I think Scott's change makes sense and is a net win.