journald: whenever we rotate a file, btrfs defrag it
Our write pattern is quite awful for CoW file systems (btrfs...), as we keep updating file parts in the beginning of the file. This results in fragmented journal files. Hence: when rotating files, defragment them, since at that point we know that no further write accesses will be made.
This commit is contained in:
@@ -531,3 +531,22 @@ finish:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btrfs_defrag_fd(int fd) {
|
||||
assert(fd >= 0);
|
||||
|
||||
if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btrfs_defrag(const char *p) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
return btrfs_defrag_fd(fd);
|
||||
}
|
||||
|
||||
@@ -57,3 +57,6 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *quota);
|
||||
int btrfs_reflink(int infd, int outfd);
|
||||
|
||||
int btrfs_get_block_device(const char *path, dev_t *dev);
|
||||
|
||||
int btrfs_defrag_fd(int fd);
|
||||
int btrfs_defrag(const char *p);
|
||||
|
||||
Reference in New Issue
Block a user