From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 D784B3E2AD0 for ; Wed, 27 May 2026 08:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779871646; cv=none; b=Fl+YgVJOLa78r9GF9rtMpkl4mEXnz4WTVA/Qm/I49NgubyxYNym7m/zQ5wpskfXEOg31cGqqSvoMwfY1JXcSoC15Ez4X+BKGS7jpeTrvZ152mhkO9eZfpdZeIuYMN6yM/3zOWbox//nOAILrLZ7OKnFsWOsZCTu9faAdwobMp80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779871646; c=relaxed/simple; bh=+S4VYKZ9ptdmSKpoyw5zEZ0qC9zK3GWuSXvh/IZacBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ucfQ6AB/Hm5PdiiJCbQ8/4270TH/Z4IgcrBT8XJumCJNgbxfpJK5sJ3cUXEaC8WfXxCUzTyRlpvdN7w57XE53zm/M+AkpvwziqlltlvMoKeCvVuA3qc5csIQuqJ2pvzBi/XUlEAHE8/TT6hltR3kMQ9qus1xu12+fOtm2C7J6kU= 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=VRjMtZnp; arc=none smtp.client-ip=209.85.128.45 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="VRjMtZnp" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4904127c32cso32932935e9.2 for ; Wed, 27 May 2026 01:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779871643; x=1780476443; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=SvPbiO/kvHgyF1x18sRDfpJ1LTwDqRquW88o+S2pTM0=; b=VRjMtZnpCKOcXcOF9DTMgqBezQRg/M94etjreoP0KPFMjPt2kMWgqAUEKwNHTRLZk4 oY64omlnIYFtPHTVkffnvv7lQLndypfYNUl0HsubOgZ61xs4tkAK8SQRTa08Qi2m6nso yks9j0LgvYs/4UuQJBAnrQ2pkHiWYjBKnwQyn8JkgRCIslpcxkg2WrHBf2H93O3OD7rG mRF5ESWiVzPTC0mh8erPuu3+P1rLE9StT5ocRa6LIaJpUy5xAA5jfSDjqjWxAQZq8Ox3 RtHohIqiSiblGpByGNRwYkS2BP1veVP+MW5/xc3EVZJJAMzAIR9ElsG1kVeidqb4ZlZy Dq0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779871643; x=1780476443; h=in-reply-to: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=SvPbiO/kvHgyF1x18sRDfpJ1LTwDqRquW88o+S2pTM0=; b=tKme25Js2pKRo7uE36oXtJ5a82ktY5vrHL7DyOnKc6wFAsb8U8GHxSv0iOv/WtDbZw VSkoraCSdeUtfuAvtVDMr7jEAXDl3oryz8u/9QJtRpeNokAIlu9ATPxrNIoDu39fFT0I pMXjRKUn+5EUuzLtsOdSeaIHT7XJD34w1Lx0M0S2oAXz3m7SA7iDwvYv15d4fRCwEByt l5uorbjSL/0gte3UyyPX7u7nLuB+o5nbFw66XZ5qjp1HCD12wvRrX9HHBJWn8itWSXCv b2tKS1GNJr/rq+b2i2xz4TziaW3Ng+ngYhwltPN6Za55mUYd7aH/PDrAa3xLpSYNjjAY YUZg== X-Forwarded-Encrypted: i=1; AFNElJ+uQslIuePXfc4B5tmIIBTS3SmfuQ13lon1acWLef23LE0HOe6oUlDxs06W0OI+GmZXHfN6kXjfZ+EBb/pkLss=@vger.kernel.org X-Gm-Message-State: AOJu0YwOdHGVKg7QfqKRv1IUTKUyWzYph6xhfQyeqwuOrWMDXzaEs4+f w2ZMpBspvRwwpY/0hqgH7IiI6xoN7oDB3Gd2onMC3dPBK7fRGMooFvrWEFWJFAYwtqQ= X-Gm-Gg: Acq92OHwiGqZ+hixJyYZs6JoG7z1vCv2gyKolNWOWVHE2sMxxyH0pDRzB2AhwHdy87t fe0IiVD1bzo/j5J5i9OueFdzuPGVOJp8aUiiUVKG0pyF19KnQQCJg3op3NPIArLqx8dfWcEVV7n hI/cLJf52xUoe/2THocycRfnZ+bn8cmhWUF438Sk38RmMFs6T/3MaRP2T/DVeqcbUMkEC1p2CBg aTRDcT480+89N3cx/VogIcVNImmnmqJobT9EKK+tUfjbDoofKtZdRmFO917aNGqvMJ/1ir2KMEk i4gPaA2rEPQ8QrwOVsLHtl7fo/Fg2ZhuRlByXtf7v5/CfafTkw1edS1PLUA+4jY9ERCPC2Hgngx hYDa7FSDsH92P8J+T81dUZRPt04wbC3iwGmURNHMZ+kI2+xhK03PvM3kD03sk9VrdhQtvSegxA8 XABukkGZqJhZy2rOFz7pLqB7F/YyITjISgnakfq0tXiRpr X-Received: by 2002:a05:600c:a402:b0:48f:be94:d82c with SMTP id 5b1f17b1804b1-490426d1a91mr259475015e9.19.1779871643182; Wed, 27 May 2026 01:47:23 -0700 (PDT) Received: from localhost (109-81-80-71.rct.o2.cz. [109.81.80.71]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4908098f315sm12090405e9.16.2026.05.27.01.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 01:47:22 -0700 (PDT) Date: Wed, 27 May 2026 10:47:21 +0200 From: Michal Hocko To: Hui Zhu Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , JP Kobryn , Andrew Morton , Shuah Khan , davem@davemloft.net, Jakub Kicinski , Jesper Dangaard Brouer , Stanislav Fomichev , KP Singh , Tao Chen , Mykyta Yatsenko , Leon Hwang , Anton Protopopov , Amery Hung , Tobias Klauser , Eyal Birger , Rong Tao , Hao Luo , Peter Zijlstra , Miguel Ojeda , Nathan Chancellor , Kees Cook , Tejun Heo , Jeff Xu , mkoutny@suse.com, Jan Hendrik Farr , Christian Brauner , Randy Dunlap , Brian Gerst , Masahiro Yamada , Willem de Bruijn , Jason Xing , Paul Chaignon , Chen Ridong , Lance Yang , Jiayuan Chen , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, geliang@kernel.org, baohua@kernel.org, Hui Zhu Subject: Re: [RFC PATCH bpf-next v7 00/11] mm: BPF struct_ops for dynamic memory protection and async reclaim Message-ID: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue 26-05-26 10:20:00, Hui Zhu wrote: > From: Hui Zhu > > Overview: > This series introduces BPF struct_ops support for the memory controller, > enabling userspace BPF programs to implement custom, dynamic memory > management policies per cgroup. The feature allows BPF programs to hook > into the core reclaim and charge paths without requiring kernel > modifications, providing a flexible alternative to static knobs such as > memory.low and memory.min. > > The series enables two complementary use cases. > > Dynamic memory protection: static memory protection thresholds > (memory.low, memory.min) are poor fits for workloads whose actual memory > activity varies over time. A high-priority cgroup holding a large working > set but temporarily idle will still suppress reclaim on its siblings, > wasting available memory. A BPF-driven approach can observe real workload > activity -- page faults, charge/uncharge events -- and activate or > withdraw protection dynamically. Why the same cannot be achieved by dynamically changing protection? > The test results at the end of this > letter quantify the difference: in a scenario where the high-priority > cgroup is idle, the BPF-controlled low-priority cgroup achieves roughly > 37x higher throughput than with static memory.low. > > Asynchronous proactive reclaim: the memcg_charged and memcg_uncharged > hooks, combined with the BPF workqueue mechanism and the new > bpf_try_to_free_mem_cgroup_pages() kfunc, enable BPF programs to perform > proactive background reclaim without blocking the charge path. The > pattern works as follows: the memcg_charged callback tracks accumulated > memory usage; when usage crosses a configurable threshold, it enqueues an > asynchronous work item via bpf_wq_start() and returns immediately without > throttling the charging task. The workqueue callback then invokes > bpf_try_to_free_mem_cgroup_pages() to reclaim pages from the target > cgroup; if usage remains elevated after reclaim, the callback re-enqueues > itself to continue. This allows a BPF program to keep a cgroup's > footprint below its hard limit (memory.max) entirely in the background, > avoiding the OOM killer or direct-reclaim stalls that would otherwise > occur. How do you account the overall work done to the specific memcg as the large part of the reclaim is done from WQ context? Also when introducing a BPF hook please focus on describing why existing interfaces fail to achieve what you need. For the async reclaim why it is not practical or feasible to use userspace driven memory reclaim. -- Michal Hocko SUSE Labs