mm, memcg: add a helper function to check may oom condition
Subsystems (5)
PATCH 1/1 mm, memcg: add a helper function to check may oom condition
Use helper function to check if we need to deal with oom condition.
--- include/linux/oom.h | 5 +++++ mm/memcontrol.c | 9 +-------- mm/page_alloc.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-)
include/linux/oom.h +5 -0
@@ -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 */
mm/memcontrol.c +1 -8
@@ -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 ) {/*
mm/page_alloc.c +1 -1
@@ -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 */
Signature · 1 line
1.8.3
David Rientjes
reviewerinclude/linux/oom.h static inline void oom_killer_enable(void) · line 85
Quoted 9 lines · Qiang Huang
include/linux/oom.h +1
-0@@ -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.
Quoted 7 lines
include/linux/oom.h +4
-0+{ +return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY); +} +extern struct task_struct *find_lock_task_mm (struct task_struct *p);/* sysctls */
Quoted 10 lines · David Rientjes
Quoted 8 lines · Qiang Huang
include/linux/oom.h +0
-0@@ -82,6 +82,11 @@ static inline void oom_killer_enable(void) oom_killer_disabled = false; }
Quoted 5 lines
include/linux/oom.h static inline void oom_killer_enable(void) · line 85
Quoted 1 line
include/linux/oom.h +1
-0+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.
Quoted 12 lines
Nice taste.
Quoted 7 lines
include/linux/oom.h +4
-0+{ +return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY); +} +extern struct task_struct *find_lock_task_mm (struct task_struct *p);/* sysctls */