mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Schmaus <flo@geekplace.eu>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Florian Schmaus <flo@geekplace.eu>
Subject: [PATCH 1/2] sched: provide sched_set_batch()
Date: Tue, 14 Jan 2025 13:47:27 +0100	[thread overview]
Message-ID: <20250114130513.498482-3-flo@geekplace.eu> (raw)
In-Reply-To: <20250114130513.498482-2-flo@geekplace.eu>

This allows kernel threads created by modules to run under
SCHED_BATCH. Typically this may be a good option if the task of the
kernel thread is not sensitive to scheduling latency, for example
rebalancing or gc tasks.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
 include/linux/sched.h   |  1 +
 kernel/sched/syscalls.c | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 64934e0830af..80d46ed1dfa8 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1874,6 +1874,7 @@ extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sc
 extern void sched_set_fifo(struct task_struct *p);
 extern void sched_set_fifo_low(struct task_struct *p);
 extern void sched_set_normal(struct task_struct *p, int nice);
+extern void sched_set_batch(struct task_struct *p, int nice);
 extern int sched_setattr(struct task_struct *, const struct sched_attr *);
 extern int sched_setattr_nocheck(struct task_struct *, const struct sched_attr *);
 extern struct task_struct *idle_task(int cpu);
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index ff0e5ab4e37c..e0e0be4223df 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -880,6 +880,16 @@ void sched_set_normal(struct task_struct *p, int nice)
 }
 EXPORT_SYMBOL_GPL(sched_set_normal);
 
+void sched_set_batch(struct task_struct *p, int nice)
+{
+	struct sched_attr attr = {
+		.sched_policy = SCHED_BATCH,
+		.sched_nice = nice,
+	};
+	WARN_ON_ONCE(sched_setattr_nocheck(p, &attr) != 0);
+}
+EXPORT_SYMBOL_GPL(sched_set_batch);
+
 static int
 do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
 {
-- 
2.45.2


  reply	other threads:[~2025-01-14 13:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 12:47 [RESEND] Add sched_set_batch() and run bcachefs-rebalance under SCHED_BATCH Florian Schmaus
2025-01-14 12:47 ` Florian Schmaus [this message]
2025-01-14 12:47 ` [PATCH 2/2] bcachefs: set rebalance thread to SCHED_BATCH and nice 19 Florian Schmaus
2025-01-14 13:29   ` Christian Loehle
2025-01-14 14:40     ` Peter Zijlstra
2025-01-14 15:05       ` Christian Loehle
2025-01-14 15:32       ` Kent Overstreet
2025-01-14 15:19     ` Kent Overstreet
2025-01-14 16:45     ` Florian Schmaus
2025-01-14 14:32   ` Peter Zijlstra
2025-01-14 15:25     ` Kent Overstreet
2025-01-14 16:45       ` Florian Schmaus
  -- strict thread matches above, loose matches on Subject: below --
2024-11-14 21:06 [PATCH 1/2] sched: Provide sched_set_batch() Florian Schmaus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250114130513.498482-3-flo@geekplace.eu \
    --to=flo@geekplace.eu \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®