From: Michal Hocko <mhocko@suse.cz>
To: Xishi Qiu <qiuxishi@huawei.com>
Cc: riel@redhat.com, walken@google.com, Linux MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
wangnan0@huawei.com
Subject: Re: [PATCH] mm: add ulimit API for user
Date: Mon, 6 Jan 2014 11:27:07 +0100 [thread overview]
Message-ID: <20140106102707.GA23730@dhcp22.suse.cz> (raw)
In-Reply-To: <52C28AAA.5060707@huawei.com>
On Tue 31-12-13 17:13:14, Xishi Qiu wrote:
> Add ulimit API for users. When memory is not enough,
> user's app will receive a signal, and it can do something
> in the handler.
>
> e.g.
> #include <sys/mman.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> void handler(int sig)
> {
> char *b = malloc(1000000000);
> memset(b, '\0', 1000000000);
> printf("catch the signal by wwy\n");
> exit(1);
> }
> int main ( int argc, char *argv[] )
> {
> struct rlimit r1 = { 3600000000, 3600000000};
> setrlimit(RLIMIT_AS, &r1);
> signal(47, &handler);
> char * a = malloc(3600000000);
> int fd=open("/home/wayne/qemu.tar.bz2", O_RDONLY);
> char abc[2000000] = {'\0'};
> mmap(NULL, 10000000, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd , 0);
> sleep(100);
> free(a);
> while(1){
> }
> }
>
> RTOS-x86_64 /tmp # ./a.out
> catch the signal by wwy
How does this demonstrate the newly added knob?
[...]
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 4ff7f52..a10155f 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2402,6 +2402,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> * Return true if the calling process may expand its vm space by the passed
> * number of pages
> */
> +
> +#ifdef CONFIG_ULIMIT_VM_SIG
> +unsigned long vm_expand_signal_enable = 0;
> +EXPORT_SYMBOL(vm_expand_signal_enable);
> +#endif
> +
> int may_expand_vm(struct mm_struct *mm, unsigned long npages)
> {
> unsigned long cur = mm->total_vm; /* pages */
> @@ -2410,7 +2415,9 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
> lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
>
> if (cur + npages > lim){
> - send_sig(SIGRTMIN+15, current, 1);
What kind of tree is this based on? Neither Linus' nor Andrew's tree
sends the signal. And I would be really surprised if such a change would
be accepted at all because may_expand_vm is not supposed to send a
signal. Only automatic stack expansion is supposed to send SEGV other
callers should simply return ENOMEM
> +#ifdef CONFIG_ULIMIT_VM_SIG
> + if (vm_expand_signal_enable){
> + send_sig(SIGRTMIN+15, current, 1);
> + }
> +#endif
> return 0;
> }
> return 1;
--
Michal Hocko
SUSE Labs
--
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>
prev parent reply other threads:[~2014-01-06 10:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-31 9:13 Xishi Qiu
2014-01-06 10:27 ` Michal Hocko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140106102707.GA23730@dhcp22.suse.cz \
--to=mhocko@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=qiuxishi@huawei.com \
--cc=riel@redhat.com \
--cc=walken@google.com \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox