Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / jbd-static-wbuf-2.6.7.patch
1 Index: linux-2.6.7/include/linux/jbd.h
2 ===================================================================
3 --- linux-2.6.7.orig/include/linux/jbd.h        2004-08-26 17:12:16.000000000 +0400
4 +++ linux-2.6.7/include/linux/jbd.h     2005-01-19 17:08:33.144512008 +0300
5 @@ -826,6 +826,12 @@
6         struct jbd_revoke_table_s *j_revoke_table[2];
7  
8         /*
9 +        * array of bhs for journal_commit_transaction
10 +        */
11 +       struct buffer_head      **j_wbuf;
12 +       int                     j_wbufsize;
13 +
14 +       /*
15          * An opaque pointer to fs-private information.  ext3 puts its
16          * superblock pointer here
17          */
18 Index: linux-2.6.7/include/linux/journal-head.h
19 ===================================================================
20 --- linux-2.6.7.orig/include/linux/journal-head.h       2003-06-24 18:05:26.000000000 +0400
21 +++ linux-2.6.7/include/linux/journal-head.h    2005-01-19 14:09:59.000000000 +0300
22 @@ -80,6 +80,11 @@
23          * [j_list_lock]
24          */
25         struct journal_head *b_cpnext, *b_cpprev;
26 +
27 +       /*
28 +        * counter to track users of the buffer in current transaction
29 +        */
30 +       int b_tcount;
31  };
32  
33  #endif         /* JOURNAL_HEAD_H_INCLUDED */
34 Index: linux-2.6.7/fs/jbd/commit.c
35 ===================================================================
36 --- linux-2.6.7.orig/fs/jbd/commit.c    2004-08-26 17:12:40.000000000 +0400
37 +++ linux-2.6.7/fs/jbd/commit.c 2005-01-19 17:28:32.965111552 +0300
38 @@ -103,7 +103,7 @@
39  {
40         transaction_t *commit_transaction;
41         struct journal_head *jh, *new_jh, *descriptor;
42 -       struct buffer_head *wbuf[64];
43 +       struct buffer_head **wbuf = journal->j_wbuf;
44         int bufs;
45         int flags;
46         int err;
47 @@ -271,7 +283,7 @@
48                                 BUFFER_TRACE(bh, "start journal writeout");
49                                 get_bh(bh);
50                                 wbuf[bufs++] = bh;
51 -                               if (bufs == ARRAY_SIZE(wbuf)) {
52 +                               if (bufs == journal->j_wbufsize) {
53                                         jbd_debug(2, "submit %d writes\n",
54                                                         bufs);
55                                         spin_unlock(&journal->j_list_lock);
56 @@ -488,7 +500,7 @@
57                 /* If there's no more to do, or if the descriptor is full,
58                    let the IO rip! */
59  
60 -               if (bufs == ARRAY_SIZE(wbuf) ||
61 +               if (bufs == journal->j_wbufsize ||
62                     commit_transaction->t_buffers == NULL ||
63                     space_left < sizeof(journal_block_tag_t) + 16) {
64  
65 Index: linux-2.6.7/fs/jbd/journal.c
66 ===================================================================
67 --- linux-2.6.7.orig/fs/jbd/journal.c   2005-01-19 12:07:59.000000000 +0300
68 +++ linux-2.6.7/fs/jbd/journal.c        2005-01-19 17:11:08.589880720 +0300
69 @@ -687,6 +687,7 @@
70  {
71         journal_t *journal = journal_init_common();
72         struct buffer_head *bh;
73 +       int n;
74  
75         if (!journal)
76                 return NULL;
77 @@ -702,6 +703,17 @@
78         journal->j_sb_buffer = bh;
79         journal->j_superblock = (journal_superblock_t *)bh->b_data;
80  
81 +       /* journal descriptor can store upto n blocks -bzzz */
82 +       n = journal->j_blocksize / sizeof(journal_block_tag_t);
83 +       journal->j_wbufsize = n;
84 +       journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
85 +       if (!journal->j_wbuf) {
86 +               printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
87 +                       __FUNCTION__);
88 +               kfree(journal);
89 +               journal = NULL;
90 +       }
91 +       
92         return journal;
93  }
94   
95 @@ -717,7 +729,7 @@
96  {
97         struct buffer_head *bh;
98         journal_t *journal = journal_init_common();
99 -       int err;
100 +       int err, n;
101         unsigned long blocknr;
102  
103         if (!journal)
104 @@ -734,6 +746,17 @@
105         journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits;
106         journal->j_blocksize = inode->i_sb->s_blocksize;
107  
108 +       /* journal descriptor can store upto n blocks -bzzz */
109 +       n = journal->j_blocksize / sizeof(journal_block_tag_t);
110 +       journal->j_wbufsize = n;
111 +       journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
112 +       if (!journal->j_wbuf) {
113 +               printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
114 +                       __FUNCTION__);
115 +               kfree(journal);
116 +               return NULL;
117 +       }
118 +
119         err = journal_bmap(journal, 0, &blocknr);
120         /* If that failed, give up */
121         if (err) {
122 @@ -1107,6 +1130,10 @@
123                 iput(journal->j_inode);
124         if (journal->j_revoke)
125                 journal_destroy_revoke(journal);
126 +       if (journal->j_wbuf) {
127 +               kfree(journal->j_wbuf);
128 +               journal->j_wbuf = NULL;
129 +       }
130         kfree(journal);
131  }
132  
133 Index: linux-2.6.7/fs/jbd/transaction.c
134 ===================================================================
135 --- linux-2.6.7.orig/fs/jbd/transaction.c       2004-08-26 17:12:40.000000000 +0400
136 +++ linux-2.6.7/fs/jbd/transaction.c    2005-01-19 17:23:30.058160408 +0300
137 @@ -611,6 +611,10 @@
138                 handle->h_buffer_credits--;
139                 if (credits)
140                         (*credits)++;
141 +
142 +               /* the block's becoming member of the trasaction -bzzz */
143 +               jh->b_tcount = 0;
144 +
145                 goto done;
146         }
147  
148 @@ -694,6 +698,9 @@
149         if (credits)
150                 (*credits)++;
151  
152 +       /* the block's becoming member of the trasaction -bzzz */
153 +       jh->b_tcount = 0;
154 +
155         /*
156          * Finally, if the buffer is not journaled right now, we need to make
157          * sure it doesn't get written to disk before the caller actually
158 @@ -723,6 +730,11 @@
159                 memcpy(jh->b_frozen_data, source+offset, jh2bh(jh)->b_size);
160                 kunmap_atomic(source, KM_USER0);
161         }
162 +
163 +       /* track all references to the block to be able to recognize the
164 +        * situation when the buffer is not part of transaction -bzzz */
165 +       jh->b_tcount++;
166 +
167         jbd_unlock_bh_state(bh);
168  
169         /*
170 @@ -822,11 +834,20 @@
171                 jh->b_transaction = transaction;
172                 JBUFFER_TRACE(jh, "file as BJ_Reserved");
173                 __journal_file_buffer(jh, transaction, BJ_Reserved);
174 +               jh->b_tcount = 0;
175         } else if (jh->b_transaction == journal->j_committing_transaction) {
176                 JBUFFER_TRACE(jh, "set next transaction");
177                 jh->b_next_transaction = transaction;
178 +               jh->b_tcount = 0;
179         }
180         spin_unlock(&journal->j_list_lock);
181 +
182 +       /*
183 +        * track all reference to the block to be able to recognize
184 +        * the situation when the buffer is not part of transaction -bzzz
185 +        */
186 +       jh->b_tcount++;
187 +
188         jbd_unlock_bh_state(bh);
189  
190         /*
191 @@ -1178,8 +1199,40 @@
192  void
193  journal_release_buffer(handle_t *handle, struct buffer_head *bh, int credits)
194  {
195 +       journal_t *journal = handle->h_transaction->t_journal;
196 +       struct journal_head *jh = bh2jh(bh);
197 +
198         BUFFER_TRACE(bh, "entry");
199 -       handle->h_buffer_credits += credits;
200 +
201 +       /* return credit back to the handle if it was really spent */
202 +       if (credits)
203 +               handle->h_buffer_credits++; 
204 +
205 +       jbd_lock_bh_state(bh);
206 +       J_ASSERT(jh->b_tcount > 0);
207 +
208 +       jh->b_tcount--;
209 +       if (jh->b_tcount == 0) {
210 +               /* we can drop it from the transaction -bzzz */
211 +               J_ASSERT(jh->b_transaction == handle->h_transaction ||
212 +                               jh->b_next_transaction == handle->h_transaction);
213 +               if (jh->b_transaction == handle->h_transaction) {
214 +                       spin_lock(&journal->j_list_lock);
215 +                       __journal_unfile_buffer(jh);
216 +                       spin_unlock(&journal->j_list_lock);
217 +               } else if(jh->b_next_transaction) {
218 +                       jh->b_next_transaction = NULL;
219 +               }
220 +
221 +               /* 
222 +                * this was last reference to the block from the current
223 +                * transaction and we'd like to return credit to the
224 +                * whole transaction -bzzz
225 +                */
226 +               if (!credits)
227 +                       handle->h_buffer_credits++; 
228 +       }
229 +       jbd_unlock_bh_state(bh);
230  }
231  
232  /** 
233 @@ -1204,6 +1257,7 @@
234         transaction_t *transaction = handle->h_transaction;
235         journal_t *journal = transaction->t_journal;
236         struct journal_head *jh;
237 +       int drop_reserve = 0;
238  
239         BUFFER_TRACE(bh, "entry");
240  
241 @@ -1227,6 +1281,7 @@
242                 J_ASSERT_JH(jh, !jh->b_committed_data);
243  
244                 __journal_unfile_buffer(jh);
245 +               drop_reserve = 1;
246  
247                 /* 
248                  * We are no longer going to journal this buffer.
249 @@ -1249,7 +1304,7 @@
250                                 spin_unlock(&journal->j_list_lock);
251                                 jbd_unlock_bh_state(bh);
252                                 __bforget(bh);
253 -                               return;
254 +                               goto drop;
255                         }
256                 }
257         } else if (jh->b_transaction) {
258 @@ -1264,6 +1319,7 @@
259                 if (jh->b_next_transaction) {
260                         J_ASSERT(jh->b_next_transaction == transaction);
261                         jh->b_next_transaction = NULL;
262 +                       drop_reserve = 1;
263                 }
264         }
265  
266 @@ -1271,6 +1327,15 @@
267         spin_unlock(&journal->j_list_lock);
268         jbd_unlock_bh_state(bh);
269         __brelse(bh);
270 +
271 +drop:
272 +       if (drop_reserve) {
273 +               /* no need to reserve log space for this block -bzzz */
274 +               spin_lock(&transaction->t_handle_lock);
275 +               transaction->t_outstanding_credits--;
276 +               spin_unlock(&transaction->t_handle_lock);
277 +       }
278 +
279         return;
280  }
281