kovidgoyal/kitty · warning
Failed to allocate space for new disk cache file during defr
Error message
Failed to allocate space for new disk cache file during defrag
What it means
During disk-cache defrag, ftruncate() on the newly opened cache file failed, so kitty could not pre-allocate space for the compacted entries. Almost always ENOSPC — the filesystem holding the cache cannot fit total_data_size bytes. Defrag aborts cleanly; data remains in the old file.
Source
Thrown at kitty/disk-cache.c:246
defrag_entries = calloc(num_entries, sizeof(DefragEntry));
if (!defrag_entries) goto cleanup;
size_t total_data_size = 0, num_entries_to_defrag = 0;
cache_map_for_loop(i) {
CacheValue *s = i.data->val;
if (s->pos_in_cache_file > -1 && s->data_sz) {
total_data_size += s->data_sz;
DefragEntry *e = defrag_entries + num_entries_to_defrag++;
e->old_offset = s->pos_in_cache_file;
e->data_sz = s->data_sz;
e->key = keydup(i.data->key); // have to dup the key as we release the mutex and another thread might free the underlying key.
if (!e->key.hash_key) {
fprintf(stderr, "Failed to allocate space for keydup in defrag\n");
goto cleanup;
}
}
}
if (ftruncate(new_cache_file, total_data_size) != 0) {
perror("Failed to allocate space for new disk cache file during defrag");
goto cleanup;
}
lseek(new_cache_file, 0, SEEK_SET);
mutex(unlock);
lock_released = true;
off_t current_pos = 0;
for (size_t i = 0; i < num_entries_to_defrag; i++) {
DefragEntry *e = defrag_entries + i;
if (!copy_between_files(self->cache_file_fd, new_cache_file, e->old_offset, e->data_sz, &fcb)) {
perror("Failed to copy data to new disk cache file during defrag");
goto cleanup;
}
e->new_offset = current_pos;
current_pos += e->data_sz;
}
ok = true;View on GitHub (pinned to 6d5d0c4406)
Solutions
- Free space on the filesystem containing the cache dir or move XDG_CACHE_HOME to a larger volume.
- Clear the old cache: quit kitty and delete the kitty disk-cache directory.
- Reduce scrollback size in kitty.conf to shrink total_data_size.
- Avoid putting the cache on FUSE/NFS mounts; keep it on a local fs.
Defensive patterns
Strategy: validation
Validate before calling
df -h "${XDG_CACHE_HOME:-$HOME/.cache}" # confirm free bytes > expected scrollback cache size Prevention
- Trim scrollback_pager_history / scrollback limits on small disks.
- Clear stale cache after crashes.
When it happens
Trigger: defrag() runs (triggered from find_cache_entry_to_write once fragmentation thresholds are met) and the sum of live entry sizes exceeds free space on the cache filesystem, or the fs doesn't support ftruncate (some FUSE/network mounts return EPERM/EINVAL).
Common situations: Large scrollback caches on a small tmpfs; cache dir on a full home partition; cache on a network filesystem (NFS) with locking/truncate quirks.
Related errors
- Failed to open second file for defrag of disk cache
- Failed to write to disk-cache file
- Failed to copy data to new disk cache file during defrag
- Failed to seek in disk cache file
- This must be run as kitten ask
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/6cd883cfe3496400.
Report an issue: GitHub.