Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Pull: `tensorfold pull` no longer stops with "detecting network configuration failed" after 64 distinct resolved addresses on a long pull; a full address table replaces its oldest entry (#4621, follows #4140).

- Metal: a checkpoint file span of 16 GiB or more loads; each `pread` asks for at most 1 GiB, since macOS refuses a count above INT_MAX (#4435). Thanks to @sethforprivacy, and to @markyu0401 for the first fix (#4433).

- Tests: requests with `n` from 2 to 16 give back every `--max-inflight` and per-key place on each way they can end (done, disconnect, a failing choice, 429, 400, cancel, shutdown), plus a seeded concurrent disconnect case (#4602).

- Tests: the Nemotron HIP page-fault suite compiles again (its fixture builds ids through `hip_serve.pages`), and the Flash Next recipe says the scale index runs on every Mac since #4547 (#4605). Thanks to @AIFlowML.
Expand Down
15 changes: 10 additions & 5 deletions zig/src/cli/pull_route.zig
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,23 @@ pub fn tunnelOf(io: std.Io, address: *const std.Io.net.IpAddress) ?Tunnel {
const AddressDeadline = struct { address: std.Io.net.IpAddress = undefined, deadline: std.Io.Clock.Timestamp = .{ .raw = .zero, .clock = .awake } };
var addresses: [64]AddressDeadline = @splat(.{});
var address_count: usize = 0;
var address_next: usize = 0; // once full, the oldest entry is replaced (a pull over rotating CDN addresses never runs out)

/// Carries a name's original deadline to each address the resolver returned.
pub fn rememberAddress(io: std.Io, address: std.Io.net.IpAddress, deadline: std.Io.Clock.Timestamp) !void {
/// Carries a name's deadline to each resolved address; when full, the oldest goes (its connect gets a fresh deadline).
pub fn rememberAddress(io: std.Io, address: std.Io.net.IpAddress, deadline: std.Io.Clock.Timestamp) error{TooManyHosts}!void {
lock.lockUncancelable(io);
defer lock.unlock(io);
for (addresses[0..address_count]) |*a| if (a.address.eql(&address)) {
a.deadline = deadline;
return;
};
if (address_count == addresses.len) return error.TooManyHosts;
addresses[address_count] = .{ .address = address, .deadline = deadline };
address_count += 1;
if (address_count < addresses.len) {
addresses[address_count] = .{ .address = address, .deadline = deadline };
address_count += 1;
return;
}
addresses[address_next] = .{ .address = address, .deadline = deadline };
address_next = (address_next + 1) % addresses.len;
}

pub fn addressDeadline(io: std.Io, address: *const std.Io.net.IpAddress) ?std.Io.Clock.Timestamp {
Expand Down
12 changes: 12 additions & 0 deletions zig/src/cli/pull_route_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,15 @@ test "pull proxy: the timeouts read their own variables" {
try std.testing.expectEqual(@as(u32, 5), s.connect_s);
try std.testing.expectEqual(@as(u32, 7), s.stall_s);
}

test "pull route: more distinct addresses than the table holds never fails a pull; the newest keeps its deadline" {
const io = std.testing.io;
const deadline: std.Io.Clock.Timestamp = .{ .raw = .zero, .clock = .awake };
var i: usize = 0;
while (i < 200) : (i += 1) {
const address: std.Io.net.IpAddress = .{ .ip4 = .{ .bytes = .{ 10, 99, @intCast(i / 256), @intCast(i % 256) }, .port = 443 } };
try route.rememberAddress(io, address, deadline);
}
const newest: std.Io.net.IpAddress = .{ .ip4 = .{ .bytes = .{ 10, 99, 0, 199 }, .port = 443 } };
try std.testing.expect(route.addressDeadline(io, &newest) != null);
}
25 changes: 24 additions & 1 deletion zig/src/core/checkpoint_metal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,13 @@ pub const Stage = struct {
}
};

/// The most one pread asks for: macOS refuses a count above INT_MAX, so a longer span takes several calls.
const max_pread = 1 << 30;

fn readAll(fd: platform.c.fd_t, dest: []u8, at: usize) !void {
var done: usize = 0;
while (done < dest.len) {
const n = platform.c.pread(fd, dest.ptr + done, dest.len - done, @intCast(at + done));
const n = platform.c.pread(fd, dest.ptr + done, @min(dest.len - done, max_pread), @intCast(at + done));
if (n <= 0) return error.ShortRead;
done += @intCast(n);
}
Expand Down Expand Up @@ -437,6 +440,26 @@ test "a split checkpoint keeps later tensors in the file, packs the rest, and st
try std.testing.expectEqualSlices(u16, (try full.get("text.scales")).host(u16), (try split.get("text.scales")).host(u16));
}

test "a span longer than one pread may ask for is read whole" {
const len: usize = (1 << 31) + 4096;
const gpa = std.testing.allocator;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
const path = try std.fmt.allocPrintSentinel(gpa, ".zig-cache/tmp/{s}/sparse.bin", .{tmp.sub_path}, 0);
defer gpa.free(path);
const fd = platform.c.open(path, .{ .ACCMODE = .RDWR, .CREAT = true }, @as(platform.c.mode_t, 0o600));
if (fd < 0) return error.SkipZigTest;
defer _ = platform.c.close(fd);
const tail = "the last bytes";
if (platform.c.pwrite(fd, tail.ptr, tail.len, @intCast(len - tail.len)) != tail.len) return error.SkipZigTest;
const dest = std.posix.mmap(null, len, .{ .READ = true, .WRITE = true }, .{ .TYPE = .PRIVATE, .ANONYMOUS = true }, -1, 0) catch return error.SkipZigTest;
defer std.posix.munmap(dest);
try readAll(fd, dest, 0);
try std.testing.expectEqualStrings(tail, dest[len - tail.len ..]);
try std.testing.expectEqual(@as(u8, 0), dest[max_pread]);
try std.testing.expectError(error.ShortRead, readAll(fd, dest[0..2], len - 1));
}

test {
_ = file_cache;
}
Loading