The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [RESEND] Add sched_set_batch() and run bcachefs-rebalance under SCHED_BATCH
@ 2025-01-14 12:47 Florian Schmaus
  2025-01-14 12:47 ` [PATCH 1/2] sched: provide sched_set_batch() Florian Schmaus
  2025-01-14 12:47 ` [PATCH 2/2] bcachefs: set rebalance thread to SCHED_BATCH and nice 19 Florian Schmaus
  0 siblings, 2 replies; 16+ messages in thread
From: Florian Schmaus @ 2025-01-14 12:47 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, Kent Overstreet
  Cc: linux-bcachefs, linux-kernel

Resending the patchset which first adds the sched_set_batch(),
akin to the existing sched_set_normal() and sched_set_fifo_low()
functions. In the second patch, we use sched_set_batch() to run
bcachefs' rebalance thread under SCHED_BATCH.

I am resending the patchset [1,2], since the two patches of the set
where not send to the same recipients. This probably caused some
confusion.

1: https://lore.kernel.org/lkml/20241114210649.71377-1-flo@geekplace.eu/
2: https://lore.kernel.org/lkml/20241114210649.71377-2-flo@geekplace.eu/


^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH 1/2] sched: Provide sched_set_batch()
@ 2024-11-14 21:06 Florian Schmaus
  2024-11-14 21:06 ` [PATCH 2/2] bcachefs: Set rebalance thread to SCHED_BATCH and nice 19 Florian Schmaus
  0 siblings, 1 reply; 16+ messages in thread
From: Florian Schmaus @ 2024-11-14 21:06 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: Florian Schmaus, linux-kernel

This function allows kernel threads created by modules to run under
SCHED_BATCH. Its usage may be a good option if the kernel thread is
not sensitive to scheduling latency; for example bcachefs' rebalancing
thread.

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 bb343136ddd0..100e6923fe39 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1862,6 +1862,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 24f9f90b6574..d272c0e0c508 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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-01-14 16:45 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-14 12:47 [RESEND] Add sched_set_batch() and run bcachefs-rebalance under SCHED_BATCH Florian Schmaus
2025-01-14 12:47 ` [PATCH 1/2] sched: provide sched_set_batch() Florian Schmaus
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
2024-11-14 21:06 ` [PATCH 2/2] bcachefs: Set rebalance thread to SCHED_BATCH and nice 19 Florian Schmaus
2024-11-15  5:43   ` Kent Overstreet
2024-11-15  8:26     ` Florian Schmaus
2024-11-15 20:42       ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox