aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Silverman <bsilver16384@gmail.com>2016-02-15 16:15:24 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-02-16 09:40:02 +0000
commitbbe748063fa139949656fd7a8dec86ebdecddb6f (patch)
treefe24af16ac4037a52839d998187faebe8a964776
parent9d40a60efec40add9443edbd75b77cdccbbc43dc (diff)
Use hard links to create empty files.
This speeds up my test of running a bunch of genrules with 3000 inputs by 2x on XFS. It might speed up ext4 a bit, but it definitely doesn't make it slower. XFS and ext4 are about the same speed with this. Test at <https://gist.github.com/bsilver8192/10527a862ce16bb7f79a>;. Refs #852 RELNOTES: Improved sandbox performance on XFS filesystems. -- Change-Id: Ifabc0442f9f919d50cb5fe80a6445890c6d7f03e Reviewed-on: https://bazel-review.googlesource.com/#/c/2890/1 MOS_MIGRATED_REVID=114693725
-rw-r--r--src/main/tools/namespace-sandbox.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/tools/namespace-sandbox.c b/src/main/tools/namespace-sandbox.c
index 0153211b7b..b092cfec5d 100644
--- a/src/main/tools/namespace-sandbox.c
+++ b/src/main/tools/namespace-sandbox.c
@@ -400,6 +400,13 @@ static void CreateFile(const char *path) {
CHECK_CALL(close(handle));
}
+// Creates an empty file at 'path' by hard linking it from a known empty file.
+// This is over two times faster than creating empty files via open() on
+// certain filesystems (e.g. XFS).
+static void LinkFile(const char *path) {
+ CHECK_CALL(link("tmp/empty_file", path));
+}
+
static void SetupDevices() {
CHECK_CALL(mkdir("dev", 0755));
const char *devs[] = {"/dev/null", "/dev/random", "/dev/urandom", "/dev/zero",
@@ -448,7 +455,7 @@ static int CreateTarget(const char *path, bool is_directory) {
if (is_directory) {
CHECK_CALL(mkdir(path, 0755));
} else {
- CreateFile(path);
+ LinkFile(path);
}
return 0;
@@ -499,6 +506,9 @@ static void SetupDirectories(struct Options *opt) {
CHECK_CALL(CreateTarget(opt->create_dirs[i] + 1, true));
}
+ // This is used as the base for hardlinking the input files.
+ CreateFile("tmp/empty_file");
+
// Mount all mounts.
for (int i = 0; i < opt->num_mounts; i++) {
struct stat sb;