From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4869C54ED1 for ; Tue, 27 May 2025 08:41:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76DB76B0096; Tue, 27 May 2025 04:41:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 745A76B0098; Tue, 27 May 2025 04:41:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65BB86B0099; Tue, 27 May 2025 04:41:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4C9CA6B0096 for ; Tue, 27 May 2025 04:41:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E3BB3160349 for ; Tue, 27 May 2025 08:41:34 +0000 (UTC) X-FDA: 83488044108.02.8B7183A Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf14.hostedemail.com (Postfix) with ESMTP id E7BBB100007 for ; Tue, 27 May 2025 08:41:32 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="TMj8/3HQ"; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1748335292; h=from:from:sender: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:dkim-signature; bh=p7koMvbwJk44nT5CGAwVYivi7QHUEWn5brvCgXni+H0=; b=7FEord6u0h/Fy/GyrMwg/Q9mZGz770nt4E7WCbDZ7phGA5AV1SOFKKTb/ziJlzhUL9Gnny OYWW1cPWOFkEb0SWf6csYFlHqDVxUKPt4H/aAgJ1YdY+2BHrq8/JFyyfSLI2GledqLezk8 Jwn9A3hotKlUIPvVAODGjBOyA8+tUtU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="TMj8/3HQ"; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1748335292; a=rsa-sha256; cv=none; b=z+vhyFwBrWPSZ61XYlQi0V14aSVsjTDfkdGy75bazqcIexSmwpJMRWd8u7wZ3uycFMxt0y +QFGJ6IyThCLnOQRl7WZIU7YMNhXTwMq+uG0GlyA6QqfJpW+wDIBKCFi0MrV8jipumFm9x q3uLu42mSEa7HpE8uJ0ph9LpzntUggU= Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6fa956f0f16so29509406d6.3 for ; Tue, 27 May 2025 01:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748335292; x=1748940092; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=p7koMvbwJk44nT5CGAwVYivi7QHUEWn5brvCgXni+H0=; b=TMj8/3HQiDVm6BJdoezRgZMv0A/Y5Trp9UhXON7DN4bnmi/f2WDXbTC8kx3KFb2BiW tkvodI66NgvsilRnrqvi8kxGMUWh9D6JTHAucKs/W0MgN9ROuY63mCRIo8mz4u7JdbPE UOVP1yicuGbWMyrI02P4uKU4T3+dS+B1RXq0cmQLKBhdb+xb8wxy9NtCrACUyEdRwjcA G1RBTxFD69rNkJTCNd/POy8I82QjaTXTrfs8BDDFhu+V+FDCBvvRq8AcBR3EmWFB9c54 bXJ3rElqg+s/YT33XsZ+5zrBtN7ClW13KDIgG9k3zPuEWXWvJAuxjK5NYJMc6dTEjHZV J1hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748335292; x=1748940092; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p7koMvbwJk44nT5CGAwVYivi7QHUEWn5brvCgXni+H0=; b=rj3HDysIfe14DQIaQ5+eR/pZx0F2z7hXL9Xayt2vetmjnRRLxyQlg04qkdcYrBqawh XW8gKb+iW6ciXqLIaZ6bWWJT95AymIkBlPdZXudVNHTqf7HsM9S8rKWYrBIcl3gNLFVa 5eXqs6CkgG7lEEOxtlmdxabywxMLgVcQgXJlaaDPVrwGnqePSQv+RXYA2XouOI5nDy/z 9UxjOw4AlVUI0bMvt7/SHgJ0ib6n16nqsyYhhY5jHjLajqWRHgxHmrL+ms8xmjILH4fh Ww5mSqPEgf0altEqx6CvWWn6cxroOtQ2DnS8Gaz98Pd1TlJW71KQCqhGaaf9SZO0FPZD YbYw== X-Forwarded-Encrypted: i=1; AJvYcCXBNKw7qjJje1RZaH/qIWXwQJzBJbqMJLqo7SXJC/lBWuUDvDF+56OB4Ibq0u7J5qLCK81xBc8kpg==@kvack.org X-Gm-Message-State: AOJu0Yzxo1ebrZcki36KaVVubNQ2w/SuHHUpro1oJPqQ/8ntsH6nkyMu sW8i0Yv7NCsbfMG8oywtxRQn46gCB6bKHpklwxpH+A9yy0XmAMw76U7m1XiLAvTFKVYqRwfSf4A JchozyOy6sonPZOn//H7YHq+3fPD54KQ= X-Gm-Gg: ASbGncuc/358xE9bd6mNIwcy9wWTT3Iv8xSF/doV2juzdLfyTmWhF4lqH1AWo7CdnFW vOspOd9RJw/KGdPG3ZsUo5laZn4/RVkvmolYa205hI94B6v44hvz89Dils1pxZpaAgBk0p1x6ai 8h5VK+wq0iY6BpbNppJvncu5Nix/EGpzDObA== X-Google-Smtp-Source: AGHT+IHuCrWzUG0fJT8OJIIsUPBPrsS4ysWMb6JECnMWI9zkMLwYmv1B/AxHyD8tyxk+USC7j0jzwg+WbHsrmMz0dSo= X-Received: by 2002:a05:6214:1d0d:b0:6f8:e2ab:cb8a with SMTP id 6a1803df08f44-6fa9cfff18fmr210571496d6.5.1748335292009; Tue, 27 May 2025 01:41:32 -0700 (PDT) MIME-Version: 1.0 References: <20250520060504.20251-1-laoar.shao@gmail.com> <7d8a9a5c-e0ef-4e36-9e1d-1ef8e853aed4@redhat.com> <5f0aadb1-28a8-4be0-bad9-16b738840e57@redhat.com> In-Reply-To: <5f0aadb1-28a8-4be0-bad9-16b738840e57@redhat.com> From: Yafang Shao Date: Tue, 27 May 2025 16:40:55 +0800 X-Gm-Features: AX0GCFvuLlCWLi1cQHi5Z4H4JSeykG8tUlPJcDn10xANbbMNlkhwr2Sz-BwyJ30 Message-ID: Subject: Re: [RFC PATCH v2 0/5] mm, bpf: BPF based THP adjustment To: David Hildenbrand Cc: akpm@linux-foundation.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, hannes@cmpxchg.org, usamaarif642@gmail.com, gutierrez.asier@huawei-partners.com, willy@infradead.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 1wmrp59eqs1w7bt1gb4psjyz18n1drkf X-Rspamd-Queue-Id: E7BBB100007 X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1748335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JvSAN/ly8x+2h+LZJqjvEl3+Fn1xZMgosXKzv2YKWtNB6xNjLb36ePWlloI9GGcfLsqSHcB2OxBhqxyJIjfHtjON3F2rq8WHJof9ZfiTz7qNxRzBZ3nys/UClyntLMWeS+BvxRXZ8Wt6jUsZbzcXzt+mSR0CKHzIt3jFpT6GXdoy/jPjggubvfwNvWUV51WIlChBM9fLnlRh4hh9ERvC6tGt6kwjG7je+4rGlcWaWEiwd4ERhGt2KPdi7JftcycgaZoUtJ50ntfnDk1Lra2EB1OC6q9aAdYpOTHAtAA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, May 27, 2025 at 4:30=E2=80=AFPM David Hildenbrand wrote: > > >> I don't think we want to add such a mechanism (new mode) where the > >> primary configuration mechanism is through bpf. > >> > >> Maybe bpf could be used as an alternative, but we should look into a > >> reasonable alternative first, like the discussed mctrl()/.../ raised i= n > >> the process_madvise() series. > >> > >> No "bpf" mode in disguise, please :) > > > > This goal can be readily achieved using a BPF program. In any case, it > > is a feasible solution. > > No BPF-only solution. > > > > >> > >>> We could define > >>> the API as follows: > >>> > >>> struct bpf_thp_ops { > >>> /** > >>> * @task_thp_mode: Get the THP mode for a specific task > >>> * > >>> * Return: > >>> * - TASK_THP_ALWAYS: "always" mode > >>> * - TASK_THP_MADVISE: "madvise" mode > >>> * - TASK_THP_NEVER: "never" mode > >>> * Future modes can also be added. > >>> */ > >>> int (*task_thp_mode)(struct task_struct *p); > >>> }; > >>> > >>> For observability, we could add a "THP mode" field to > >>> /proc/[pid]/status. For example: > >>> > >>> $ grep "THP mode" /proc/123/status > >>> always > >>> $ grep "THP mode" /proc/456/status > >>> madvise > >>> $ grep "THP mode" /proc/789/status > >>> never > >>> > >>> The THP mode for each task would be determined by the attached BPF > >>> program based on the task's attributes. We would place the BPF hook i= n > >>> appropriate kernel functions. Note that this setting wouldn't be > >>> inherited during fork/exec - the BPF program would make the decision > >>> dynamically for each task. > >> > >> What would be the mode (default) when the bpf program would not be act= ive? > >> > >>> This approach also enables runtime adjustments to THP modes based on > >>> system-wide conditions, such as memory fragmentation or other > >>> performance overheads. The BPF program could adapt policies > >>> dynamically, optimizing THP behavior in response to changing > >>> workloads. > >> > >> I am not sure that is the proper way to handle these scenarios: I neve= r > >> heard that people would be adjusting the system-wide policy dynamicall= y > >> in that way either. > >> > >> Whatever we do, we have to make sure that what we add won't > >> over-complicate things in the future. Having tooling dynamically adjus= t > >> the THP policy of processes that coarsely sounds ... very wrong long-t= erm. > > > > This is just an example demonstrating how BPF can be used to adjust > > its flexibility. Notably, all these policies can be implemented > > without modifying the kernel. > > See below on "policy". > > > > >> > >> > > As Liam pointed out in another thread, naming is challenging her= e - > >>> "process" might not be the most accurate term for this context. > >> > >> No, it's not even a per-process thing. It is per MM, and a MM might be > >> used by multiple processes ... > > > > I consistently use 'thread' for the latter case. > > You can use CLONE_VM without CLONE_THREAD ... If I understand correctly, this can only occur for shared THP but not anonymous THP. For instance, if either process allocates an anonymous THP, it would trigger the creation of a new MM. Please correct me if I'm mistaken. > > Additionally, this > > can be implemented per-MM without kernel code modifications. > > With a well-designed API, users can even implement custom THP > > policies=E2=80=94all without altering kernel code. > > You can switch between modes, that' all you can do. I wouldn't really > call that "custom policy" as it is extremely limited. > > And that's exactly my point: it's basic switching between modes ... a > reasonable policy in the future will make placement decisions and not > just state "always/never/madvise". Could you please elaborate further on 'make placement decisions'? As previously mentioned, we (including the broader community) really need the user input to determine whether THP allocation is appropriate in a given case. --=20 Regards Yafang