Re: [patch 2/2] mm, oom: fix race when specifying a thread as the oom origin

From: Thiago Farina
Date: Mon Nov 12 2012 - 17:14:31 EST


On Thu, Nov 8, 2012 at 1:51 PM, Michal Hocko <mhocko@xxxxxxx> wrote:
> On Thu 08-11-12 01:27:00, David Rientjes wrote:
>> test_set_oom_score_adj() and compare_swap_oom_score_adj() are used to
>> specify that current should be killed first if an oom condition occurs in
>> between the two calls.
>>
>> The usage is
>>
>> short oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
>> ...
>> compare_swap_oom_score_adj(OOM_SCORE_ADJ_MAX, oom_score_adj);
>>
>> to store the thread's oom_score_adj, temporarily change it to the maximum
>> score possible, and then restore the old value if it is still the same.
>>
>> This happens to still be racy, however, if the user writes
>> OOM_SCORE_ADJ_MAX to /proc/pid/oom_score_adj in between the two calls.
>> The compare_swap_oom_score_adj() will then incorrectly reset the old
>> value prior to the write of OOM_SCORE_ADJ_MAX.
>>
>> To fix this, introduce a new oom_flags_t member in struct signal_struct
>> that will be used for per-thread oom killer flags. KSM and swapoff can
>> now use a bit in this member to specify that threads should be killed
>> first in oom conditions without playing around with oom_score_adj.
>>
>> This also allows the correct oom_score_adj to always be shown when
>> reading /proc/pid/oom_score.
>>
>> Signed-off-by: David Rientjes <rientjes@xxxxxxxxxx>
>
> I didn't like the previous playing with the oom_score_adj and what you
> propose looks much nicer.
> Maybe s/oom_task_origin/task_oom_origin/ would be a better fit
May be s/oom_task_origin/is_task_origin_oom? Just my 2 cents.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/