git: a8a6eac57091 - main - linux: implement prctl PR_{G,S}ET_THP_DISABLE

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 11 Sep 2026 05:51:33 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a8a6eac570917825d947020775d8f1962b396fd7

commit a8a6eac570917825d947020775d8f1962b396fd7
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-09-11 05:42:34 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-09-11 05:42:34 +0000

    linux: implement prctl PR_{G,S}ET_THP_DISABLE
    
    Since we don't have THP in FreeBSD, return that it's disabled. Linux
    applications use this to get around the weird latency spikes THP in
    Linux creates. Since FreeBSD superpages don't suffer from this issue,
    just say it's disabled.
    
    This removes the noisiest noise from the linux claude running on
    FreeBSD.
    
    Sponsored by:           Netflix
---
 sys/compat/linux/linux_misc.c | 18 ++++++++++++++++++
 sys/compat/linux/linux_misc.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 96c0ab81beef..8487f53e1371 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1864,6 +1864,24 @@ linux_prctl(struct thread *td, struct linux_prctl_args *args)
 			error = EINVAL;
 		}
 		break;
+	case LINUX_PR_GET_THP_DISABLE:
+		/*
+		 * THP not in play, since FreeBSD doesn't have THP. Although
+		 * similar, superpages don't have the crazy issues THP does, so
+		 * tell the best lie possible: there's no problems with crazy
+		 * latency spikes: this feature is disabled.
+		 */
+
+		td->td_retval[0] = 1;
+		break;
+	case LINUX_PR_SET_THP_DISABLE:
+		/*
+		 * Accept anything that's valid.
+		 */
+		if (args->arg2 != 0 && args->arg2 != 1)
+			return (EINVAL);
+		td->td_retval[0] = 0;
+		break;
 	default:
 		linux_msg(td, "unsupported prctl option %d", args->option);
 		error = EINVAL;
diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h
index 196f9372d4bf..fb77784ddea8 100644
--- a/sys/compat/linux/linux_misc.h
+++ b/sys/compat/linux/linux_misc.h
@@ -61,6 +61,8 @@
 #define	LINUX_PR_GET_CHILD_SUBREAPER	37 /* Get child subreaper status */
 #define	LINUX_PR_SET_NO_NEW_PRIVS	38 /* Set no_new_privs attribute */
 #define	LINUX_PR_GET_NO_NEW_PRIVS	39 /* Get no_new_privs attribute */
+#define LINUX_PR_SET_THP_DISABLE	41 /* Disable / enable THP */
+#define LINUX_PR_GET_THP_DISABLE	42 /* Get THP state */
 #define	LINUX_PR_SET_PTRACER	1499557217
 #define	LINUX_PR_SET_VMA	1398164801
 #define	LINUX_PR_SET_VMA_ANON_NAME	0