From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DCCC246BB4 for ; Wed, 8 Oct 2025 02:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759889761; cv=none; b=p8uYn9/lNHF5Z31iFMZtHYdtEQaYgC+hnQlUpeak+G8KJalKS+WqT3QeyNgldxxEfoIoMZrWDExSul55e5cYlRMY9pwVNH1Laq/RVt/1/GYE6GWEmMk8ywHqVV4tOguPhLXjhnU2jq2oFKRJ6/3xH93cqOK7WDaeJG82GCL6dn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759889761; c=relaxed/simple; bh=vIg33BOFvu2DJKTJckDWopI10BTYzh0CRGfWO2QY7n0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=hdAiTys8HNwQTj/I62zn4XEG0Q5Hiaeu8RRyyUtc22zoWEds/5iVrwz8D/Wq8tXyBs0Kt27cnYpcRq0XNF8KP9CLVOGWG9Ts00Xc7FjBOTJKwLpazlPWM7dfETB/DUcSZtCTpUQgY+6CTKou9NAPuPhuh3LeAnMwH0hBj0Pfr7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LNObAgyX; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LNObAgyX" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1759889746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vIg33BOFvu2DJKTJckDWopI10BTYzh0CRGfWO2QY7n0=; b=LNObAgyXn7QpbbMMaXccMVDeUIbaqghyVb6uU4GzlJVkCU97y3ZDswl/JuAogn3IQOXnLX hX0kezR1H8s/664IJ/6vqK1EU6TH4K5Sogf2p48mnjJCsdnIluI91xgIH7kLl23hNZVr8A 4TSArLy+pby/78AvJ5HuB9Zh2kqTpDg= From: Roman Gushchin To: Song Liu Cc: Andrii Nakryiko , Martin KaFai Lau , Alexei Starovoitov , Kumar Kartikeya Dwivedi , linux-mm , bpf , Suren Baghdasaryan , Johannes Weiner , Michal Hocko , David Rientjes , Matt Bobrowski , Alexei Starovoitov , Andrew Morton , LKML Subject: Re: [PATCH v1 01/14] mm: introduce bpf struct ops for OOM handling In-Reply-To: (Song Liu's message of "Tue, 7 Oct 2025 18:07:03 -0700") References: <20250818170136.209169-1-roman.gushchin@linux.dev> <20250818170136.209169-2-roman.gushchin@linux.dev> <87ms7tldwo.fsf@linux.dev> <1f2711b1-d809-4063-804b-7b2a3c8d933e@linux.dev> <87wm6rwd4d.fsf@linux.dev> <87iki0n4lm.fsf@linux.dev> <877bxb77eh.fsf@linux.dev> <871pnfk2px.fsf@linux.dev> <87tt0bfsq7.fsf@linux.dev> Date: Tue, 07 Oct 2025 19:15:40 -0700 Message-ID: <87playf8ab.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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Song Liu writes: > On Mon, Oct 6, 2025 at 5:42=E2=80=AFPM Roman Gushchin wrote: > [...] >> >> > >> >> > So, there cannot be bpf_link__attach_cgroup(), but there can be (at >> >> > least conceptually) bpf_map__attach_cgroup(), where map is struct_o= ps >> >> > map. >> >> >> >> I see... >> >> So basically when a struct ops map is created we have a fd and then >> >> we can attach it (theoretically multiple times) using BPF_LINK_CREATE. >> > >> > Yes, exactly. "theoretically" part is true right now because of how >> > things are wired up internally, but this must be fixable >> >> Ok, one more question: do you think it's better to alter the existing >> bpf_struct_ops.reg() callback and add the bpf_attr parameter >> or add the new .attach() callback? > > IIUC, bpf_struct_ops_link is just for bpf_struct_ops.reg(). The > attach() operation can be separate, and it doesn't need to be > implemented in sys_bpf() syscall. BPF TCP congestion control > uses setsockopt() to do the attach(). Current sched_ext does > the attach as part of reg(). Tejun is proposing to use reg() for > sub scheduler [1]. In my earlier patch set for fanotify-bpf, I > was planning to use ioctl on the fanotify fd [2]. I think these > all work for the given use case. > > I am not sure what is the best option for cgroup oom killer. There > are multiple options. Technically, it can even be a sysfs entry. > We can use it as: > > # load and pin oom killers first > $ cat /sys/fs/cgroup/user.slice/oom.killer > [oom_a] oom_b oom_c > $ echo oom_b > /sys/fs/cgroup/user.slice/oom.killer > $ cat /sys/fs/cgroup/user.slice/oom.killer > oom_a [oom_b] oom_c It actually looks nice! But I expect that most users of bpf_oom won't use it directly, but through some sort of middleware (e.g. systemd), so Idk if such a user-oriented interface makes a lot of sense. > Note that, I am not proposing to use sysfs entries for oom killer. > I just want to say it is an option. > > Given attach() can be implemented in different ways, we probably > don't need to add it to bpf_struct_ops. But if that turns out to be > the best option, I would not argue against it. OTOH, I think it is > better to keep reg() and attach() separate, though sched_ext is > using reg() for both options. I'm inclining towards a similar approach, except that I don't want to embed cgroup_id into the struct_ops, but keep it in the link, as Martin suggested. But I need to implement it end-to-end before I can be sure that it's the best option. Working on it... > > Does this make sense? Yes, thank you for the great summary!