Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753543Ab2KLWOn (ORCPT ); Mon, 12 Nov 2012 17:14:43 -0500 Received: from mail-lb0-f174.google.com ([209.85.217.174]:62477 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752458Ab2KLWOm (ORCPT ); Mon, 12 Nov 2012 17:14:42 -0500 MIME-Version: 1.0 In-Reply-To: <20121108155112.GN31821@dhcp22.suse.cz> References: <20121108155112.GN31821@dhcp22.suse.cz> Date: Mon, 12 Nov 2012 20:14:40 -0200 Message-ID: Subject: Re: [patch 2/2] mm, oom: fix race when specifying a thread as the oom origin From: Thiago Farina To: Michal Hocko Cc: David Rientjes , Andrew Morton , KAMEZAWA Hiroyuki , KOSAKI Motohiro , Greg Kroah-Hartman , Anton Vorontsov , Oleg Nesterov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1825 Lines: 39 On Thu, Nov 8, 2012 at 1:51 PM, Michal Hocko 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 > > 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/