Re: [PATCH] ring-buffer: Add set/clear_current_oom_origin() during allocations

From: Joel Fernandes
Date: Wed Apr 04 2018 - 12:03:56 EST


On Wed, Apr 4, 2018 at 9:00 AM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Wed, 4 Apr 2018 11:53:10 -0400
> Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
>> @@ -1162,35 +1163,60 @@ static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer)
>> static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu)
>> {
>> struct buffer_page *bpage, *tmp;
>> + bool user_thread = current->mm != NULL;
>> + gfp_t mflags;
>> long i;
>>
>> - /* Check if the available memory is there first */
>> + /*
>> + * Check if the available memory is there first.
>> + * Note, si_mem_available() only gives us a rough estimate of available
>> + * memory. It may not be accurate. But we don't care, we just want
>> + * to prevent doing any allocation when it is obvious that it is
>> + * not going to succeed.
>> + */
>
> In case you are wondering how I tested this, I simply added:
>
> #if 0
>> i = si_mem_available();
>> if (i < nr_pages)
>> return -ENOMEM;
> #endif
>
> for the tests. Note, without this, I tried to allocate all memory
> (bisecting it with allocations that failed and allocations that
> succeeded), and couldn't trigger an OOM :-/

I guess you need to have something *else* other than the write to
buffer_size_kb doing the GFP_KERNEL allocations but unfortunately gets
OOM killed?

Also, I agree with the new patch and its nice idea to do that.

thanks,

- Joel