aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-04 18:58:31 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-04 18:58:31 -0700
commit7db27f11d043a6261aaa1bad1935f70ca5563782 (patch)
treeeec604c39bb617a210a7130038487b7c7a8b0c35
parent3ebb4feb986c3b3aacf33d441645314b587ef5b3 (diff)
downloadbun-7db27f11d043a6261aaa1bad1935f70ca5563782.tar.gz
bun-7db27f11d043a6261aaa1bad1935f70ca5563782.tar.zst
bun-7db27f11d043a6261aaa1bad1935f70ca5563782.zip
memfd_create does not actually make it faster
-rw-r--r--src/c.zig2
-rw-r--r--src/fs.zig37
2 files changed, 8 insertions, 31 deletions
diff --git a/src/c.zig b/src/c.zig
index ad7631709..1c288a0ef 100644
--- a/src/c.zig
+++ b/src/c.zig
@@ -136,7 +136,7 @@ pub fn moveFileZSlowWithHandle(in_handle: std.os.fd_t, to_dir: std.os.fd_t, dest
const out_handle = try std.os.openatZ(to_dir, destination, std.os.O_WRONLY | std.os.O_CREAT | std.os.O_CLOEXEC, 022);
defer std.os.close(out_handle);
if (comptime Enviroment.isLinux) {
- std.os.system.fallocate(out_handle, 0, 0, @intCast(i64, stat.size));
+ _ = std.os.system.fallocate(out_handle, 0, 0, @intCast(i64, stat.size));
_ = try std.os.sendfile(out_handle, in_handle, 0, @intCast(usize, stat.size), &[_]std.c.iovec_const{}, &[_]std.c.iovec_const{}, 0);
} else {
if (comptime Enviroment.isMac) {
diff --git a/src/fs.zig b/src/fs.zig
index 434f4ce36..68fdc6436 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -533,41 +533,18 @@ pub const FileSystem = struct {
if (this.fd != 0) std.os.close(this.fd);
}
- pub fn create(this: *Tmpfile, rfs: *RealFS, name: [*:0]const u8) !void {
- if (comptime Environment.isLinux) {
- this.fd = try std.os.memfd_createZ(name, std.os.MFD_CLOEXEC);
- return;
- }
+ const O_TMPFILE = 020000000;
- var tmpdir_ = try rfs.openTmpDir();
+ pub fn create(this: *Tmpfile, rfs: *RealFS, name: [*:0]const u8) !void {
+ var tmpdir_ = if (Environment.isLinux) try rfs.openDir(rfs.parent_fs.top_level_dir) else try rfs.openTmpDir();
+
+ const default_flags = std.os.O_CREAT | std.os.O_EXCL | std.os.O_RDWR | std.os.O_CLOEXEC;
+ const flags = if (Environment.isLinux) default_flags | O_TMPFILE else default_flags;
this.dir_fd = tmpdir_.fd;
- this.fd = try std.os.openatZ(tmpdir_.fd, name, std.os.O_CREAT | std.os.O_EXCL | std.os.O_RDWR | std.os.O_CLOEXEC, 0666);
- }
-
- pub fn promoteLinux(this: *Tmpfile, destination_fd: std.os.fd_t, name: [*:0]const u8) !void {
- std.debug.assert(this.fd != 0);
-
- const out_handle = try std.os.openatZ(destination_fd, name, std.os.O_WRONLY | std.os.O_CREAT | std.os.O_CLOEXEC, 022);
- defer std.os.close(out_handle);
- const read = try std.os.sendfile(
- out_handle,
- this.fd,
- 0,
- 0,
- &[_]std.c.iovec_const{},
- &[_]std.c.iovec_const{},
- 0,
- );
- try std.os.ftruncate(out_handle, read);
- this.close();
+ this.fd = try std.os.openatZ(tmpdir_.fd, name, flags, 0666);
}
pub fn promote(this: *Tmpfile, from_name: [*:0]const u8, destination_fd: std.os.fd_t, name: [*:0]const u8) !void {
- if (comptime Environment.isLinux) {
- try @call(.{ .modifier = .always_inline }, promoteLinux, .{ this, destination_fd, name });
- return;
- }
-
std.debug.assert(this.fd != 0);
std.debug.assert(this.dir_fd != 0);