]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: improve cache handling
authord032747 <michael.trapp@sap.com>
Fri, 22 Apr 2022 08:07:46 +0000 (10:07 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 29 Apr 2022 11:10:14 +0000 (13:10 +0200)
Short running applications with a few UUID request don't need
a large cache. Therefore increment the cache size over runtime.

libuuid/src/gen_uuid.c

index 76d5371ea72421ee46cafc5e30cb3644ecb87fdb..805b40d9016e64f3e4bdfdcfb064e0f4615fe430 100644 (file)
@@ -443,6 +443,7 @@ int __uuid_generate_time(uuid_t out, int *num)
 static int uuid_generate_time_generic(uuid_t out) {
 #ifdef HAVE_TLS
        THREAD_LOCAL int                num = 0;
+       THREAD_LOCAL int                cache_size = 1;
        THREAD_LOCAL struct uuid        uu;
        THREAD_LOCAL time_t             last_time = 0;
        time_t                          now;
@@ -453,7 +454,15 @@ static int uuid_generate_time_generic(uuid_t out) {
                        num = 0;
        }
        if (num <= 0) {
-               num = 1000000;
+               /*
+                * num + OP_BULK provides a local cache in each application.
+                * Start with a small cache size to cover short running applications
+                * and increment the cache size over the runntime.
+                */
+               if (cache_size < 1000000)
+                       cache_size *= 10;
+               num = cache_size;
+
                if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
                                        out, &num) == 0) {
                        last_time = time(NULL);