]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #29142 from poettering/pidref
authorLuca Boccassi <bluca@debian.org>
Sat, 9 Sep 2023 17:39:16 +0000 (18:39 +0100)
committerGitHub <noreply@github.com>
Sat, 9 Sep 2023 17:39:16 +0000 (18:39 +0100)
core: first step towards a pidfd focused future

12 files changed:
.github/workflows/mkosi.yml
man/org.freedesktop.systemd1.xml
mkosi.conf.d/10-extra-search-paths.conf [new file with mode: 0644]
mkosi.conf.d/10-fedora.conf
mkosi.conf.d/10-systemd.conf
mkosi.conf.d/10-tools.conf [new file with mode: 0644]
mkosi.presets/initrd/mkosi.conf
mkosi.presets/system/mkosi.conf
mkosi.presets/system/mkosi.conf.d/05-initrd.conf [new file with mode: 0644]
mkosi.presets/system/mkosi.kernel.build
src/core/cgroup.c
src/shared/bus-print-properties.c

index 7b9ad6a67f17bf96e4ab04a363de59920a239262..55bbad2bde2288567a25d46229ef66df154de0cd 100644 (file)
@@ -76,13 +76,10 @@ jobs:
 
     steps:
     - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
-    - uses: systemd/mkosi@cb5974d013f7c4c2a45f67c9ae990767e32e9034
+    - uses: systemd/mkosi@adaa41512aa30c952daae5ba0abcf2622d66b93b
 
     - name: Configure
       run: |
-        # We configure ExtraSearchPaths=build/ so make sure build/ exists.
-        mkdir build/
-
         tee mkosi.conf <<- EOF
         [Distribution]
         Distribution=${{ matrix.distro }}
index 75d3d457bd3036c29ed771f55b41b0d58af5968d..4ca0583d65522517d09c3ccaa61476dc988b407c 100644 (file)
@@ -4603,10 +4603,11 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
       <varname>ExtensionDirectories</varname>
       see systemd.exec(5) for their meaning.</para>
 
-      <para><varname>MemoryAvailable</varname> indicates how much unused memory is available to the unit before
-      the <literal>MemoryMax</literal> or <literal>MemoryHigh</literal> (whichever is lower) limit set by the cgroup
-      memory controller is reached. It will take into consideration limits on all parent slices, other than the
-      limits set on the unit itself.</para>
+      <para><varname>MemoryAvailable</varname> takes into account unit's and parents' <literal>MemoryMax</literal>
+      or <literal>MemoryHigh</literal> or physically available RAM versus given level's memory consumption
+      and takes minimum. Beware that other units below the tightest parent slice may consume the memory quicker
+      and less than reported value would remain for own allocation.
+      It works better in conjunction with <varname>MemoryAccounting=yes</varname> on involved units.</para>
 
       <para><varname>DelegateSubgroup</varname> contains the cgroup subgroup to place invoked unit processes
       in. As configured by the option of the same name in unit files. This is set to the empty string when it
diff --git a/mkosi.conf.d/10-extra-search-paths.conf b/mkosi.conf.d/10-extra-search-paths.conf
new file mode 100644 (file)
index 0000000..bd3cdb1
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+PathExists=build/
+
+[Host]
+ExtraSearchPaths=build/
index 0196c9f745c4d79e64a2f7c6d2abc3e3af0122a7..006cdeded8df1a7345df3106da54b3620300cf12 100644 (file)
@@ -4,4 +4,4 @@
 Distribution=fedora
 
 [Distribution]
-@Release=38
+@Release=39
index f25d53d2b76834f40f8bb25d333a29eb4922b664..b2921ffc6745fa221a00f17de6027c9897ad547d 100644 (file)
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Preset]
+Presets=system
+
 [Output]
 OutputDirectory=mkosi.output
 BuildDirectory=mkosi.builddir
@@ -14,7 +17,6 @@ Environment=ASAN_OPTIONS=verify_asan_link_order=false
 [Host]
 @Incremental=yes
 @QemuMem=2G
-ExtraSearchPaths=build/
 # Make sure we don't trigger systemd-firstboot prompting for the root password.
 Credentials=passwd.plaintext-password.root=
 KernelCommandLineExtra=systemd.crash_shell
diff --git a/mkosi.conf.d/10-tools.conf b/mkosi.conf.d/10-tools.conf
new file mode 100644 (file)
index 0000000..21bdea5
--- /dev/null
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+PathExists=!build/
+SystemdVersion=<254
+
+[Host]
+ToolsTree=default
index 5d347b71d81d7bc2656c55910ea1776098442dd4..0ef3a7bd4adc301aab0691b5399b5399523a04f8 100644 (file)
@@ -1,9 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
-[Match]
-Bootable=|auto
-Bootable=|yes
-
 [Preset]
 Dependencies=base
 
index 0cccf98fd868d0810c7372c261afb69373308ea7..361bb6af7245159bdb9eb06afd9b3aadb1f22279 100644 (file)
@@ -2,14 +2,12 @@
 
 [Preset]
 Dependencies=base
-             initrd
 
 [Content]
 Autologin=yes
 BaseTrees=../../mkosi.output/base
 ExtraTrees=../../mkosi.output/base-systemd
 ExtraTrees=../../src:/usr/src/src
-Initrds=../../mkosi.output/initrd
 Packages=
         acl
         bash-completion
diff --git a/mkosi.presets/system/mkosi.conf.d/05-initrd.conf b/mkosi.presets/system/mkosi.conf.d/05-initrd.conf
new file mode 100644 (file)
index 0000000..e5dedaf
--- /dev/null
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Bootable=!no
+Format=disk
+
+[Preset]
+Dependencies=initrd
+
+[Content]
+Initrds=../../mkosi.output/initrd
index 5938330d4b9ae833ca9dd2e937e6a699928390fe..a21585c4cab1bedc8cdbef844b1172d9dc9d508f 100755 (executable)
@@ -12,6 +12,11 @@ if [ -d "$SRCDIR"/mkosi.kernel/ ]; then
     cd "$SRCDIR"
     mkdir -p "$BUILDDIR"
 
+    # Prevent a distro's custom installkernel script from being used.
+    if [ -x /sbin/installkernel ]; then
+        mount --bind /dev/null /sbin/installkernel
+    fi
+
     # Ensure fast incremental builds by fixating these values which usually change for each build.
     export KBUILD_BUILD_TIMESTAMP="Fri Jun  5 15:58:00 CEST 2015"
     export KBUILD_BUILD_HOST="mkosi"
index 91ef33b12c922e4d426d4f30b3e0841563740cc2..b304b39e8c1e5c5ca395572302f70dceadd0e744 100644 (file)
@@ -3751,10 +3751,7 @@ int manager_notify_cgroup_empty(Manager *m, const char *cgroup) {
 }
 
 int unit_get_memory_available(Unit *u, uint64_t *ret) {
-        uint64_t unit_current, available = UINT64_MAX;
-        CGroupContext *unit_context;
-        const char *memory_file;
-        int r;
+        uint64_t available = UINT64_MAX, current = 0;
 
         assert(u);
         assert(ret);
@@ -3763,58 +3760,33 @@ int unit_get_memory_available(Unit *u, uint64_t *ret) {
          * claim before hitting the configured cgroup limits (if any). Consider both MemoryHigh
          * and MemoryMax, and also any slice the unit might be nested below. */
 
-        if (!UNIT_CGROUP_BOOL(u, memory_accounting))
-                return -ENODATA;
-
-        if (!u->cgroup_path)
-                return -ENODATA;
-
-        /* The root cgroup doesn't expose this information */
-        if (unit_has_host_root_cgroup(u))
-                return -ENODATA;
-
-        if ((u->cgroup_realized_mask & CGROUP_MASK_MEMORY) == 0)
-                return -ENODATA;
-
-        r = cg_all_unified();
-        if (r < 0)
-                return r;
-        memory_file = r > 0 ? "memory.current" : "memory.usage_in_bytes";
-
-        r = cg_get_attribute_as_uint64("memory", u->cgroup_path, memory_file, &unit_current);
-        if (r < 0)
-                return r;
-
-        assert_se(unit_context = unit_get_cgroup_context(u));
-
-        if (unit_context->memory_max != UINT64_MAX || unit_context->memory_high != UINT64_MAX)
-                available = LESS_BY(MIN(unit_context->memory_max, unit_context->memory_high), unit_current);
-
-        for (Unit *slice = UNIT_GET_SLICE(u); slice; slice = UNIT_GET_SLICE(slice)) {
-                uint64_t slice_current, slice_available = UINT64_MAX;
-                CGroupContext *slice_context;
+        do {
+                uint64_t unit_available, unit_limit = UINT64_MAX;
+                CGroupContext *unit_context;
 
                 /* No point in continuing if we can't go any lower */
                 if (available == 0)
                         break;
 
-                if (!slice->cgroup_path)
-                        continue;
+                unit_context = unit_get_cgroup_context(u);
+                if (!unit_context)
+                        return -ENODATA;
 
-                slice_context = unit_get_cgroup_context(slice);
-                if (!slice_context)
+                if (!u->cgroup_path)
                         continue;
 
-                if (slice_context->memory_max == UINT64_MAX && slice_context->memory_high == UINT64_MAX)
-                        continue;
+                (void) unit_get_memory_current(u, &current);
+                /* in case of error, previous current propagates as lower bound */
 
-                r = cg_get_attribute_as_uint64("memory", slice->cgroup_path, memory_file, &slice_current);
-                if (r < 0)
+                if (unit_has_name(u, SPECIAL_ROOT_SLICE))
+                        unit_limit = physical_memory();
+                else if (unit_context->memory_max == UINT64_MAX && unit_context->memory_high == UINT64_MAX)
                         continue;
+                unit_limit = MIN3(unit_limit, unit_context->memory_max, unit_context->memory_high);
 
-                slice_available = LESS_BY(MIN(slice_context->memory_max, slice_context->memory_high), slice_current);
-                available = MIN(slice_available, available);
-        }
+                unit_available = LESS_BY(unit_limit, current);
+                available = MIN(unit_available, available);
+        } while ((u = UNIT_GET_SLICE(u)));
 
         *ret = available;
 
index db41ad249579da84796f3ab616620fc2cf054128..8999a1a4fad5a512ccfee60078170326418935ca 100644 (file)
@@ -157,12 +157,12 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
                 else if ((STR_IN_SET(name, "CPUWeight", "StartupCPUWeight", "IOWeight", "StartupIOWeight") && u == CGROUP_WEIGHT_INVALID) ||
                            (STR_IN_SET(name, "CPUShares", "StartupCPUShares") && u == CGROUP_CPU_SHARES_INVALID) ||
                            (STR_IN_SET(name, "BlockIOWeight", "StartupBlockIOWeight") && u == CGROUP_BLKIO_WEIGHT_INVALID) ||
-                           (STR_IN_SET(name, "MemoryCurrent", "TasksCurrent") && u == UINT64_MAX) ||
+                           (STR_IN_SET(name, "MemoryCurrent", "MemoryAvailable", "TasksCurrent") && u == UINT64_MAX) ||
                            (endswith(name, "NSec") && u == UINT64_MAX))
 
                         bus_print_property_value(name, expected_value, flags, "[not set]");
 
-                else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryZSwapMax", "MemoryLimit", "MemoryAvailable") && u == CGROUP_LIMIT_MAX) ||
+                else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryZSwapMax", "MemoryLimit") && u == CGROUP_LIMIT_MAX) ||
                          (STR_IN_SET(name, "TasksMax", "DefaultTasksMax") && u == UINT64_MAX) ||
                          (startswith(name, "Limit") && u == UINT64_MAX) ||
                          (startswith(name, "DefaultLimit") && u == UINT64_MAX))