Skip to content

Commit

Permalink
Merge pull request #44 from nicktehrany/fix_segmap_file_stats
Browse files Browse the repository at this point in the history
Fix the file stats for segmap stats, was missing files
  • Loading branch information
nicktehrany authored Nov 14, 2022
2 parents 8b5f6f5 + 741d968 commit dacfa07
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 19 deletions.
4 changes: 2 additions & 2 deletions include/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct f2fs_checkpoint {

static_assert(sizeof(struct f2fs_checkpoint) == 192, "");

enum {
enum type {
CURSEG_HOT_DATA = 0, /* directory entry blocks */
CURSEG_WARM_DATA, /* data blocks */
CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
Expand Down Expand Up @@ -309,7 +309,7 @@ static_assert(sizeof(struct f2fs_node) == 4096, "");

struct segment_info {
unsigned int id;
unsigned int type;
enum type type;
uint32_t valid_blocks;
/* uint8_t bitmap[]; */ /* TODO: we can get this info from segment_bits */
};
Expand Down
17 changes: 15 additions & 2 deletions include/zns-tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct extent {
uint64_t logical_blk; /* LBA starting address of the extent */
uint64_t phy_blk; /* PBA starting address of the extent */
uint64_t zone_lbas; /* LBAS of the zone the extent is in */
uint64_t zone_cap; /* Zone capacity */
uint64_t len; /* Length of the extent in 512B sectors */
uint64_t zone_size; /* Size of the zone the extent is in */
uint64_t zone_wp; /* Write Pointer of this current zone */
Expand All @@ -123,7 +124,17 @@ struct extent_map {
struct file_counter {
char file[MAX_FILE_LENGTH]; /* file name, fix maximum file length to avoid
messy reallocs */
uint32_t ctr; /* extent counter for the file */
uint32_t ext_ctr; /* extent counter for the file */
uint32_t segment_ctr; /* number of segments the file contained in */
uint32_t zone_ctr; /* number of zones the file is contained in */
uint32_t cold_ctr; /* number of the segments that are CURSEG_COLD_DATA */
uint32_t warm_ctr; /* number of the segments that are CURSEG_WARM_DATA*/
uint32_t hot_ctr; /* number of the segments that are CURSEG_HOT_DATA */
uint64_t last_segment_id; /* track the last segment id so we don't increase
counters for extents in the same segment for a
file */
uint32_t last_zone; /* track the last zone number so we don't increase
counters for extents in the same zone */
};

struct file_counter_map {
Expand All @@ -149,7 +160,9 @@ extern int contains_element(uint32_t[], uint32_t, uint32_t);
extern void sort_extents(struct extent_map *);
extern void show_extent_flags(uint32_t);
extern uint32_t get_file_counter(char *);
extern void set_file_counters(struct extent_map *);
extern void set_file_extent_counters(struct extent_map *);
extern void increase_file_segment_counter(char *, unsigned int, unsigned int,
enum type, uint64_t);
extern void set_super_block_info(struct f2fs_super_block);
extern void init_ctrl();

Expand Down
58 changes: 52 additions & 6 deletions lib/libzns-tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ static void get_zone_info(struct extent *extent) {

extent->zone_wp = hdr->zones[0].wp;
extent->zone_lbae = hdr->zones[0].start + hdr->zones[0].capacity;
extent->zone_cap = hdr->zones[0].capacity;
extent->zone_lbas = hdr->zones[0].start;

close(fd);
Expand Down Expand Up @@ -512,7 +513,7 @@ uint32_t get_file_counter(char *file) {
for (uint32_t i = 0; i < file_counter_map->cur_ctr; i++) {
if (strncmp(file_counter_map->file[i].file, file,
strlen(file_counter_map->file[i].file)) == 0) {
return file_counter_map->file[i].ctr;
return file_counter_map->file[i].ext_ctr;
}
}

Expand All @@ -525,18 +526,18 @@ uint32_t get_file_counter(char *file) {
* @file: char * to file name (full path)
*
* */
static void increase_file_counter(char *file) {
static void increase_file_extent_counter(char *file) {
for (uint32_t i = 0; i < file_counter_map->cur_ctr; i++) {
if (strncmp(file_counter_map->file[i].file, file,
strlen(file_counter_map->file[i].file)) == 0) {
file_counter_map->file[i].ctr++;
file_counter_map->file[i].ext_ctr++;
return;
}
}

memcpy(file_counter_map->file[file_counter_map->cur_ctr].file, file,
MAX_FILE_LENGTH);
file_counter_map->file[file_counter_map->cur_ctr].ctr = 1;
file_counter_map->file[file_counter_map->cur_ctr].ext_ctr = 1;
file_counter_map->cur_ctr++;
}

Expand All @@ -547,14 +548,59 @@ static void increase_file_counter(char *file) {
* @extent_map: extents to count file extents
*
* */
void set_file_counters(struct extent_map *extent_map) {
void set_file_extent_counters(struct extent_map *extent_map) {
file_counter_map =
(struct file_counter_map *)calloc(1, sizeof(struct file_counter_map));
file_counter_map->file = (struct file_counter *)calloc(
1, sizeof(struct file_counter) * ctrl.nr_files);

for (uint32_t i = 0; i < extent_map->ext_ctr; i++) {
increase_file_counter(extent_map->extent[i].file);
increase_file_extent_counter(extent_map->extent[i].file);
}
}

/*
* Increase the segment counts for a particular file
*
* @file: char * to file name (full path)
*
* */
void increase_file_segment_counter(char *file, unsigned int num_segments,
unsigned int cur_segment, enum type type,
uint64_t zone_cap) {
uint32_t i;

for (i = 0; i < file_counter_map->cur_ctr; i++) {
if (strncmp(file_counter_map->file[i].file, file,
strlen(file_counter_map->file[i].file)) == 0) {
goto found;
}
}

found:
if (file_counter_map->file[i].last_segment_id != cur_segment) {
file_counter_map->file[i].segment_ctr += num_segments;
file_counter_map->file[i].last_segment_id = cur_segment;

switch (type) {
case CURSEG_COLD_DATA:
file_counter_map->file[i].cold_ctr += num_segments;
break;
case CURSEG_WARM_DATA:
file_counter_map->file[i].warm_ctr += num_segments;
break;
case CURSEG_HOT_DATA:
file_counter_map->file[i].hot_ctr += num_segments;
break;
default:
break;
}
}

uint32_t zone = get_zone_number(cur_segment >> ctrl.segment_shift);
if (file_counter_map->file[i].last_zone != zone) {
file_counter_map->file[i].zone_ctr += (num_segments / zone_cap) + 1;
file_counter_map->file[i].last_segment_id = cur_segment;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fpbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ int main(int argc, char *argv[]) {
break;
case 's':
size = get_integer_value(optarg);
if (size > 4096) {
if (size >= 4096) {
wl_man.wl[0].fsize = size;
} else {
ERR_MSG("Minimum size of 4K required. Otherwise F2FS inlines "
Expand Down
34 changes: 26 additions & 8 deletions src/segmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void show_help() {
MSG("-s [uint]\tSet the starting zone to map. Default zone 1.\n");
MSG("-z [uint]\tOnly show this single zone\n");
MSG("-e [uint]\tSet the ending zone to map. Default last zone.\n");
MSG("-s\t\tShow segment statistics (requires -p to be enabled).\n");
MSG("-c\t\tShow segment statistics (requires -p to be enabled).\n");
MSG("-o\t\tShow only segment statistics (automatically enables -s).\n");

show_info();
Expand Down Expand Up @@ -433,13 +433,15 @@ static void show_segment_stats() {
if (segmap_man.isdir && ctrl.nr_files > 1) {
UNDERSCORE_FORMATTER
FORMATTER
for (uint32_t i = 0; i < segmap_man.ctr; i++) {
for (uint32_t i = 0; i < file_counter_map->cur_ctr; i++) {
MSG("%-50s | %-17u | %-28u | %-25u | %-13u | %-13u | %-13u\n",
segmap_man.fs[i].filename,
get_file_counter(segmap_man.fs[i].filename),
segmap_man.fs[i].segment_ctr, segmap_man.fs[i].zone_ctr,
segmap_man.fs[i].cold_ctr, segmap_man.fs[i].warm_ctr,
segmap_man.fs[i].hot_ctr);
file_counter_map->file[i].file,
file_counter_map->file[i].ext_ctr,
file_counter_map->file[i].segment_ctr,
file_counter_map->file[i].zone_ctr,
file_counter_map->file[i].cold_ctr,
file_counter_map->file[i].warm_ctr,
file_counter_map->file[i].hot_ctr);
}
}
}
Expand Down Expand Up @@ -492,6 +494,22 @@ static void show_segment_report() {
uint64_t extent_end =
glob_extent_map->extent[i].phy_blk + glob_extent_map->extent[i].len;

uint64_t segment_end = ((glob_extent_map->extent[i].phy_blk +
glob_extent_map->extent[i].len) &
ctrl.f2fs_segment_mask) >>
ctrl.segment_shift;

/* Can be zero if file starts and ends in same segment therefore + 1 for
* current segment */
uint64_t num_segments =
segment_end - (segment_start >> ctrl.segment_shift) + 1;

/* Extent can only be a single file so add all segments we have here */
increase_file_segment_counter(glob_extent_map->extent[i].file,
num_segments, segment_id,
segman.sm_info[segment_id].type,
glob_extent_map->extent[i].zone_cap);

// if the beginning of the extent and the ending of the extent are in
// the same segment
if (segment_start == (extent_end & ctrl.f2fs_segment_mask) ||
Expand Down Expand Up @@ -694,7 +712,7 @@ int main(int argc, char *argv[]) {
}
}

set_file_counters(glob_extent_map);
set_file_extent_counters(glob_extent_map);

show_segment_report();

Expand Down

0 comments on commit dacfa07

Please sign in to comment.