From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9B1235950 for ; Tue, 3 Feb 2026 13:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770125017; cv=none; b=fDbMBX+0ZlTSXE9F9Uy3PuE+s7Z5VfusWecixIWG0l+E3RvY+LQZgvP6BddLqKGkx5Uyqv56jQdcvoIwvlJK2N3yJ74Mdie3s9TywGUO9iO0zOmkSb20GArJBJLOIo+8AJRqiLtev2w6obULR5Yeo2B5NtS2n5JQQzMk0/jGxY8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770125017; c=relaxed/simple; bh=m3yePJc5GJA6IQZfzwxGBSJ6VJU+aPmQFSVFUxjLip4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fwvirB4ocFqqyaVUbBS2jKG+WDos36Zm+Jj1eYB8S1p232dNqjG8c80D7QlBbzOB+dYOJGb8oO4KHOn2cpL9hXnMfQMq1htO3nO1FPuIML/pR4i80XihG1iJUFkcaetSYBXVhbWt0Xto6/+awMcd0+frSjS47PMqd5PvgcnRGTs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RHU9TQnT; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RHU9TQnT" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4806e0f6b69so41286425e9.3 for ; Tue, 03 Feb 2026 05:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1770125014; x=1770729814; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=X9jKCMLhYnPbhGwJQdPwGF6Ru9Db2nKOSg989VKRbuc=; b=RHU9TQnT3v/UP+udLXke8my/D7cl6GQgGutNManoVPenN0hBXukToYoGzQ/6u+N9KP zzW1/8MyoCTa4jJmR5L/s6eiJvNP4h10Bvzi9PYOAzbnY/SaAGgpH6+dEJbsifhMx7Vu QT7ho0ZSnHvvhoTM7ev8JOerrD/wHog5Acm4nN1ZzxZyM1rwJrVHhG31VzmcS74XM+/l ni1eM5LvUybOoDglmaTffus0JX/giSuFc4caXwKTK2XBrAbzmTyZpbtFnPEaFqDfwKYq suPuE2KMw1JTDYXM6IcnRjNPFhrjt0FahVncFU9oLDVswInGXW5/27j6t1XAKiamstL8 d0Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770125014; x=1770729814; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X9jKCMLhYnPbhGwJQdPwGF6Ru9Db2nKOSg989VKRbuc=; b=CtJPH2ypTnALQc2e4r6i+4vPNzuZSS3LGtpCWnCw82SlUTJWkXQFRN65VYnZYRLo/i kFQ6vnlD6FDHvdljVCs+IZMfLzbtCQXqinpsLgWs/73p7swg+b0QomEm+3vWNCqor6Ld QJCkcvSC+7PEtnbjVNhqGQQxB3ecHDCPklfyF1Y98QW86gE3Y4N6Y2Bk5uOJPLBFMwVv fftmH4hL7qSw51vS1dtckTDZwDNRGmIskH6gT6yd9WfoNFlpVpncg6p8kK7d3UUObE8k gwz8q9j+M45te/AUtURK8vN/b5UKbQWwcsuyb/KiS4I3VF25+rrcP3aG0XjpKgK3SnxE hS/Q== X-Forwarded-Encrypted: i=1; AJvYcCWeUPSwzTtHEoV/61qPyBma+UBvz0sfXQsvsfGc9x+wDvlcdrcwgOausy+ygkJk7oWXC0DRhmxyjfch5EE=@vger.kernel.org X-Gm-Message-State: AOJu0YyMy+BBbAPEOkx6AIa5UaAYif+St6/7hDGqHz7a+BqosBCa5RBA j/LYUWLwveQLbM2tIU47jU/vZApttzaYtJy6/9P/7fR72cfbCzmam78DFR/0tUdcv0k= X-Gm-Gg: AZuq6aIKO6XGuHXGsLdj+O4nqZMbiTKRTuj7L64xkSayY1fzAywZSL6TBmwpKZDMnBB 93EuH41otu/SJFEHwzzQm55pTqWc+RG7Pt1oYulEtYyywvpYa44XcaZZFIk6XdqiwvaWl2ahMVV G+28L/GyR4xvuUxibOUwR176ormTlPVIkx6SNaecRk9+r1J4eBhBXPMUq0aNEmH2hHq3KL0TxOE +MC2N9ek6XwozM4GLpQDWlQnw2dq32mrel3gK1owBsn6kU6K1/kvGkk7pISyiwK7sOMLO4bxOAZ ORpP5n8R9txPDGIayAb6qt6tVHxXn9dSm5CFkGb4UhCKgXVqdGRthREJPdcjb/6Nvges8qx9zsy rZnoCuYb1xLinoZH81/OQQjy2IqeGaKrQcfU/b0BHSZdiHVN9HeFMyjYLHQgi70yHgqQ3mEx1WA AEbHWrAb83HyjjYbnJ/37Cc8aN X-Received: by 2002:a05:600c:a087:b0:479:35e7:a0e3 with SMTP id 5b1f17b1804b1-482db48f2ccmr215249685e9.30.1770125014093; Tue, 03 Feb 2026 05:23:34 -0800 (PST) Received: from localhost (109-81-26-156.rct.o2.cz. [109.81.26.156]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482da903a30sm149018775e9.1.2026.02.03.05.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 05:23:33 -0800 (PST) Date: Tue, 3 Feb 2026 14:23:32 +0100 From: Michal Hocko To: Roman Gushchin Cc: Alexei Starovoitov , Matt Bobrowski , bpf , Alexei Starovoitov , Shakeel Butt , JP Kobryn , LKML , linux-mm , Suren Baghdasaryan , Johannes Weiner , Andrew Morton Subject: Re: [PATCH bpf-next v3 10/17] mm: introduce bpf_task_is_oom_victim() kfunc Message-ID: References: <20260127024421.494929-1-roman.gushchin@linux.dev> <20260127024421.494929-11-roman.gushchin@linux.dev> <87jywuwumq.fsf@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87jywuwumq.fsf@linux.dev> On Mon 02-02-26 16:14:37, Roman Gushchin wrote: > Alexei Starovoitov writes: > > > On Sun, Feb 1, 2026 at 9:39 PM Matt Bobrowski wrote: > >> > >> On Mon, Jan 26, 2026 at 06:44:13PM -0800, Roman Gushchin wrote: > >> > Export tsk_is_oom_victim() helper as a BPF kfunc. > >> > It's very useful to avoid redundant oom kills. > >> > > >> > Signed-off-by: Roman Gushchin > >> > Suggested-by: Michal Hocko > >> > --- > >> > mm/oom_kill.c | 14 ++++++++++++++ > >> > 1 file changed, 14 insertions(+) > >> > > >> > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > >> > index 8f63a370b8f5..53f9f9674658 100644 > >> > --- a/mm/oom_kill.c > >> > +++ b/mm/oom_kill.c > >> > @@ -1381,10 +1381,24 @@ __bpf_kfunc int bpf_out_of_memory(struct mem_cgroup *memcg__nullable, > >> > return ret; > >> > } > >> > > >> > +/** > >> > + * bpf_task_is_oom_victim - Check if the task has been marked as an OOM victim > >> > + * @task: task to check > >> > + * > >> > + * Returns true if the task has been previously selected by the OOM killer > >> > + * to be killed. It's expected that the task will be destroyed soon and some > >> > + * memory will be freed, so maybe no additional actions required. > >> > + */ > >> > +__bpf_kfunc bool bpf_task_is_oom_victim(struct task_struct *task) > >> > +{ > >> > + return tsk_is_oom_victim(task); > >> > +} > >> > >> Why not just do a direct memory read (i.e., task->signal->oom_mm) > >> within the BPF program? I'm not quite convinced that a BPF kfunc > >> wrapper for something like tsk_is_oom_victim() is warranted as you can > >> literally achieve the same semantics without one. > > > > +1 > > there is no need for this kfunc. > > It was explicitly asked by Michal Hocko, who is (co)maintaining the oom > code. I don't have a strong opinion here. I agree that it can be easily > open-coded without a kfunc, but at the same time the cost of having an > extra kfunc is not high and it makes the API more consistent. > > Michal, do you feel strongly about having a dedicated kfunc vs the > direct memory read? The reason I wanted this an explicit API is that oom states are quite internal part of the oom synchronization. And I would really like to have that completely transparent for oom policies. In other words I do not want to touch all potential oom policies or break them in the worst case just because we need to change this. So while a trivial interface now (and hopefully for a long time) it is really an internal thing. Do I insist? No, I do not but I would like to hear why this is a bad idea. -- Michal Hocko SUSE Labs