* Re: [PATCH] mm: limit a process RSS
[not found] <1522655119-6317-1-git-send-email-lirongqing@baidu.com>
@ 2018-04-03 7:36 ` Michal Hocko
2018-04-03 8:20 ` 答复: " Li,Rongqing
0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2018-04-03 7:36 UTC (permalink / raw)
To: Li RongQing; +Cc: akpm, kirill.shutemov, jglisse, minchan, linux-mm
On Mon 02-04-18 15:45:19, Li RongQing wrote:
> we cannot limit a process RSS although there is ulimit -m,
> not sure why and when ulimit -m is not working, make it work
Could you be more specific about why do you need this functionality?
The RSS limit has never been implemented AFAIK and the main reason is
that the semantic is quite weak to be useful (e.g. the shared memory
accounting, resident memory that is not mapped etc.).
We have memory cgroup controller as an alternative.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread* 答复: [PATCH] mm: limit a process RSS
2018-04-03 7:36 ` [PATCH] mm: limit a process RSS Michal Hocko
@ 2018-04-03 8:20 ` Li,Rongqing
2018-04-03 8:29 ` Michal Hocko
0 siblings, 1 reply; 4+ messages in thread
From: Li,Rongqing @ 2018-04-03 8:20 UTC (permalink / raw)
To: Michal Hocko
Cc: akpm@linux-foundation.org, kirill.shutemov@linux.intel.com,
jglisse@redhat.com, minchan@kernel.org, linux-mm@kvack.org
> -----邮件原件-----
> 发件人: Michal Hocko [mailto:mhocko@kernel.org]
> 发送时间: 2018年4月3日 15:37
> 收件人: Li,Rongqing <lirongqing@baidu.com>
> 抄送: akpm@linux-foundation.org; kirill.shutemov@linux.intel.com;
> jglisse@redhat.com; minchan@kernel.org; linux-mm@kvack.org
> 主题: Re: [PATCH] mm: limit a process RSS
>
> On Mon 02-04-18 15:45:19, Li RongQing wrote:
> > we cannot limit a process RSS although there is ulimit -m, not sure
> > why and when ulimit -m is not working, make it work
>
> Could you be more specific about why do you need this functionality?
> The RSS limit has never been implemented AFAIK and the main reason is that
> the semantic is quite weak to be useful (e.g. the shared memory accounting,
> resident memory that is not mapped etc.).
avoid some buggy process will exhaust memory, sometime the engineer did not sure if an application has bug since lots of conditions are needed to trigger bug, like an application will take more and more memory when lots of request arrived.
This method give user an alternative
>
> We have memory cgroup controller as an alternative.
Memory cgroup is to control a group processes, But this method only control a process, if every process has a different limit, lots of cgroup need to create, if lots of cgroup, I think the cgroup maybe not efficient.
This method did not count pagecache, and this method takes less cpu.
-RongQing
> --
> Michal Hocko
> SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 答复: [PATCH] mm: limit a process RSS
2018-04-03 8:20 ` 答复: " Li,Rongqing
@ 2018-04-03 8:29 ` Michal Hocko
0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2018-04-03 8:29 UTC (permalink / raw)
To: Li,Rongqing
Cc: akpm@linux-foundation.org, kirill.shutemov@linux.intel.com,
jglisse@redhat.com, minchan@kernel.org, linux-mm@kvack.org
On Tue 03-04-18 08:20:05, Li,Rongqing wrote:
>
>
> > -----e?(R)a>>?a??a>>?-----
> > a??a>>?aoo: Michal Hocko [mailto:mhocko@kernel.org]
> > a??e??ae??e?': 2018a1'4ae??3ae?JPY 15:37
> > ae??a>>?aoo: Li,Rongqing <lirongqing@baidu.com>
> > ae??e??: akpm@linux-foundation.org; kirill.shutemov@linux.intel.com;
> > jglisse@redhat.com; minchan@kernel.org; linux-mm@kvack.org
> > a,>>ec?: Re: [PATCH] mm: limit a process RSS
> >
> > On Mon 02-04-18 15:45:19, Li RongQing wrote:
> > > we cannot limit a process RSS although there is ulimit -m, not sure
> > > why and when ulimit -m is not working, make it work
> >
> > Could you be more specific about why do you need this functionality?
> > The RSS limit has never been implemented AFAIK and the main reason is that
> > the semantic is quite weak to be useful (e.g. the shared memory accounting,
> > resident memory that is not mapped etc.).
>
> avoid some buggy process will exhaust memory, sometime the engineer
> did not sure if an application has bug since lots of conditions are
> needed to trigger bug, like an application will take more and more
> memory when lots of request arrived.
>
> This method give user an alternative
Which will not work in general.
> >
> > We have memory cgroup controller as an alternative.
>
> Memory cgroup is to control a group processes, But this method only
> control a process, if every process has a different limit, lots of
> cgroup need to create, if lots of cgroup, I think the cgroup maybe not
> efficient.
Why does each process need a separate limit? Processes usually run in
sessions with other related processes. If you have a standalone process
then nothing really prevents it from running inside a dedicated cgroup.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mm: limit a process RSS
@ 2018-03-30 5:11 Li RongQing
0 siblings, 0 replies; 4+ messages in thread
From: Li RongQing @ 2018-03-30 5:11 UTC (permalink / raw)
To: linux-mm, linux-kernel
we cannot limit a process RSS although there is ulimit -m,
not sure why and when ulimit -m is not working, make it work
similar requirement:
https://stackoverflow.com/questions/3360348/why-ulimit-cant-limit-resident-memory-successfully-and-how
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
mm/memory.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mm/memory.c b/mm/memory.c
index 5fcfc24904d1..50cf9399477c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4140,6 +4140,9 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
ret = __handle_mm_fault(vma, address, flags);
if (flags & FAULT_FLAG_USER) {
+ unsigned long total_rss = get_mm_rss(current->mm);
+ u64 rlimit;
+
mem_cgroup_oom_disable();
/*
* The task may have entered a memcg OOM situation but
@@ -4149,6 +4152,17 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
*/
if (task_in_memcg_oom(current) && !(ret & VM_FAULT_OOM))
mem_cgroup_oom_synchronize(false);
+
+ rlimit = current->signal->rlim[RLIMIT_RSS].rlim_cur;
+
+ if (unlikely(total_rss > (rlimit >> PAGE_SHIFT)) &&
+ (current->pid != 1)) {
+
+ pr_info("kill process %s rsslimit[%lluK] rss[%luK]\n",
+ current->comm, (rlimit >> 10),
+ total_rss << (PAGE_SHIFT - 10));
+ do_group_exit(SIGKILL);
+ }
}
return ret;
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-03 8:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1522655119-6317-1-git-send-email-lirongqing@baidu.com>
2018-04-03 7:36 ` [PATCH] mm: limit a process RSS Michal Hocko
2018-04-03 8:20 ` 答复: " Li,Rongqing
2018-04-03 8:29 ` Michal Hocko
2018-03-30 5:11 Li RongQing
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).