[PATCH] FAT: optimize FSINFO writeback

From: steve
Date: Tue Jun 30 2009 - 16:08:20 EST


Only write the FSINFO block back to disk when its contents change.
This optimization can be important when the underlying physical media
can wear out, i.e. Flash.

Signed-off-by: Steven J. Magnani <steve@xxxxxxxxxxxxxxx>
---
diff -uprN a/fs/fat/misc.c b/fs/fat/misc.c
--- a/fs/fat/misc.c 2009-06-29 11:12:40.000000000 -0500
+++ b/fs/fat/misc.c 2009-06-29 11:46:45.000000000 -0500
@@ -61,11 +61,25 @@ void fat_clusters_flush(struct super_blo
le32_to_cpu(fsinfo->signature2),
sbi->fsinfo_sector);
} else {
- if (sbi->free_clusters != -1)
- fsinfo->free_clusters = cpu_to_le32(sbi->free_clusters);
- if (sbi->prev_free != -1)
- fsinfo->next_cluster = cpu_to_le32(sbi->prev_free);
- mark_buffer_dirty(bh);
+ char write_needed = 0;
+ __le32 le_value;
+
+ if (sbi->free_clusters != -1) {
+ le_value = cpu_to_le32(sbi->free_clusters);
+ if (fsinfo->free_clusters != le_value) {
+ fsinfo->free_clusters = le_value;
+ write_needed = 1;
+ }
+ }
+ if (sbi->prev_free != -1) {
+ le_value = cpu_to_le32(sbi->prev_free);
+ if (fsinfo->next_cluster != le_value) {
+ fsinfo->next_cluster = le_value;
+ write_needed = 1;
+ }
+ }
+ if (write_needed)
+ mark_buffer_dirty(bh);
}
brelse(bh);
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/