linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, memcg: add a helper function to check may oom condition
@ 2013-09-09  2:18 Qiang Huang
  2013-09-09 20:22 ` David Rientjes
  0 siblings, 1 reply; 3+ messages in thread
From: Qiang Huang @ 2013-09-09  2:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Michal Hocko, hannes, Li Zefan, Cgroups, linux-mm

Use helper function to check if we need to deal with oom condition.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
---
 include/linux/oom.h | 5 +++++
 mm/memcontrol.c     | 9 +--------
 mm/page_alloc.c     | 2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/linux/oom.h b/include/linux/oom.h
index da60007..d061c63 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -82,6 +82,11 @@ static inline void oom_killer_enable(void)
 	oom_killer_disabled = false;
 }

+static inline bool may_oom(gfp_t gfp_mask)
+{
+	return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY);
+}
+
 extern struct task_struct *find_lock_task_mm(struct task_struct *p);

 /* sysctls */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b73988a..e07fcfa 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2910,21 +2910,14 @@ static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
 	struct res_counter *fail_res;
 	struct mem_cgroup *_memcg;
 	int ret = 0;
-	bool may_oom;

 	ret = res_counter_charge(&memcg->kmem, size, &fail_res);
 	if (ret)
 		return ret;

-	/*
-	 * Conditions under which we can wait for the oom_killer. Those are
-	 * the same conditions tested by the core page allocator
-	 */
-	may_oom = (gfp & __GFP_FS) && !(gfp & __GFP_NORETRY);
-
 	_memcg = memcg;
 	ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT,
-				      &_memcg, may_oom);
+				      &_memcg, may_oom(gfp));

 	if (ret == -EINTR)  {
 		/*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index b7c612d..42af675 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2589,7 +2589,7 @@ rebalance:
 	 * running out of options and have to consider going OOM
 	 */
 	if (!did_some_progress) {
-		if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
+		if (may_oom(gfp_mask)) {
 			if (oom_killer_disabled)
 				goto nopage;
 			/* Coredumps can quickly deplete all memory reserves */
-- 
1.8.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm, memcg: add a helper function to check may oom condition
  2013-09-09  2:18 [PATCH] mm, memcg: add a helper function to check may oom condition Qiang Huang
@ 2013-09-09 20:22 ` David Rientjes
  2013-09-10  0:57   ` Qiang Huang
  0 siblings, 1 reply; 3+ messages in thread
From: David Rientjes @ 2013-09-09 20:22 UTC (permalink / raw)
  To: Qiang Huang
  Cc: Andrew Morton, Michal Hocko, hannes, Li Zefan, Cgroups, linux-mm

On Mon, 9 Sep 2013, Qiang Huang wrote:

> diff --git a/include/linux/oom.h b/include/linux/oom.h
> index da60007..d061c63 100644
> --- a/include/linux/oom.h
> +++ b/include/linux/oom.h
> @@ -82,6 +82,11 @@ static inline void oom_killer_enable(void)
>  	oom_killer_disabled = false;
>  }
> 
> +static inline bool may_oom(gfp_t gfp_mask)

Makes sense, but I think the name should be more specific to gfp flags to 
make it clear what it's using to determine eligibility, maybe oom_gfp_allowed()? 
We usually prefix oom killer functions with "oom".

Nice taste.

> +{
> +	return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY);
> +}
> +
>  extern struct task_struct *find_lock_task_mm(struct task_struct *p);
> 
>  /* sysctls */

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm, memcg: add a helper function to check may oom condition
  2013-09-09 20:22 ` David Rientjes
@ 2013-09-10  0:57   ` Qiang Huang
  0 siblings, 0 replies; 3+ messages in thread
From: Qiang Huang @ 2013-09-10  0:57 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Michal Hocko, hannes, Li Zefan, Cgroups, linux-mm

On 2013/9/10 4:22, David Rientjes wrote:
> On Mon, 9 Sep 2013, Qiang Huang wrote:
> 
>> diff --git a/include/linux/oom.h b/include/linux/oom.h
>> index da60007..d061c63 100644
>> --- a/include/linux/oom.h
>> +++ b/include/linux/oom.h
>> @@ -82,6 +82,11 @@ static inline void oom_killer_enable(void)
>>  	oom_killer_disabled = false;
>>  }
>>
>> +static inline bool may_oom(gfp_t gfp_mask)
> 
> Makes sense, but I think the name should be more specific to gfp flags to 
> make it clear what it's using to determine eligibility, maybe oom_gfp_allowed()? 
> We usually prefix oom killer functions with "oom".

Yes, oom_gfp_allowed() seems better, I'll send a second version,
thanks for you advice, David.

> 
> Nice taste.
> 
>> +{
>> +	return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY);
>> +}
>> +
>>  extern struct task_struct *find_lock_task_mm(struct task_struct *p);
>>
>>  /* sysctls */
> 
> 


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-10  0:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-09  2:18 [PATCH] mm, memcg: add a helper function to check may oom condition Qiang Huang
2013-09-09 20:22 ` David Rientjes
2013-09-10  0:57   ` Qiang Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox