aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorge Matthies <openglfreak@googlemail.com>2023-09-01 17:51:31 +0200
committerTorge Matthies <openglfreak@googlemail.com>2023-09-01 17:51:31 +0200
commite0e3032926d77ad424f5127ed8a5b4e44b6be476 (patch)
tree377091c63a50baa26d13f0913f6248ee1d6b5810
parent63c8f14756921c1d1d6a99082a679b92aef288c1 (diff)
downloadbcachefs-tools-e0e3032926d77ad424f5127ed8a5b4e44b6be476.tar.gz
Fix one second delay when exiting
Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
-rw-r--r--linux/shrinker.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/linux/shrinker.c b/linux/shrinker.c
index 0b5715b3..dfefad40 100644
--- a/linux/shrinker.c
+++ b/linux/shrinker.c
@@ -131,7 +131,21 @@ void run_shrinkers(gfp_t gfp_mask, bool allocation_failed)
static int shrinker_thread(void *arg)
{
while (!kthread_should_stop()) {
- sleep(1);
+ struct timespec to;
+ int v;
+
+ clock_gettime(CLOCK_MONOTONIC, &to);
+ to.tv_sec += 1;
+ __set_current_state(TASK_INTERRUPTIBLE);
+ errno = 0;
+ while ((v = READ_ONCE(current->state)) != TASK_RUNNING &&
+ errno != ETIMEDOUT)
+ futex(&current->state, FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG,
+ v, &to, NULL, (uint32_t)~0);
+ if (kthread_should_stop())
+ break;
+ if (v != TASK_RUNNING)
+ __set_current_state(TASK_RUNNING);
run_shrinkers(GFP_KERNEL, false);
}