mm, show_mem: drop pgdat_resize_lock in show_mem()
Subsystems (2)
PATCH 1/1 mm, show_mem: drop pgdat_resize_lock in show_mem()
Function show_mem() is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.
The data protected by pgdat_resize_lock is mostly correct except there is:
* page struct defer init
* memory hotplug
--- lib/show_mem.c | 2 -- 1 file changed, 2 deletions(-)
lib/show_mem.c +0 -2
@@ -21,7 +21,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)unsigned long flags;int zoneid; -pgdat_resize_lock (pgdat, &flags);for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {struct zone *zone = &pgdat->node_zones[zoneid];if (!populated_zone (zone))
@@ -33,7 +32,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)if (is_highmem_idx (zoneid)) highmem += zone->present_pages; } -pgdat_resize_unlock (pgdat, &flags); }printk ("%lu pages RAM\n" , total);
Signature · 1 line
2.15.1
Andrew Morton
maintainerQuoted 8 lines · On Thu, 29 Nov 2018 05:08:15 +0800 Wei Yang <[email protected]> wrote:
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplug
What is the advantage in doing this? What problem does the taking of that lock cause?
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Thu, 29 Nov 2018 05:08:15 +0800 Wei Yang <[email protected]> wrote:
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.
Quoted 7 lines
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplugWhat is the advantage in doing this? What problem does the taking of that lock cause?
Michal and I had a discussion in https://patchwork.kernel.org/patch/10689759/
The purpose of this is to see whehter it is nessary to make pgdat_resize_lock IRQ context safe. After went through the code, most of the users are not from IRQ context.
If my understanding is correct, Michal's suggestion is to drop the lock here. (The second last reply from Michal.)
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 3 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.
I would drop the part after and
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplug
This is more confusing than helpful. I would just drop it.
The changelog doesn't explain what is done and why. The second one is much more important. I would say this
"
Function show_mem() is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be toleratable and the worst that could happen is to print an imprecise node state.
Drop the resize lock because this is the only place which might hold the lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
"
lib/show_mem.c void show_mem(unsigned int filter, nodemask_t *nodemask) · line 21
Quoted 12 lines
Signed-off-by Wei Yang <[email protected]>--- lib/show_mem.c | 2 -- 1 file changed, 2 deletions(-)lib/show_mem.c +0
-0@@ -21,7 +21,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)unsigned long flags;
btw. you want to drop flags.
Quoted 17 lines
lib/show_mem.c +0
-2int zoneid; -pgdat_resize_lock (pgdat, &flags);for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {struct zone *zone = &pgdat->node_zones[zoneid];if (!populated_zone (zone))@@ -33,7 +32,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)if (is_highmem_idx (zoneid)) highmem += zone->present_pages; } -pgdat_resize_unlock (pgdat, &flags); }printk ("%lu pages RAM\n" , total);Signature · 1 line
2.15.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 24 lines · Michal Hocko
Quoted 3 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.I would drop the part after and
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplugThis is more confusing than helpful. I would just drop it.
The changelog doesn't explain what is done and why. The second one is much more important. I would say this
"
Functionshow_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be toleratable and the worst that could happen is to print an imprecise node state.
Quoted 5 lines
Drop the resize lock because this is the only place which might hold the lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
"
Ah, I have to admit this is much clearer and easier for audience to understand the reason.
Thanks a lot.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Wei Yang <[email protected]>--- lib/show_mem.c | 2 -- 1 file changed, 2 deletions(-)
Quoted 8 lines
lib/show_mem.c void show_mem(unsigned int filter, nodemask_t *nodemask) · line 21
Quoted 6 lines
lib/show_mem.c +0
-0@@ -21,7 +21,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)unsigned long flags;btw. you want to drop flags.
Oops, what a shame . :-(
Quoted 21 lines
Quoted 17 lines
lib/show_mem.c +0
-2int zoneid; -pgdat_resize_lock (pgdat, &flags);for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {struct zone *zone = &pgdat->node_zones[zoneid];if (!populated_zone (zone))@@ -33,7 +32,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)if (is_highmem_idx (zoneid)) highmem += zone->present_pages; } -pgdat_resize_unlock (pgdat, &flags); }printk ("%lu pages RAM\n" , total);Signature · 1 line
2.15.1Signature · 2 lines
Michal Hocko SUSE Labs
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 17 lines · Michal Hocko
Quoted 3 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.I would drop the part after and
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplugThis is more confusing than helpful. I would just drop it.
The changelog doesn't explain what is done and why. The second one is much more important. I would say this
Quoted 8 lines
"
Functionshow_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be toleratable and the worst that could happen is to print an imprecise node state.Drop the resize lock because this is the only place which might hold the
As I mentioned in https://patchwork.kernel.org/patch/10689759/, there is one place used in __remove_zone(). I don't get your suggestion of this place. And is __remove_zone() could be called in IRQ context?
Quoted 5 lines
lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
"
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 25 lines · Wei Yang
Quoted 24 lines · Michal Hocko
Quoted 3 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.I would drop the part after and
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplugThis is more confusing than helpful. I would just drop it.
The changelog doesn't explain what is done and why. The second one is much more important. I would say this
"
Functionshow_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be toleratable and the worst that could happen is to print an imprecise node state.
Quoted 5 lines
Quoted 1 line
Drop the resize lock because this is the only place which might hold the
As I mentioned in https://patchwork.kernel.org/patch/10689759/, there is one place used in
__remove_zone(). I don't get your suggestion of this place. And is__remove_zone()could be called in IRQ context?
It is only called from __remove_pages and that one calls cond_resched so obviosly not.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 26 lines · Michal Hocko
Quoted 25 lines · Wei Yang
Quoted 24 lines · Michal Hocko
Quoted 3 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information and not willing to affect core mm subsystem.I would drop the part after and
Quoted 4 lines
The data protected by
pgdat_resize_lockis mostly correct except there is:* page struct defer init
* memory hotplugThis is more confusing than helpful. I would just drop it.
The changelog doesn't explain what is done and why. The second one is much more important. I would say this
"
Functionshow_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be toleratable and the worst that could happen is to print an imprecise node state.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Drop the resize lock because this is the only place which might hold the
As I mentioned in https://patchwork.kernel.org/patch/10689759/, there is one place used in
__remove_zone(). I don't get your suggestion of this place. And is__remove_zone()could be called in IRQ context?It is only called from
__remove_pagesand that one callscond_reschedso obviosly not.
Forgive my poor background knowledge, I went throught the code, but not found where call cond_resched.
__remove_pages()
release_mem_region_adjustable()
clear_zone_contiguous()
__remove_section()
unregister_memory_section()
__remove_zone()
sparse_remove_one_section()
set_zone_contiguous()Would you mind giving me a hint?
Quoted 3 lines
Signature · 2 lines
Michal Hocko SUSE Labs
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 1 line · Wei Yang
On Thu, Nov 29, 2018 at 04:49:22PM +0100, Michal Hocko wrote:
[...]
Quoted 16 lines
Quoted 3 lines
It is only called from
__remove_pagesand that one callscond_reschedso obviosly not.Forgive my poor background knowledge, I went throught the code, but not found where call
cond_resched.
__remove_pages()release_mem_region_adjustable() clear_zone_contiguous() __remove_section() unregister_memory_section() __remove_zone() sparse_remove_one_section() set_zone_contiguous()
Quoted 1 line
Would you mind giving me a hint?
This is the code as of 4.20-rc2
for (i = 0; i < sections_to_remove; i++) {
unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION;
cond_resched();
ret = __remove_section(zone, __pfn_to_section(pfn), map_offset,
altmap);
map_offset = 0;
if (ret)
break;
}Maybe things have changed in the meantime but in general the code is sleepable (e.g. release_mem_region_adjustable does GFP_KERNEL allocation) and that rules out IRQ context.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 34 lines · Michal Hocko
Quoted 1 line · Wei Yang
On Thu, Nov 29, 2018 at 04:49:22PM +0100, Michal Hocko wrote:
[...]
Quoted 16 lines
Quoted 3 lines
It is only called from
__remove_pagesand that one callscond_reschedso obviosly not.Forgive my poor background knowledge, I went throught the code, but not found where call
cond_resched.
__remove_pages()release_mem_region_adjustable() clear_zone_contiguous() __remove_section() unregister_memory_section() __remove_zone() sparse_remove_one_section() set_zone_contiguous()Quoted 1 line
Would you mind giving me a hint?
This is the code as of 4.20-rc2
for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; cond_resched(); ret = __remove_section(zone, __pfn_to_section(pfn), map_offset, altmap); map_offset = 0; if (ret) break; }
Quoted 3 lines
Maybe things have changed in the meantime but in general the code is sleepable (e.g.
release_mem_region_adjustabledoesGFP_KERNELallocation) and that rules out IRQ context.
Thanks, my code is not up to date.
Quoted 3 lines
Signature · 2 lines
Michal Hocko SUSE Labs
Signature · 2 lines
Wei Yang Help you, Help me
PATCH v2 1/1 mm, show_mem: drop pgdat_resize_lock in show_mem()
In reply to Wei YangFunction show_mem() is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be tolerable and the worst that could happen is to print an imprecise node state.
Drop the resize lock because this is the only place which might hold the lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
---
v2:
* adjust the changelog to show the reason of this change
* remove unused variable flags
--- lib/show_mem.c | 3 --- 1 file changed, 3 deletions(-)
lib/show_mem.c +0 -3
@@ -18,10 +18,8 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)show_free_areas (filter, nodemask);for_each_online_pgdat (pgdat) { -unsigned long flags;int zoneid; -pgdat_resize_lock (pgdat, &flags);for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {struct zone *zone = &pgdat->node_zones[zoneid];if (!populated_zone (zone))
@@ -33,7 +31,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)if (is_highmem_idx (zoneid)) highmem += zone->present_pages; } -pgdat_resize_unlock (pgdat, &flags); }printk ("%lu pages RAM\n" , total);
Signature · 1 line
2.15.1
Quoted 6 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be tolerable and the worst that could happen is to print an imprecise node state.
Quoted 6 lines
Drop the resize lock because this is the only place which might hold the lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
Signed-off-by Wei Yang <[email protected]>
Quoted 35 lines
---
v2:
* adjust the changelog to show the reason of this change
* remove unused variable flags--- lib/show_mem.c | 3 --- 1 file changed, 3 deletions(-)lib/show_mem.c +0
-3@@ -18,10 +18,8 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)show_free_areas (filter, nodemask);for_each_online_pgdat (pgdat) { -unsigned long flags;int zoneid; -pgdat_resize_lock (pgdat, &flags);for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {struct zone *zone = &pgdat->node_zones[zoneid];if (!populated_zone (zone))@@ -33,7 +31,6 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)if (is_highmem_idx (zoneid)) highmem += zone->present_pages; } -pgdat_resize_unlock (pgdat, &flags); }printk ("%lu pages RAM\n" , total);Signature · 1 line
2.15.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 11 lines · Wei Yang
Function
show_mem()is used to print system memory status when user requires or fail to allocate memory. Generally, this is a best effort information so any races with memory hotplug (or very theoretically an early initialization) should be tolerable and the worst that could happen is to print an imprecise node state.Drop the resize lock because this is the only place which might hold the lock from the interrupt context and so all other callers might use a simple spinlock. Even though this doesn't solve any real issue it makes the code easier to follow and tiny more effective.
Signed-off-by Wei Yang <[email protected]>