Use setfiles -A option if available to reduce memory usage

resolves: RHEL-114292
This commit is contained in:
Richard W.M. Jones 2025-09-18 08:54:13 +01:00
parent 7da86f4a86
commit e0ed2a1c0d
6 changed files with 154 additions and 8 deletions

View File

@ -0,0 +1,41 @@
From 30ccb9a3e6ce3f5abddde99e2c9c527738806609 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 11 Sep 2025 21:03:37 +0100
Subject: [PATCH] daemon/selinux.ml: Use setfiles -A option to reduce memory
usage
In filesystems that have many millions of files, the default behaviour
of setfiles is to build a huge hash table containing every filename.
This uses up lots of memory which prevents relabelling from happening
in the reduced memory environment of the libguestfs appliance.
I added the setfiles -A option to change this default behaviour. If
setfiles has the option then use it.
Fixes: https://issues.redhat.com/browse/RHEL-114292
Related: https://issues.redhat.com/browse/RHEL-111165
Related: https://issues.redhat.com/browse/RHEL-111505
---
daemon/selinux.ml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/daemon/selinux.ml b/daemon/selinux.ml
index 19da2c8a5..2b49e5eba 100644
--- a/daemon/selinux.ml
+++ b/daemon/selinux.ml
@@ -73,6 +73,12 @@ let setfiles ?(force = false) specfile paths =
*)
if setfiles_has_option 'C' then List.push_back args "-C";
+ (* Use the -A option if available to reduce the amount of memory
+ * used in filesystems with millions of files
+ * See: https://issues.redhat.com/browse/RHEL-111505
+ *)
+ if setfiles_has_option 'A' then List.push_back args "-A";
+
(* If the appliance is being run with multiple vCPUs, running setfiles
* in multithreading mode might speed up the process. Option "-T" was
* introduced in SELinux userspace v3.4, and we need to check whether it's
--
2.47.1

View File

@ -0,0 +1,101 @@
From 495f71affc7ade1842a8bc66f5f65862c444ca93 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 12 Sep 2025 08:37:58 +0100
Subject: [PATCH] daemon, generator: Use power of 2 for initial size of
Hashtbl.create
Before 2011 it was recommended to use a prime number for the initial
size. In 2011 the OCaml hash table was reimplemented using a hash
function based on Murmur 3. Hashtbl.create now adjusts the initial
size to the next power of 2 (minimum 16). So replace obsolete
'Hashtbl.create 13' with 'Hashtbl.create 16'.
---
daemon/selinux.ml | 2 +-
generator/memoized_cache.ml | 2 +-
generator/optgroups.ml | 2 +-
generator/pr.ml | 2 +-
generator/tests_c_api.ml | 2 +-
generator/utils.ml | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/daemon/selinux.ml b/daemon/selinux.ml
index 2b49e5eba..9802e8913 100644
--- a/daemon/selinux.ml
+++ b/daemon/selinux.ml
@@ -35,7 +35,7 @@ let setfiles_has_option =
let _, _, err = commandr "setfiles" [opt] in
String.find err err_msg = -1
in
- let h = Hashtbl.create 13 in
+ let h = Hashtbl.create 16 in
fun flag ->
try Hashtbl.find h flag
with
diff --git a/generator/memoized_cache.ml b/generator/memoized_cache.ml
index 46ba929a3..8ae224edc 100644
--- a/generator/memoized_cache.ml
+++ b/generator/memoized_cache.ml
@@ -44,7 +44,7 @@ let create ?(version = 1) ?(batch_size = 100) name lookup_fn =
let filename = sprintf "generator/.%s.data.version.%d" name version in
let memo =
try with_open_in filename input_value
- with _ -> Hashtbl.create 13 in
+ with _ -> Hashtbl.create 16 in
{
memo; filename; lookup_fn; batch_size; unsaved_count = 0;
}
diff --git a/generator/optgroups.ml b/generator/optgroups.ml
index 43c9fe75a..f65f0ccbd 100644
--- a/generator/optgroups.ml
+++ b/generator/optgroups.ml
@@ -34,7 +34,7 @@ let optgroups_retired = [
(* Create list of optional groups. *)
let optgroups =
- let h = Hashtbl.create 13 in
+ let h = Hashtbl.create 16 in
List.iter (
function
| { optional = Some group } as fn ->
diff --git a/generator/pr.ml b/generator/pr.ml
index af9da9f68..615c241d0 100644
--- a/generator/pr.ml
+++ b/generator/pr.ml
@@ -32,7 +32,7 @@ let lines = ref 0
(* Name of each file generated. *)
let files = ref []
-let fileshash = Hashtbl.create 13
+let fileshash = Hashtbl.create 16
(* Print-to-current-output function, used everywhere. It has
* printf-like semantics.
diff --git a/generator/tests_c_api.ml b/generator/tests_c_api.ml
index c9ef3b0c8..81f2cd6fe 100644
--- a/generator/tests_c_api.ml
+++ b/generator/tests_c_api.ml
@@ -64,7 +64,7 @@ let rec generate_c_api_tests () =
pr " size_t i;\n";
pr " const char *no_tests[] = {\n";
- let hash : (string, bool) Hashtbl.t = Hashtbl.create 13 in
+ let hash : (string, bool) Hashtbl.t = Hashtbl.create 16 in
List.iter (
fun { tests } ->
let seqs = List.filter_map (
diff --git a/generator/utils.ml b/generator/utils.ml
index 88d8899b5..44b7c7d42 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -109,7 +109,7 @@ let rstructs_used_by functions =
| RStructListOnly, RStructListOnly -> RStructListOnly
in
- let h = Hashtbl.create 13 in
+ let h = Hashtbl.create 16 in
(* if elem->oldv exists, update entry using ||| operator,
* else just add elem->newv to the hash
--
2.47.1

View File

@ -1,4 +1,4 @@
From 0f5add1d2d63c31c81f9bd190120ff860b6d9373 Mon Sep 17 00:00:00 2001
From adc7aeb5cc1aa90b9eb63b7c7d1c452155960146 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 29 Jul 2013 14:47:56 +0100
Subject: [PATCH] RHEL: Disable unsupported remote drive protocols

View File

@ -1,4 +1,4 @@
From 1eda452cb73b8dabf0695e10bac6e74a83c6a5fe Mon Sep 17 00:00:00 2001
From 0c27052b03be0536f6f7ccdecf14248925edadb0 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 7 Jul 2015 09:28:03 -0400
Subject: [PATCH] RHEL: Reject use of libguestfs-winsupport features except for

View File

@ -1,4 +1,4 @@
From db9c0259837bbd2c5e3bf003ff8d0cc7b9c50c9d Mon Sep 17 00:00:00 2001
From e78fadc8bf73b3824334cfb1ad5c922f5397cad7 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 13 May 2025 17:28:25 +0100
Subject: [PATCH] RHEL: appliance/init: Run depmod -a to rebuild kernel module

View File

@ -35,7 +35,7 @@ Summary: Access and modify virtual machine disk images
Name: libguestfs
Epoch: 1
Version: 1.57.3
Release: 1%{?dist}
Release: 2%{?dist}
License: LGPL-2.1-or-later
# Build only for architectures that have a kernel
@ -73,9 +73,11 @@ Source8: copy-patches.sh
# https://github.com/libguestfs/libguestfs/commits/rhel-10.2
# Patches.
Patch0001: 0001-RHEL-Disable-unsupported-remote-drive-protocols-RHBZ.patch
Patch0002: 0002-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0003: 0003-RHEL-appliance-init-Run-depmod-a-to-rebuild-kernel-m.patch
Patch0001: 0001-daemon-selinux.ml-Use-setfiles-A-option-to-reduce-me.patch
Patch0002: 0002-daemon-generator-Use-power-of-2-for-initial-size-of-.patch
Patch0003: 0003-RHEL-Disable-unsupported-remote-drive-protocols-RHBZ.patch
Patch0004: 0004-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0005: 0005-RHEL-appliance-init-Run-depmod-a-to-rebuild-kernel-m.patch
BuildRequires: autoconf, automake, libtool, gettext-devel
@ -1078,11 +1080,13 @@ rm ocaml/html/.gitignore
%changelog
* Tue Sep 09 2025 Richard W.M. Jones <rjones@redhat.com> - 1:1.57.3-1
* Tue Sep 09 2025 Richard W.M. Jones <rjones@redhat.com> - 1:1.57.3-2
- Rebase to libguestfs 1.57.3
resolves: RHEL-111240
- Add new libguestfs ntfs_chmod API
resolves: RHEL-113833
- Use setfiles -A option if available to reduce memory usage
resolves: RHEL-114292
* Thu Aug 14 2025 Richard W.M. Jones <rjones@redhat.com> - 1:1.56.1-3
- Rebase to libguestfs 1.56.1