]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
home: Use log2u64() over log2()
authorDaan De Meyer <daan@amutable.com>
Fri, 15 May 2026 11:06:21 +0000 (11:06 +0000)
committerDaan De Meyer <daan@amutable.com>
Mon, 18 May 2026 21:17:38 +0000 (21:17 +0000)
And drop the libm dependency.

src/home/homed-manager.c
src/home/meson.build

index fc6fe8a4b1c448179984b5d5b3fe9cf40523e288..0fcf7b9395e9195e41cfb1a704ca38dc090e1614 100644 (file)
@@ -3,7 +3,6 @@
 #include <grp.h>
 #include <linux/fscrypt.h>
 #include <linux/magic.h>
-#include <math.h>
 #include <pwd.h>
 #include <sys/inotify.h>
 #include <sys/ioctl.h>
@@ -41,6 +40,7 @@
 #include "homed-manager-bus.h"
 #include "homed-operation.h"
 #include "homed-varlink.h"
+#include "logarithm.h"
 #include "mkdir.h"
 #include "notify-recv.h"
 #include "ordered-set.h"
@@ -1937,9 +1937,9 @@ static int manager_rebalance_calculate(Manager *m) {
         }
 
         /* Scale next rebalancing interval based on the least amount of space of any of the home
-         * directories. We pick a time in the range 1min … 15min, scaled by log2(min_free), so that:
-         * 10M → ~0.7min, 100M → ~2.7min, 1G → ~4.6min, 10G → ~6.5min, 100G ~8.4 */
-        m->rebalance_interval_usec = (usec_t) CLAMP((LESS_BY(log2(min_free), 22)*15*USEC_PER_MINUTE)/26,
+         * directories. We pick a time in the range 1min … 15min, scaled by floor(log2(min_free)),
+         * so that: 10M → ~0.6min, 100M → ~2.3min, 1G → ~4.0min, 10G → ~6.3min, 100G → ~8.1min */
+        m->rebalance_interval_usec = (usec_t) CLAMP((LESS_BY(log2u64(min_free), 22u)*15*USEC_PER_MINUTE)/26,
                                                     1 * USEC_PER_MINUTE,
                                                     15 * USEC_PER_MINUTE);
 
index 0b27001c5a04bba0008a6958076f0e7362c4a957..64c62f1dddf2ab5dd91cf362ba50d46a79885e8b 100644 (file)
@@ -68,7 +68,6 @@ executables += [
                 'sources' : systemd_homed_sources,
                 'extract' : systemd_homed_extract_sources,
                 'dependencies' : [
-                        libm,
                         libopenssl_cflags,
                         threads,
                 ],