Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
add infrastructure for read-only file system level caches
Browse files Browse the repository at this point in the history
Add a macro to mark code sections that only read from the file system,
along with a config option and documentation.

This facilitates implementation of relatively simple file system level
caches without the need to synchronize with the file system.

Enable read-only sections for 'git status' and preload_index.

Signed-off-by: Karsten Blees <blees@dcon.de>
  • Loading branch information
kblees committed Aug 16, 2014
1 parent 7f5b617 commit 119a8f8
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Documentation/config.txt
Expand Up @@ -631,6 +631,12 @@ relatively high IO latencies. When enabled, Git will do the
index comparison to the filesystem data in parallel, allowing
overlapping IO's. Defaults to true.

core.fscache::
Enable additional caching of file system data for some operations.
+
Git for Windows uses this to bulk-read and cache lstat data of entire
directories (instead of doing lstat file by file).

core.createObject::
You can set this to 'link', in which case a hardlink followed by
a delete of the source are used to make sure that object creation
Expand Down
1 change: 1 addition & 0 deletions builtin/commit.c
Expand Up @@ -1368,6 +1368,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
PATHSPEC_PREFER_FULL,
prefix, argv);

enable_fscache(1);
read_cache_preload(&s.pathspec);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);

Expand Down
2 changes: 2 additions & 0 deletions cache.h
Expand Up @@ -648,6 +648,8 @@ enum hide_dotfiles_type {
};
extern enum hide_dotfiles_type hide_dotfiles;

extern int core_fscache;

enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
Expand Down
5 changes: 5 additions & 0 deletions config.c
Expand Up @@ -881,6 +881,11 @@ static int git_default_core_config(const char *var, const char *value)
return 0;
}

if (!strcmp(var, "core.fscache")) {
core_fscache = git_config_bool(var, value);
return 0;
}

/* Add other config variables here and to Documentation/config.txt. */
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions environment.c
Expand Up @@ -64,6 +64,7 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
struct startup_info *startup_info;
unsigned long pack_size_limit_cfg;
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
int core_fscache;

/*
* The character that begins a commented line in user-editable file
Expand Down
15 changes: 15 additions & 0 deletions git-compat-util.h
Expand Up @@ -794,4 +794,19 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
#define mark_as_git_dir(x) /* noop */
#endif

/*
* Enable/disable a read-only cache for file system data on platforms that
* support it.
*
* Implementing a live-cache is complicated and requires special platform
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
* to mark sections of git code that extensively read from the file system
* without modifying anything. Implementations can use this to cache e.g. stat
* data or even file content without the need to synchronize with the file
* system.
*/
#ifndef enable_fscache
#define enable_fscache(x) /* noop */
#endif

#endif
2 changes: 2 additions & 0 deletions preload-index.c
Expand Up @@ -84,6 +84,7 @@ static void preload_index(struct index_state *index,
offset = 0;
work = DIV_ROUND_UP(index->cache_nr, threads);
memset(&data, 0, sizeof(data));
enable_fscache(1);
for (i = 0; i < threads; i++) {
struct thread_data *p = data+i;
p->index = index;
Expand All @@ -100,6 +101,7 @@ static void preload_index(struct index_state *index,
if (pthread_join(p->pthread, NULL))
die("unable to join threaded lstat");
}
enable_fscache(0);
}
#endif

Expand Down

0 comments on commit 119a8f8

Please sign in to comment.