⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbd-stats-2.6-rhel5.patch

📁 非常经典的一个分布式系统
💻 PATCH
📖 第 1 页 / 共 2 页
字号:
+		return -EIO;+	}+	spin_lock(&journal->j_history_lock);+	memcpy(s->stats, &journal->j_stats, size);+	s->journal = journal;+	spin_unlock(&journal->j_history_lock);++	rc = seq_open(file, &jbd_seq_info_ops);+	if (rc == 0) {+		struct seq_file *m = (struct seq_file *)file->private_data;+		m->private = s;+	} else {+		kfree(s->stats);+		kfree(s);+	}+	return rc;++}++static int jbd_seq_info_release(struct inode *inode, struct file *file)+{+	struct seq_file *seq = (struct seq_file *)file->private_data;+	struct jbd_stats_proc_session *s = seq->private;+	kfree(s->stats);+	kfree(s);+	return seq_release(inode, file);+}++static struct file_operations jbd_seq_info_fops = {+	.owner		= THIS_MODULE,+	.open           = jbd_seq_info_open,+	.read           = seq_read,+	.llseek         = seq_lseek,+	.release        = jbd_seq_info_release,+};++static struct proc_dir_entry *proc_jbd_stats = NULL;++static void jbd_stats_proc_init(journal_t *journal)+{+	char name[64];++	snprintf(name, sizeof(name) - 1, "%s", bdevname(journal->j_dev, name));+	journal->j_proc_entry = proc_mkdir(name, proc_jbd_stats);+	if (journal->j_proc_entry) {+		struct proc_dir_entry *p;+		p = create_proc_entry("history", S_IRUGO,+				journal->j_proc_entry);+		if (p) {+			p->proc_fops = &jbd_seq_history_fops;+			p->data = journal;+			p = create_proc_entry("info", S_IRUGO,+						journal->j_proc_entry);+			if (p) {+				p->proc_fops = &jbd_seq_info_fops;+				p->data = journal;+			}+		}+	}+}++static void jbd_stats_proc_exit(journal_t *journal)+{+	char name[64];++	snprintf(name, sizeof(name) - 1, "%s", bdevname(journal->j_dev, name));+	remove_proc_entry("info", journal->j_proc_entry);+	remove_proc_entry("history", journal->j_proc_entry);+	remove_proc_entry(name, proc_jbd_stats);+}++static void journal_init_stats(journal_t *journal)+{+	int size;++	if (proc_jbd_stats == NULL)+		return;++	journal->j_history_max = 100;+	size = sizeof(struct transaction_stats_s) * journal->j_history_max;+	journal->j_history = kmalloc(size, GFP_KERNEL);+	if (journal->j_history == NULL) {+		journal->j_history_max = 0;+		return;+	}+	memset(journal->j_history, 0, size);+	spin_lock_init(&journal->j_history_lock);+}+ /*  * Management for journal control blocks: functions to create and  * destroy journal_t structures, and to initialise and read existing@@ -681,6 +976,9 @@ static journal_t * journal_init_common ( 		kfree(journal); 		goto fail; 	}++	journal_init_stats(journal);+ 	return journal; fail: 	return NULL;@@ -724,6 +1022,7 @@ journal_t * journal_init_dev(struct bloc 	journal->j_blk_offset = start; 	journal->j_maxlen = len; 	journal->j_blocksize = blocksize;+	jbd_stats_proc_init(journal);  	bh = __getblk(journal->j_dev, start, journal->j_blocksize); 	J_ASSERT(bh != NULL);@@ -773,6 +1072,7 @@ journal_t * journal_init_inode (struct i  	journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits; 	journal->j_blocksize = inode->i_sb->s_blocksize;+	jbd_stats_proc_init(journal);  	/* journal descriptor can store up to n blocks -bzzz */ 	n = journal->j_blocksize / sizeof(journal_block_tag_t);@@ -1161,6 +1461,8 @@ void journal_destroy(journal_t *journal) 		brelse(journal->j_sb_buffer); 	} +	if (journal->j_proc_entry)+		jbd_stats_proc_exit(journal); 	if (journal->j_inode) 		iput(journal->j_inode); 	if (journal->j_revoke)@@ -2027,6 +2329,28 @@ static void __exit remove_jbd_proc_entry  #endif +#if defined(CONFIG_PROC_FS)++#define JBD_STATS_PROC_NAME "fs/jbd"++static void __init create_jbd_stats_proc_entry(void)+{+	proc_jbd_stats = proc_mkdir(JBD_STATS_PROC_NAME, NULL);+}++static void __exit remove_jbd_stats_proc_entry(void)+{+	if (proc_jbd_stats)+		remove_proc_entry(JBD_STATS_PROC_NAME, NULL);+}++#else++#define create_jbd_stats_proc_entry() do {} while (0)+#define remove_jbd_stats_proc_entry() do {} while (0)++#endif+ kmem_cache_t *jbd_handle_cache;  static int __init journal_init_handle_cache(void)@@ -2090,6 +2414,7 @@ static int __init journal_init(void) 	if (ret != 0) 		journal_destroy_caches(); 	create_jbd_proc_entry();+	create_jbd_stats_proc_entry(); 	return ret; } @@ -2101,6 +2426,7 @@ static void __exit journal_exit(void) 		printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n); #endif 	remove_jbd_proc_entry();+	remove_jbd_stats_proc_entry(); 	journal_destroy_caches(); } Index: linux-2.6.18-8.1.8/fs/jbd/checkpoint.c===================================================================--- linux-2.6.18-8.1.8.orig/fs/jbd/checkpoint.c	2007-08-28 22:22:10.000000000 +0200+++ linux-2.6.18-8.1.8/fs/jbd/checkpoint.c	2007-08-28 22:23:23.000000000 +0200@@ -231,7 +231,7 @@ __flush_batch(journal_t *journal, struct  * Called under jbd_lock_bh_state(jh2bh(jh)), and drops it  */ static int __process_buffer(journal_t *journal, struct journal_head *jh,-			struct buffer_head **bhs, int *batch_count)+			struct buffer_head **bhs, int *batch_count, transaction_t *transaction) { 	struct buffer_head *bh = jh2bh(jh); 	int ret = 0;@@ -249,6 +249,7 @@ static int __process_buffer(journal_t *j 		transaction_t *t = jh->b_transaction; 		tid_t tid = t->t_tid; +		transaction->t_chp_stats.cs_forced_to_close++; 		spin_unlock(&journal->j_list_lock); 		jbd_unlock_bh_state(bh); 		log_start_commit(journal, tid);@@ -278,6 +279,7 @@ static int __process_buffer(journal_t *j 		bhs[*batch_count] = bh; 		__buffer_relink_io(jh); 		jbd_unlock_bh_state(bh);+		transaction->t_chp_stats.cs_written++; 		(*batch_count)++; 		if (*batch_count == NR_BATCH) { 			spin_unlock(&journal->j_list_lock);@@ -321,6 +323,8 @@ int log_do_checkpoint(journal_t *journal 	if (!journal->j_checkpoint_transactions) 		goto out; 	transaction = journal->j_checkpoint_transactions;+	if (transaction->t_chp_stats.cs_chp_time == 0)+		transaction->t_chp_stats.cs_chp_time = CURRENT_MSECS; 	this_tid = transaction->t_tid; restart: 	/*@@ -345,7 +349,8 @@ restart: 				retry = 1; 				break; 			}-			retry = __process_buffer(journal, jh, bhs,&batch_count);+			retry = __process_buffer(journal, jh, bhs,&batch_count,+						 transaction); 			if (!retry && lock_need_resched(&journal->j_list_lock)){ 				spin_unlock(&journal->j_list_lock); 				retry = 1;@@ -667,6 +672,8 @@ void __journal_insert_checkpoint(struct   void __journal_drop_transaction(journal_t *journal, transaction_t *transaction) {+	struct transaction_stats_s stats;+ 	assert_spin_locked(&journal->j_list_lock); 	if (transaction->t_cpnext) { 		transaction->t_cpnext->t_cpprev = transaction->t_cpprev;@@ -693,5 +700,25 @@ void __journal_drop_transaction(journal_ 	J_ASSERT(journal->j_running_transaction != transaction);  	jbd_debug(1, "Dropping transaction %d, all done\n", transaction->t_tid);++	/*+	 * File the transaction for history+	 */+	if (transaction->t_chp_stats.cs_written != 0 ||+			transaction->t_chp_stats.cs_chp_time != 0) {+		stats.ts_type = JBD_STATS_CHECKPOINT;+		stats.ts_tid = transaction->t_tid;+		stats.u.chp = transaction->t_chp_stats;+		if (stats.ts_chp_time)+			stats.ts_chp_time =+				jbd_time_diff(stats.ts_chp_time, CURRENT_MSECS);+		spin_lock(&journal->j_history_lock);+		memcpy(journal->j_history + journal->j_history_cur, &stats,+				sizeof(stats));+		if (++journal->j_history_cur == journal->j_history_max)+			journal->j_history_cur = 0;+		spin_unlock(&journal->j_history_lock);+	}+ 	kfree(transaction); }Index: linux-2.6.18-8.1.8/fs/jbd/commit.c===================================================================--- linux-2.6.18-8.1.8.orig/fs/jbd/commit.c	2007-08-28 22:22:10.000000000 +0200+++ linux-2.6.18-8.1.8/fs/jbd/commit.c	2007-08-28 22:22:29.000000000 +0200@@ -13,6 +13,7 @@  * part of the ext2fs journaling system.  */ +#include <linux/jiffies.h> #include <linux/time.h> #include <linux/fs.h> #include <linux/jbd.h>@@ -23,6 +24,7 @@ #include <linux/smp_lock.h> #include <linux/crc32.h> + /*  * Default IO end handler for temporary BJ_IO buffer_heads.  */@@ -355,6 +357,7 @@ write_out_data:  */ void journal_commit_transaction(journal_t *journal) {+	struct transaction_stats_s stats; 	transaction_t *commit_transaction; 	struct journal_head *jh, *new_jh, *descriptor; 	struct buffer_head **wbuf = journal->j_wbuf;@@ -403,6 +406,11 @@ void journal_commit_transaction(journal_ 	spin_lock(&journal->j_state_lock); 	commit_transaction->t_state = T_LOCKED; +	stats.ts_wait = commit_transaction->t_max_wait;+	stats.ts_locked = CURRENT_MSECS;+	stats.ts_running = jbd_time_diff(commit_transaction->t_start,+						stats.ts_locked);+ 	spin_lock(&commit_transaction->t_handle_lock); 	while (commit_transaction->t_updates) { 		DEFINE_WAIT(wait);@@ -473,6 +481,9 @@ void journal_commit_transaction(journal_ 	 */ 	journal_switch_revoke_table(journal); +	stats.ts_flushing = CURRENT_MSECS;+	stats.ts_locked = jbd_time_diff(stats.ts_locked, stats.ts_flushing);+ 	commit_transaction->t_state = T_FLUSH; 	journal->j_committing_transaction = commit_transaction; 	journal->j_running_transaction = NULL;@@ -540,6 +551,11 @@ void journal_commit_transaction(journal_ 	 */ 	commit_transaction->t_state = T_COMMIT; +	stats.ts_logging = CURRENT_MSECS;+	stats.ts_flushing = jbd_time_diff(stats.ts_flushing, stats.ts_logging);+	stats.ts_blocks = commit_transaction->t_outstanding_credits;+	stats.ts_blocks_logged = 0;+ 	descriptor = NULL; 	bufs = 0; 	while (commit_transaction->t_buffers) {@@ -698,6 +714,7 @@ start_journal_io: 				submit_bh(WRITE, bh); 			} 			cond_resched();+			stats.ts_blocks_logged += bufs;  			/* Force a new descriptor to be generated next                            time round the loop. */@@ -915,6 +932,7 @@ restart_loop: 		cp_transaction = jh->b_cp_transaction; 		if (cp_transaction) { 			JBUFFER_TRACE(jh, "remove from old cp transaction");+			cp_transaction->t_chp_stats.cs_dropped++; 			__journal_remove_checkpoint(jh); 		} @@ -989,6 +1007,36 @@ restart_loop:  	J_ASSERT(commit_transaction->t_state == T_COMMIT); +	commit_transaction->t_start = CURRENT_MSECS;+	stats.ts_logging = jbd_time_diff(stats.ts_logging,+					 commit_transaction->t_start);++	/*+	 * File the transaction for history+	 */+	stats.ts_type = JBD_STATS_RUN;+	stats.ts_tid = commit_transaction->t_tid;+	stats.ts_handle_count = commit_transaction->t_handle_count;+	spin_lock(&journal->j_history_lock);+	memcpy(journal->j_history + journal->j_history_cur, &stats,+			sizeof(stats));+	if (++journal->j_history_cur == journal->j_history_max)+		journal->j_history_cur = 0;++	/*+	 * Calculate overall stats+	 */+	journal->j_stats.ts_tid++;+	journal->j_stats.ts_wait += stats.ts_wait;+	journal->j_stats.ts_running += stats.ts_running;+	journal->j_stats.ts_locked += stats.ts_locked;+	journal->j_stats.ts_flushing += stats.ts_flushing;+	journal->j_stats.ts_logging += stats.ts_logging;+	journal->j_stats.ts_handle_count += stats.ts_handle_count;+	journal->j_stats.ts_blocks += stats.ts_blocks;+	journal->j_stats.ts_blocks_logged += stats.ts_blocks_logged;+	spin_unlock(&journal->j_history_lock);+ 	commit_transaction->t_state = T_FINISHED; 	J_ASSERT(commit_transaction == journal->j_committing_transaction); 	journal->j_commit_sequence = commit_transaction->t_tid;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -