Skip to contentSkip to conversation

libuuid: Move clock.txt to /run

PATCH In review Michal Suchanek 4 participants 8 messages Mar 1, 2023 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libuuid: Move clock.txt to /run

Some users complain that due to filesystem performance of writing the clock.txt generating UUIDs is slow.

uuidd would solve this but some distributions do not run it by default.

Moving the clock.txt to /run which is in tmpfs should resolve the problem even for users not running uuidd.

---
 libuuid/src/uuidP.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libuuid/src/uuidP.h +1 -1
index 200702c1e..574a30fca 100644
@@ -39,7 +39,7 @@
 
 #include "uuid.h"
 
-#define LIBUUID_CLOCK_FILE	"/var/lib/libuuid/clock.txt"
+#define LIBUUID_CLOCK_FILE	"/run/libuuid/clock.txt"
 
 /*
  * Offset between 15-Oct-1582 and 1-Jan-70
Signature · 1 line
2.39.2
#1 lore raw
Quoted 2 lines · Michal Suchanek

Moving the clock.txt to /run which is in tmpfs should resolve the problem even for users not running uuidd.

[..]

libuuid/src/uuidP.h line 42

Quoted 3 lines
libuuid/src/uuidP.h +1 -1
-#define LIBUUID_CLOCK_FILE	"/var/lib/libuuid/clock.txt"
+#define LIBUUID_CLOCK_FILE	"/run/libuuid/clock.txt"

Last time I asked about this file on this mailing list, I was informed that clock.txt is supposed to survive reboots. Moving it to /run (or any other tmpfs) would break this.

Chris

#2 lore raw
Quoted 11 lines · Chris Hofstaedtler
Quoted 2 lines · Michal Suchanek

Moving the clock.txt to /run which is in tmpfs should resolve the problem even for users not running uuidd.

[..]

libuuid/src/uuidP.h line 42

Quoted 3 lines
libuuid/src/uuidP.h +1 -1
-#define LIBUUID_CLOCK_FILE	"/var/lib/libuuid/clock.txt"
+#define LIBUUID_CLOCK_FILE	"/run/libuuid/clock.txt"

Last time I asked about this file on this mailing list, I was informed that clock.txt is supposed to survive reboots. Moving it to /run (or any other tmpfs) would break this.

What's so valuable in it that it needs to survive?

I don't have it at all.

Also the code seems to re-synchronize with the real time clock from time to time which makes the content relevant only for limited periods of time.

Thanks

Michal

#3 lore raw
Quoted 11 lines · Michal Suchánek
Quoted 3 lines

Last time I asked about this file on this mailing list, I was informed that clock.txt is supposed to survive reboots. Moving it to /run (or any other tmpfs) would break this.

What's so valuable in it that it needs to survive?

I don't have it at all.

Also the code seems to re-synchronize with the real time clock from time to time which makes the content relevant only for limited periods of time.

The concern is if the system time goes backwards, this could result in a duplicative UUID being returned. This was especially a concern for systems that were dual-booting with Windows, where Windows set the real-time clock to localtime, and Linux set the real-time clock to GMT, and so the real time clock on those systems had a tendency to bound around a *lot*.

Using a random number generator for clock can help, but it's only 13 bits, so it's certainly not fool-proof. Given that using a time-based UUID leaks the MAC address of your ethernet port as well as when the UUID was generated (which can be interesting when you're curious say, when a Libreoffice doc was created), in general best practice is to use the random UUID type, especially given that modern Linux systems all have the getrandom(2) system call. That gives you 58 bits of entropy in the UUID, so that's probably the better way to go.

Cheers,

- Ted

#4 lore raw
Quoted 20 lines · Theodore Ts'o
Quoted 11 lines · Michal Suchánek
Quoted 3 lines

Last time I asked about this file on this mailing list, I was informed that clock.txt is supposed to survive reboots. Moving it to /run (or any other tmpfs) would break this.

What's so valuable in it that it needs to survive?

I don't have it at all.

Also the code seems to re-synchronize with the real time clock from time to time which makes the content relevant only for limited periods of time.

The concern is if the system time goes backwards, this could result in a duplicative UUID being returned. This was especially a concern for systems that were dual-booting with Windows, where Windows set the real-time clock to localtime, and Linux set the real-time clock to GMT, and so the real time clock on those systems had a tendency to bound around a *lot*.

Quoted 8 lines

Using a random number generator for clock can help, but it's only 13 bits, so it's certainly not fool-proof. Given that using a time-based UUID leaks the MAC address of your ethernet port as well as when the UUID was generated (which can be interesting when you're curious say, when a Libreoffice doc was created), in general best practice is to use the random UUID type, especially given that modern Linux systems all have the getrandom(2) system call. That gives you 58 bits of entropy in the UUID, so that's probably the better way to go.

That explains why I don't have a clock.txt file. I did not go out of my way to generate time-based uuids.

Thanks

Michal

#5 lore raw
Quoted 11 lines · Michal Suchánek
Quoted 8 lines

Using a random number generator for clock can help, but it's only 13 bits, so it's certainly not fool-proof. Given that using a time-based UUID leaks the MAC address of your ethernet port as well as when the UUID was generated (which can be interesting when you're curious say, when a Libreoffice doc was created), in general best practice is to use the random UUID type, especially given that modern Linux systems all have the getrandom(2) system call. That gives you 58 bits of entropy in the UUID, so that's probably the better way to go.

That explains why I don't have a clock.txt file. I did not go out of my way to generate time-based uuids.

Note that the only reason why you might be trying to generate a huge number of time-based UUID is if you are running a database (cough, SAP, cough) that is doing database index compression hacks so they can use still (a) use UUID's, but (b) not pay the cost of 16-byte UUID for every single object in their database.

But if they are doing this, you ***really*** want to be using uuidd, because even using clock.txt in tmpfs, it's going to be *way* faster to use uuidd, and since some workloads (cough, SAP, cough) are creating a vast number of UUID's per second while initializing their database, your distribution users *will* want to install uuidd if they are using those kinds of Enterprise Resource Planning systems. If you consider how much per hour these users pay for their certified
implementation consultsants, it's worth real $$$. :-)

- Ted

#6 lore raw
Quoted 10 lines · Theodore Ts'o
Quoted 9 lines · Michal Suchánek
Quoted 8 lines

Using a random number generator for clock can help, but it's only 13 bits, so it's certainly not fool-proof. Given that using a time-based UUID leaks the MAC address of your ethernet port as well as when the UUID was generated (which can be interesting when you're curious say, when a Libreoffice doc was created), in general best practice is to use the random UUID type, especially given that modern Linux systems all have the getrandom(2) system call. That gives you 58 bits of entropy in the UUID, so that's probably the better way to go.

Quoted 5 lines
Quoted 2 lines

That explains why I don't have a clock.txt file. I did not go out of my way to generate time-based uuids.

Note that the only reason why you might be trying to generate a huge number of time-based UUID is if you are running a database (cough,

Thanks for the very detailed explanation.

I suppose the default is fine for most users then, and makes it reasonably safe to use time basedd uuids for users of systems like Raspberry Pi which exhibit weird time jumps, likely due to lack of RTC battery.

uuidd is provided for people who want to generate large quantities of UUIDs.

When somebody *really* wants and it improves their use case they can mount tmpfs on /var/lib/libuuid/

Might be nice to write down in the uuid_generate man page if this is coming up repeatedly.

Thanks

Michal

maintainer
#7 lore raw
In reply to Michal Suchanek
Quoted 2 lines · Michal Suchanek

Some users complain that due to filesystem performance of writing the clock.txt generating UUIDs is slow.

XFS right? ;-)

Quoted 1 line

uuidd would solve this but some distributions do not run it by default.

For some performance critical use-cases you will see this issue with uuidd too. The latest changes in the libuuid and uuidd solves this problem by continuous-clock where uuidd uses dedicated clock sequence range to avoid often state-file updates.

Numbers from Michael (author of the patch)

The classic setup delivered <430.000 uuid/sec on average. The cont-clock setup delivered >6.800.000 uuid/sec on average.

I hope we will have -rc1 with this change this week.

Note that generate large number of time-based UUIDs without uuidd does not make sense.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com