memcg: avoid overflow in memcg_hierarchical_free_pages()
Subsystems (2)
PATCH 1/1 memcg: avoid overflow in memcg_hierarchical_free_pages()
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
--- mm/memcontrol.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
mm/memcontrol.c +5 -5
@@ -1345,17 +1345,17 @@ memcg_hierarchical_free_pages(struct mem_cgroup *mem) {unsigned long free, min_free; - min_free =global_page_state (NR_FREE_PAGES ) <<PAGE_SHIFT ; + min_free =global_page_state (NR_FREE_PAGES );while (mem) { - free =res_counter_read_u64 (&mem->res,RES_LIMIT ) - -res_counter_read_u64 (&mem->res,RES_USAGE ); + free = (res_counter_read_u64 (&mem->res,RES_LIMIT ) - +res_counter_read_u64 (&mem->res,RES_USAGE )) >> +PAGE_SHIFT ; min_free =min (min_free, free); mem =parent_mem_cgroup (mem); } -/* Translate free memory in pages */ -return min_free >>PAGE_SHIFT ; +return min_free; }/*
Signature · 1 line
1.7.3.1
Quoted 4 lines · Greg Thelen
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
Signed-off-by Greg Thelen <[email protected]>
Signature · 9 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Greg Thelen
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
Signed-off-by Greg Thelen <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 13 lines · On Mon, 8 Nov 2010 17:15:20 -0800 Greg Thelen <[email protected]> wrote:
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
Signed-off-by Greg Thelen <[email protected]>--- mm/memcontrol.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)mm/memcontrol.c +0
-0
mm/memcontrol.c memcg_hierarchical_free_pages(struct mem_cgroup *mem) · line 1347
Quoted 3 lines
mm/memcontrol.c +0
-0@@ -1345,17 +1345,17 @@ memcg_hierarchical_free_pages(struct mem_cgroup *mem) {unsigned long free, min_free;
hmm, the default value of RES_LIMIT is LLONG_MAX, so I think we must declare "free" as unsinged long long to avoid overflow.
Thanks,
Daisuke Nishimura.
Quoted 22 lines
mm/memcontrol.c +5
-5- min_free =global_page_state (NR_FREE_PAGES ) <<PAGE_SHIFT ; + min_free =global_page_state (NR_FREE_PAGES );while (mem) { - free =res_counter_read_u64 (&mem->res,RES_LIMIT ) - -res_counter_read_u64 (&mem->res,RES_USAGE ); + free = (res_counter_read_u64 (&mem->res,RES_LIMIT ) - +res_counter_read_u64 (&mem->res,RES_USAGE )) >> +PAGE_SHIFT ; min_free =min (min_free, free); mem =parent_mem_cgroup (mem); } -/* Translate free memory in pages */ -return min_free >>PAGE_SHIFT ; +return min_free; }/* Signature · 1 line
1.7.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Daisuke Nishimura
Quoted 8 lines · On Mon, 8 Nov 2010 17:15:20 -0800 Greg Thelen <[email protected]> wrote:
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
Signed-off-by Greg Thelen <[email protected]>---
mm/memcontrol.c | 10 +++++-----1 files changed, 5 insertions(+), 5 deletions(-)
Quoted 10 lines
mm/memcontrol.c memcg_hierarchical_free_pages(struct mem_cgroup *mem) · line 1347
Quoted 8 lines
mm/memcontrol.c +0
-0@@ -1345,17 +1345,17 @@ memcg_hierarchical_free_pages(struct mem_cgroup *mem) { unsigned long free, min_free;hmm, the default value of
RES_LIMITisLLONG_MAX, so I think we must declare "free" as unsinged long long to avoid overflow.
Agreed. I am testing a fix for that issue now. I do not want complicate this patch with the RES_LIMIT issue you mention. The fix will be in a separate patch.
Quoted 26 lines
Thanks,
Daisuke Nishimura.Quoted 22 lines
mm/memcontrol.c +5
-6- min_free = global_page_state(NR_FREE_PAGES) << PAGE_SHIFT; + min_free = global_page_state(NR_FREE_PAGES); while (mem) { - free = res_counter_read_u64(&mem->res, RES_LIMIT) - - res_counter_read_u64(&mem->res, RES_USAGE); + free = (res_counter_read_u64(&mem->res, RES_LIMIT) - + res_counter_read_u64(&mem->res, RES_USAGE)) >> + PAGE_SHIFT; min_free = min(min_free, free); mem = parent_mem_cgroup(mem); } - /* Translate free memory in pages */ - return min_free >> PAGE_SHIFT; + return min_free; } /* -- 1.7.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · On Mon, 8 Nov 2010 17:15:20 -0800 Greg Thelen <[email protected]> wrote:
Use page counts rather than byte counts to avoid overflowing unsigned long local variables.
Signed-off-by Greg Thelen <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>