lkml.org 
[lkml]   [2018]   [Apr]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1] kernel/trace:check the val against the available mem
On Wed, 4 Apr 2018 16:23:29 +0200
Michal Hocko <mhocko@kernel.org> wrote:

> On Wed 04-04-18 10:11:49, Steven Rostedt wrote:
> > On Wed, 4 Apr 2018 08:23:40 +0200
> > Michal Hocko <mhocko@kernel.org> wrote:
> >
> > > If you are afraid of that then you can have a look at {set,clear}_current_oom_origin()
> > > which will automatically select the current process as an oom victim and
> > > kill it.
> >
> > Would it even receive the signal? Does alloc_pages_node() even respond
> > to signals? Because the OOM happens while the allocation loop is
> > running.
>
> Well, you would need to do something like:
>
> >
> > I tried it out, I did the following:
> >
> > set_current_oom_origin();
> > for (i = 0; i < nr_pages; i++) {
> > struct page *page;
> > /*
> > * __GFP_RETRY_MAYFAIL flag makes sure that the allocation fails
> > * gracefully without invoking oom-killer and the system is not
> > * destabilized.
> > */
> > bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()),
> > GFP_KERNEL | __GFP_RETRY_MAYFAIL,
> > cpu_to_node(cpu));
> > if (!bpage)
> > goto free_pages;
> >
> > list_add(&bpage->list, pages);
> >
> > page = alloc_pages_node(cpu_to_node(cpu),
> > GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
> > if (!page)
> > goto free_pages;
>
> if (fatal_signal_pending())
> fgoto free_pages;

But wouldn't page be NULL in this case?

>
> > bpage->page = page_address(page);
> > rb_init_page(bpage->page);
> > }
> > clear_current_oom_origin();
>
> If you use __GFP_RETRY_MAYFAIL it would have to be somedy else to
> trigger the OOM killer and this user context would get killed. If you
> drop __GFP_RETRY_MAYFAIL it would be this context to trigger the OOM but
> it would still be the selected victim.

Then we guarantee to kill the process instead of just sending a
-ENOMEM, which would change user space ABI, and is a NO NO.

Ideally, we want to avoid an OOM. I could add the above as well, when
si_mem_avaiable() returns something that is greater than what is
available, and at least this is the process that will get the OOM if it
fails to allocate.

Would that work for you?

-- Steve

\
 
 \ /
  Last update: 2018-04-04 16:31    [W:0.143 / U:7.644 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site