[Mesa-dev] [PATCH] util/disk_cache: pass predicate functions file stats directly (v2)

Grazvydas Ignotas notasas at gmail.com
Wed Mar 15 19:09:58 UTC 2017


On Wed, Mar 15, 2017 at 3:01 PM, Alan Swanson <reiver at improbability.net> wrote:
> Since switching to LRU eviction the only user of these predicate
> functions now resolves directory entry stats itself so pass them
> directly saving calling fstat and strlen twice (and the
> expensive strlen is skipped entirely if access time is newer).
>
> v2: Update for empty cache dir detection changes
> ---
>  src/util/disk_cache.c | 49 ++++++++++++++++++-------------------------------
>  1 file changed, 18 insertions(+), 31 deletions(-)
>
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index e015e56f5e..f986f40d93 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -481,8 +481,9 @@ make_cache_file_directory(struct disk_cache *cache, const cache_key key)
>   */
>  static char *
>  choose_lru_file_matching(const char *dir_path,
> -                         bool (*predicate)(const struct dirent *,
> -                                           const char *dir_path))
> +                         bool (*predicate)(const char *dir_path,
> +                                           const struct stat,

Should stat be a pointer, to avoid possible implicit copying of struct stat?

> +                                           const char *, const size_t))
>  {
>     DIR *dir;
>     struct dirent *entry;
> @@ -498,13 +499,15 @@ choose_lru_file_matching(const char *dir_path,
>        entry = readdir(dir);
>        if (entry == NULL)
>           break;
> -      if (!predicate(entry, dir_path))
> -         continue;
>
>        struct stat sb;
>        if (fstatat(dirfd(dir), entry->d_name, &sb, 0) == 0) {
>           if (!lru_atime || (sb.st_atime < lru_atime)) {
>              size_t len = strlen(entry->d_name) + 1;
> +
> +            if (!predicate(dir_path, sb, entry->d_name, len))
> +               continue;

Predicate functions expect string length (see the .tmp check) but you
pass length + 1.

GraÅžvydas


More information about the mesa-dev mailing list