Last active
May 9, 2023 01:05
-
-
Save sjc2870/c923d7fa627d10ab65d6c305afb02cdb to your computer and use it in GitHub Desktop.
used for testing the performance of replacing xattr in ext4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img=/dev/sdb1 | |
dir=/mnt/ext4 | |
file=$dir/file1 | |
mkdir -p $dir | |
umount $dir | |
mke2fs -Fq -t ext4 -I 256 -O ea_inode $img | |
mount $img $dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <attr/xattr.h> | |
#include <stdio.h> | |
#define DEFAULT_TIMES 1000000 | |
#define SIZE 4096 // assume block size is 4096 | |
int main (int argc, char **argv) | |
{ | |
const char* file = "/mnt/ext4/file1"; | |
const char* key = "user.test"; | |
char* value1 = malloc(SIZE); | |
char* value2 = malloc(SIZE); | |
int i = 0; | |
int times = DEFAULT_TIMES; | |
if (argc > 1) { | |
times = atoi(argv[1]); | |
} | |
memset(value1, 'a', SIZE); | |
memset(value2, 'b', SIZE); | |
for (int i = 0; i < times; ++i) { | |
if (lsetxattr(file, key, value1, SIZE, 0)) { | |
perror("lsetxattr"); | |
exit(EXIT_FAILURE); | |
} | |
if (lsetxattr(file, key, value2, SIZE, 0)) { | |
perror("lsetxattr"); | |
exit(EXIT_FAILURE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment