|
|
Log in / Subscribe / Register

Why glibc's fstat() is slow

Why glibc's fstat() is slow

Posted Sep 14, 2023 19:07 UTC (Thu) by brenns10 (subscriber, #112114)
In reply to: Why glibc's fstat() is slow by wsy
Parent article: Why glibc's fstat() is slow

It's wild how many places that pops up! I fixed that in procps-ng where it would do a stat(/etc/local time) multiple times *per process* because of the printf formats being used. I'm sure tons of software, especially multithreaded apps, are experiencing this and slowdowns associated with it.

https://gitlab.com/procps-ng/procps/-/merge_requests/119


to post comments

Why glibc's fstat() is slow

Posted Sep 14, 2023 21:56 UTC (Thu) by guillemj (subscriber, #49706) [Link]

There is https://sourceware.org/bugzilla/show_bug.cgi?id=24004 with a patch attached. You can use localtime_r(3) to avoid this problem. And at least for multithreaded code I'd expect it to be using that already, but otherwise other code might indeed suffer from this issue.

speed of repeated localtime() etc.

Posted Sep 16, 2023 0:30 UTC (Sat) by jreiser (subscriber, #11027) [Link]

Software which appends entries to a log file can call localtime (or its relatives) once per event, and there can be dozens or hundreds of events per second, for instance open(). In most cases the speed of logging can be improved by remembering the headway between the current gettimeofday() and the next future gettimeofday() when the relevant portion of localtime() can change. For an output format of HH:mm:ss, then the headway is limited to at most 1 second. For the local timezone, the minimum headway can be up to 30 minutes. If gettimeofday()still is within the headway, then there is no need to consult any any external authority.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds