Commit | Line | Data |
---|---|---|
0a8165d7 | 1 | /* |
351df4b2 JK |
2 | * fs/f2fs/segment.c |
3 | * | |
4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | |
5 | * http://www.samsung.com/ | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | #include <linux/fs.h> | |
12 | #include <linux/f2fs_fs.h> | |
13 | #include <linux/bio.h> | |
14 | #include <linux/blkdev.h> | |
690e4a3e | 15 | #include <linux/prefetch.h> |
351df4b2 JK |
16 | #include <linux/vmalloc.h> |
17 | ||
18 | #include "f2fs.h" | |
19 | #include "segment.h" | |
20 | #include "node.h" | |
6ec178da | 21 | #include <trace/events/f2fs.h> |
351df4b2 | 22 | |
9a7f143a CL |
23 | #define __reverse_ffz(x) __reverse_ffs(~(x)) |
24 | ||
7fd9e544 JK |
25 | static struct kmem_cache *discard_entry_slab; |
26 | ||
9a7f143a CL |
27 | /* |
28 | * __reverse_ffs is copied from include/asm-generic/bitops/__ffs.h since | |
29 | * MSB and LSB are reversed in a byte by f2fs_set_bit. | |
30 | */ | |
31 | static inline unsigned long __reverse_ffs(unsigned long word) | |
32 | { | |
33 | int num = 0; | |
34 | ||
35 | #if BITS_PER_LONG == 64 | |
36 | if ((word & 0xffffffff) == 0) { | |
37 | num += 32; | |
38 | word >>= 32; | |
39 | } | |
40 | #endif | |
41 | if ((word & 0xffff) == 0) { | |
42 | num += 16; | |
43 | word >>= 16; | |
44 | } | |
45 | if ((word & 0xff) == 0) { | |
46 | num += 8; | |
47 | word >>= 8; | |
48 | } | |
49 | if ((word & 0xf0) == 0) | |
50 | num += 4; | |
51 | else | |
52 | word >>= 4; | |
53 | if ((word & 0xc) == 0) | |
54 | num += 2; | |
55 | else | |
56 | word >>= 2; | |
57 | if ((word & 0x2) == 0) | |
58 | num += 1; | |
59 | return num; | |
60 | } | |
61 | ||
62 | /* | |
63 | * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c becasue | |
64 | * f2fs_set_bit makes MSB and LSB reversed in a byte. | |
65 | * Example: | |
66 | * LSB <--> MSB | |
67 | * f2fs_set_bit(0, bitmap) => 0000 0001 | |
68 | * f2fs_set_bit(7, bitmap) => 1000 0000 | |
69 | */ | |
70 | static unsigned long __find_rev_next_bit(const unsigned long *addr, | |
71 | unsigned long size, unsigned long offset) | |
72 | { | |
73 | const unsigned long *p = addr + BIT_WORD(offset); | |
74 | unsigned long result = offset & ~(BITS_PER_LONG - 1); | |
75 | unsigned long tmp; | |
76 | unsigned long mask, submask; | |
77 | unsigned long quot, rest; | |
78 | ||
79 | if (offset >= size) | |
80 | return size; | |
81 | ||
82 | size -= result; | |
83 | offset %= BITS_PER_LONG; | |
84 | if (!offset) | |
85 | goto aligned; | |
86 | ||
87 | tmp = *(p++); | |
88 | quot = (offset >> 3) << 3; | |
89 | rest = offset & 0x7; | |
90 | mask = ~0UL << quot; | |
91 | submask = (unsigned char)(0xff << rest) >> rest; | |
92 | submask <<= quot; | |
93 | mask &= submask; | |
94 | tmp &= mask; | |
95 | if (size < BITS_PER_LONG) | |
96 | goto found_first; | |
97 | if (tmp) | |
98 | goto found_middle; | |
99 | ||
100 | size -= BITS_PER_LONG; | |
101 | result += BITS_PER_LONG; | |
102 | aligned: | |
103 | while (size & ~(BITS_PER_LONG-1)) { | |
104 | tmp = *(p++); | |
105 | if (tmp) | |
106 | goto found_middle; | |
107 | result += BITS_PER_LONG; | |
108 | size -= BITS_PER_LONG; | |
109 | } | |
110 | if (!size) | |
111 | return result; | |
112 | tmp = *p; | |
113 | found_first: | |
114 | tmp &= (~0UL >> (BITS_PER_LONG - size)); | |
115 | if (tmp == 0UL) /* Are any bits set? */ | |
116 | return result + size; /* Nope. */ | |
117 | found_middle: | |
118 | return result + __reverse_ffs(tmp); | |
119 | } | |
120 | ||
121 | static unsigned long __find_rev_next_zero_bit(const unsigned long *addr, | |
122 | unsigned long size, unsigned long offset) | |
123 | { | |
124 | const unsigned long *p = addr + BIT_WORD(offset); | |
125 | unsigned long result = offset & ~(BITS_PER_LONG - 1); | |
126 | unsigned long tmp; | |
127 | unsigned long mask, submask; | |
128 | unsigned long quot, rest; | |
129 | ||
130 | if (offset >= size) | |
131 | return size; | |
132 | ||
133 | size -= result; | |
134 | offset %= BITS_PER_LONG; | |
135 | if (!offset) | |
136 | goto aligned; | |
137 | ||
138 | tmp = *(p++); | |
139 | quot = (offset >> 3) << 3; | |
140 | rest = offset & 0x7; | |
141 | mask = ~(~0UL << quot); | |
142 | submask = (unsigned char)~((unsigned char)(0xff << rest) >> rest); | |
143 | submask <<= quot; | |
144 | mask += submask; | |
145 | tmp |= mask; | |
146 | if (size < BITS_PER_LONG) | |
147 | goto found_first; | |
148 | if (~tmp) | |
149 | goto found_middle; | |
150 | ||
151 | size -= BITS_PER_LONG; | |
152 | result += BITS_PER_LONG; | |
153 | aligned: | |
154 | while (size & ~(BITS_PER_LONG - 1)) { | |
155 | tmp = *(p++); | |
156 | if (~tmp) | |
157 | goto found_middle; | |
158 | result += BITS_PER_LONG; | |
159 | size -= BITS_PER_LONG; | |
160 | } | |
161 | if (!size) | |
162 | return result; | |
163 | tmp = *p; | |
164 | ||
165 | found_first: | |
166 | tmp |= ~0UL << size; | |
167 | if (tmp == ~0UL) /* Are any bits zero? */ | |
168 | return result + size; /* Nope. */ | |
169 | found_middle: | |
170 | return result + __reverse_ffz(tmp); | |
171 | } | |
172 | ||
0a8165d7 | 173 | /* |
351df4b2 JK |
174 | * This function balances dirty node and dentry pages. |
175 | * In addition, it controls garbage collection. | |
176 | */ | |
177 | void f2fs_balance_fs(struct f2fs_sb_info *sbi) | |
178 | { | |
351df4b2 | 179 | /* |
029cd28c JK |
180 | * We should do GC or end up with checkpoint, if there are so many dirty |
181 | * dir/node pages without enough free segments. | |
351df4b2 | 182 | */ |
43727527 | 183 | if (has_not_enough_free_secs(sbi, 0)) { |
351df4b2 | 184 | mutex_lock(&sbi->gc_mutex); |
408e9375 | 185 | f2fs_gc(sbi); |
351df4b2 JK |
186 | } |
187 | } | |
188 | ||
4660f9c0 JK |
189 | void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi) |
190 | { | |
191 | /* check the # of cached NAT entries and prefree segments */ | |
192 | if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK) || | |
193 | excess_prefree_segs(sbi)) | |
194 | f2fs_sync_fs(sbi->sb, true); | |
195 | } | |
196 | ||
351df4b2 JK |
197 | static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, |
198 | enum dirty_type dirty_type) | |
199 | { | |
200 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
201 | ||
202 | /* need not be added */ | |
203 | if (IS_CURSEG(sbi, segno)) | |
204 | return; | |
205 | ||
206 | if (!test_and_set_bit(segno, dirty_i->dirty_segmap[dirty_type])) | |
207 | dirty_i->nr_dirty[dirty_type]++; | |
208 | ||
209 | if (dirty_type == DIRTY) { | |
210 | struct seg_entry *sentry = get_seg_entry(sbi, segno); | |
4625d6aa | 211 | enum dirty_type t = sentry->type; |
b2f2c390 | 212 | |
4625d6aa CL |
213 | if (!test_and_set_bit(segno, dirty_i->dirty_segmap[t])) |
214 | dirty_i->nr_dirty[t]++; | |
351df4b2 JK |
215 | } |
216 | } | |
217 | ||
218 | static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, | |
219 | enum dirty_type dirty_type) | |
220 | { | |
221 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
222 | ||
223 | if (test_and_clear_bit(segno, dirty_i->dirty_segmap[dirty_type])) | |
224 | dirty_i->nr_dirty[dirty_type]--; | |
225 | ||
226 | if (dirty_type == DIRTY) { | |
4625d6aa CL |
227 | struct seg_entry *sentry = get_seg_entry(sbi, segno); |
228 | enum dirty_type t = sentry->type; | |
229 | ||
230 | if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t])) | |
231 | dirty_i->nr_dirty[t]--; | |
b2f2c390 | 232 | |
5ec4e49f JK |
233 | if (get_valid_blocks(sbi, segno, sbi->segs_per_sec) == 0) |
234 | clear_bit(GET_SECNO(sbi, segno), | |
235 | dirty_i->victim_secmap); | |
351df4b2 JK |
236 | } |
237 | } | |
238 | ||
0a8165d7 | 239 | /* |
351df4b2 JK |
240 | * Should not occur error such as -ENOMEM. |
241 | * Adding dirty entry into seglist is not critical operation. | |
242 | * If a given segment is one of current working segments, it won't be added. | |
243 | */ | |
8d8451af | 244 | static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno) |
351df4b2 JK |
245 | { |
246 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
247 | unsigned short valid_blocks; | |
248 | ||
249 | if (segno == NULL_SEGNO || IS_CURSEG(sbi, segno)) | |
250 | return; | |
251 | ||
252 | mutex_lock(&dirty_i->seglist_lock); | |
253 | ||
254 | valid_blocks = get_valid_blocks(sbi, segno, 0); | |
255 | ||
256 | if (valid_blocks == 0) { | |
257 | __locate_dirty_segment(sbi, segno, PRE); | |
258 | __remove_dirty_segment(sbi, segno, DIRTY); | |
259 | } else if (valid_blocks < sbi->blocks_per_seg) { | |
260 | __locate_dirty_segment(sbi, segno, DIRTY); | |
261 | } else { | |
262 | /* Recovery routine with SSR needs this */ | |
263 | __remove_dirty_segment(sbi, segno, DIRTY); | |
264 | } | |
265 | ||
266 | mutex_unlock(&dirty_i->seglist_lock); | |
351df4b2 JK |
267 | } |
268 | ||
37208879 JK |
269 | static void f2fs_issue_discard(struct f2fs_sb_info *sbi, |
270 | block_t blkstart, block_t blklen) | |
271 | { | |
272 | sector_t start = ((sector_t)blkstart) << sbi->log_sectors_per_block; | |
273 | sector_t len = ((sector_t)blklen) << sbi->log_sectors_per_block; | |
274 | blkdev_issue_discard(sbi->sb->s_bdev, start, len, GFP_NOFS, 0); | |
275 | } | |
276 | ||
b2955550 JK |
277 | static void add_discard_addrs(struct f2fs_sb_info *sbi, |
278 | unsigned int segno, struct seg_entry *se) | |
279 | { | |
280 | struct list_head *head = &SM_I(sbi)->discard_list; | |
281 | struct discard_entry *new; | |
282 | int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long); | |
283 | int max_blocks = sbi->blocks_per_seg; | |
284 | unsigned long *cur_map = (unsigned long *)se->cur_valid_map; | |
285 | unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map; | |
286 | unsigned long dmap[entries]; | |
287 | unsigned int start = 0, end = -1; | |
288 | int i; | |
289 | ||
290 | if (!test_opt(sbi, DISCARD)) | |
291 | return; | |
292 | ||
293 | /* zero block will be discarded through the prefree list */ | |
294 | if (!se->valid_blocks || se->valid_blocks == max_blocks) | |
295 | return; | |
296 | ||
297 | /* SIT_VBLOCK_MAP_SIZE should be multiple of sizeof(unsigned long) */ | |
298 | for (i = 0; i < entries; i++) | |
299 | dmap[i] = (cur_map[i] ^ ckpt_map[i]) & ckpt_map[i]; | |
300 | ||
301 | while (SM_I(sbi)->nr_discards <= SM_I(sbi)->max_discards) { | |
302 | start = __find_rev_next_bit(dmap, max_blocks, end + 1); | |
303 | if (start >= max_blocks) | |
304 | break; | |
305 | ||
306 | end = __find_rev_next_zero_bit(dmap, max_blocks, start + 1); | |
307 | ||
308 | new = f2fs_kmem_cache_alloc(discard_entry_slab, GFP_NOFS); | |
309 | INIT_LIST_HEAD(&new->list); | |
310 | new->blkaddr = START_BLOCK(sbi, segno) + start; | |
311 | new->len = end - start; | |
312 | ||
313 | list_add_tail(&new->list, head); | |
314 | SM_I(sbi)->nr_discards += end - start; | |
315 | } | |
316 | } | |
317 | ||
0a8165d7 | 318 | /* |
351df4b2 JK |
319 | * Should call clear_prefree_segments after checkpoint is done. |
320 | */ | |
321 | static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi) | |
322 | { | |
323 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
81fb5e87 | 324 | unsigned int segno = -1; |
351df4b2 JK |
325 | unsigned int total_segs = TOTAL_SEGS(sbi); |
326 | ||
327 | mutex_lock(&dirty_i->seglist_lock); | |
328 | while (1) { | |
329 | segno = find_next_bit(dirty_i->dirty_segmap[PRE], total_segs, | |
81fb5e87 | 330 | segno + 1); |
351df4b2 JK |
331 | if (segno >= total_segs) |
332 | break; | |
333 | __set_test_and_free(sbi, segno); | |
351df4b2 JK |
334 | } |
335 | mutex_unlock(&dirty_i->seglist_lock); | |
336 | } | |
337 | ||
338 | void clear_prefree_segments(struct f2fs_sb_info *sbi) | |
339 | { | |
b2955550 JK |
340 | struct list_head *head = &(SM_I(sbi)->discard_list); |
341 | struct list_head *this, *next; | |
342 | struct discard_entry *entry; | |
351df4b2 | 343 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); |
29e59c14 | 344 | unsigned long *prefree_map = dirty_i->dirty_segmap[PRE]; |
351df4b2 | 345 | unsigned int total_segs = TOTAL_SEGS(sbi); |
29e59c14 | 346 | unsigned int start = 0, end = -1; |
351df4b2 JK |
347 | |
348 | mutex_lock(&dirty_i->seglist_lock); | |
29e59c14 | 349 | |
351df4b2 | 350 | while (1) { |
29e59c14 CL |
351 | int i; |
352 | start = find_next_bit(prefree_map, total_segs, end + 1); | |
353 | if (start >= total_segs) | |
351df4b2 | 354 | break; |
29e59c14 CL |
355 | end = find_next_zero_bit(prefree_map, total_segs, start + 1); |
356 | ||
357 | for (i = start; i < end; i++) | |
358 | clear_bit(i, prefree_map); | |
359 | ||
360 | dirty_i->nr_dirty[PRE] -= end - start; | |
361 | ||
362 | if (!test_opt(sbi, DISCARD)) | |
363 | continue; | |
351df4b2 | 364 | |
37208879 JK |
365 | f2fs_issue_discard(sbi, START_BLOCK(sbi, start), |
366 | (end - start) << sbi->log_blocks_per_seg); | |
351df4b2 JK |
367 | } |
368 | mutex_unlock(&dirty_i->seglist_lock); | |
b2955550 JK |
369 | |
370 | /* send small discards */ | |
371 | list_for_each_safe(this, next, head) { | |
372 | entry = list_entry(this, struct discard_entry, list); | |
37208879 | 373 | f2fs_issue_discard(sbi, entry->blkaddr, entry->len); |
b2955550 JK |
374 | list_del(&entry->list); |
375 | SM_I(sbi)->nr_discards -= entry->len; | |
376 | kmem_cache_free(discard_entry_slab, entry); | |
377 | } | |
351df4b2 JK |
378 | } |
379 | ||
380 | static void __mark_sit_entry_dirty(struct f2fs_sb_info *sbi, unsigned int segno) | |
381 | { | |
382 | struct sit_info *sit_i = SIT_I(sbi); | |
383 | if (!__test_and_set_bit(segno, sit_i->dirty_sentries_bitmap)) | |
384 | sit_i->dirty_sentries++; | |
385 | } | |
386 | ||
387 | static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type, | |
388 | unsigned int segno, int modified) | |
389 | { | |
390 | struct seg_entry *se = get_seg_entry(sbi, segno); | |
391 | se->type = type; | |
392 | if (modified) | |
393 | __mark_sit_entry_dirty(sbi, segno); | |
394 | } | |
395 | ||
396 | static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) | |
397 | { | |
398 | struct seg_entry *se; | |
399 | unsigned int segno, offset; | |
400 | long int new_vblocks; | |
401 | ||
402 | segno = GET_SEGNO(sbi, blkaddr); | |
403 | ||
404 | se = get_seg_entry(sbi, segno); | |
405 | new_vblocks = se->valid_blocks + del; | |
406 | offset = GET_SEGOFF_FROM_SEG0(sbi, blkaddr) & (sbi->blocks_per_seg - 1); | |
407 | ||
5d56b671 | 408 | f2fs_bug_on((new_vblocks >> (sizeof(unsigned short) << 3) || |
351df4b2 JK |
409 | (new_vblocks > sbi->blocks_per_seg))); |
410 | ||
411 | se->valid_blocks = new_vblocks; | |
412 | se->mtime = get_mtime(sbi); | |
413 | SIT_I(sbi)->max_mtime = se->mtime; | |
414 | ||
415 | /* Update valid block bitmap */ | |
416 | if (del > 0) { | |
417 | if (f2fs_set_bit(offset, se->cur_valid_map)) | |
418 | BUG(); | |
419 | } else { | |
420 | if (!f2fs_clear_bit(offset, se->cur_valid_map)) | |
421 | BUG(); | |
422 | } | |
423 | if (!f2fs_test_bit(offset, se->ckpt_valid_map)) | |
424 | se->ckpt_valid_blocks += del; | |
425 | ||
426 | __mark_sit_entry_dirty(sbi, segno); | |
427 | ||
428 | /* update total number of valid blocks to be written in ckpt area */ | |
429 | SIT_I(sbi)->written_valid_blocks += del; | |
430 | ||
431 | if (sbi->segs_per_sec > 1) | |
432 | get_sec_entry(sbi, segno)->valid_blocks += del; | |
433 | } | |
434 | ||
435 | static void refresh_sit_entry(struct f2fs_sb_info *sbi, | |
436 | block_t old_blkaddr, block_t new_blkaddr) | |
437 | { | |
438 | update_sit_entry(sbi, new_blkaddr, 1); | |
439 | if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) | |
440 | update_sit_entry(sbi, old_blkaddr, -1); | |
441 | } | |
442 | ||
443 | void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr) | |
444 | { | |
445 | unsigned int segno = GET_SEGNO(sbi, addr); | |
446 | struct sit_info *sit_i = SIT_I(sbi); | |
447 | ||
5d56b671 | 448 | f2fs_bug_on(addr == NULL_ADDR); |
351df4b2 JK |
449 | if (addr == NEW_ADDR) |
450 | return; | |
451 | ||
452 | /* add it into sit main buffer */ | |
453 | mutex_lock(&sit_i->sentry_lock); | |
454 | ||
455 | update_sit_entry(sbi, addr, -1); | |
456 | ||
457 | /* add it into dirty seglist */ | |
458 | locate_dirty_segment(sbi, segno); | |
459 | ||
460 | mutex_unlock(&sit_i->sentry_lock); | |
461 | } | |
462 | ||
0a8165d7 | 463 | /* |
351df4b2 JK |
464 | * This function should be resided under the curseg_mutex lock |
465 | */ | |
466 | static void __add_sum_entry(struct f2fs_sb_info *sbi, int type, | |
e79efe3b | 467 | struct f2fs_summary *sum) |
351df4b2 JK |
468 | { |
469 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
470 | void *addr = curseg->sum_blk; | |
e79efe3b | 471 | addr += curseg->next_blkoff * sizeof(struct f2fs_summary); |
351df4b2 | 472 | memcpy(addr, sum, sizeof(struct f2fs_summary)); |
351df4b2 JK |
473 | } |
474 | ||
0a8165d7 | 475 | /* |
351df4b2 JK |
476 | * Calculate the number of current summary pages for writing |
477 | */ | |
478 | int npages_for_summary_flush(struct f2fs_sb_info *sbi) | |
479 | { | |
351df4b2 | 480 | int valid_sum_count = 0; |
9a47938b | 481 | int i, sum_in_page; |
351df4b2 JK |
482 | |
483 | for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { | |
484 | if (sbi->ckpt->alloc_type[i] == SSR) | |
485 | valid_sum_count += sbi->blocks_per_seg; | |
486 | else | |
487 | valid_sum_count += curseg_blkoff(sbi, i); | |
488 | } | |
489 | ||
9a47938b FL |
490 | sum_in_page = (PAGE_CACHE_SIZE - 2 * SUM_JOURNAL_SIZE - |
491 | SUM_FOOTER_SIZE) / SUMMARY_SIZE; | |
492 | if (valid_sum_count <= sum_in_page) | |
351df4b2 | 493 | return 1; |
9a47938b FL |
494 | else if ((valid_sum_count - sum_in_page) <= |
495 | (PAGE_CACHE_SIZE - SUM_FOOTER_SIZE) / SUMMARY_SIZE) | |
351df4b2 JK |
496 | return 2; |
497 | return 3; | |
498 | } | |
499 | ||
0a8165d7 | 500 | /* |
351df4b2 JK |
501 | * Caller should put this summary page |
502 | */ | |
503 | struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno) | |
504 | { | |
505 | return get_meta_page(sbi, GET_SUM_BLOCK(sbi, segno)); | |
506 | } | |
507 | ||
508 | static void write_sum_page(struct f2fs_sb_info *sbi, | |
509 | struct f2fs_summary_block *sum_blk, block_t blk_addr) | |
510 | { | |
511 | struct page *page = grab_meta_page(sbi, blk_addr); | |
512 | void *kaddr = page_address(page); | |
513 | memcpy(kaddr, sum_blk, PAGE_CACHE_SIZE); | |
514 | set_page_dirty(page); | |
515 | f2fs_put_page(page, 1); | |
516 | } | |
517 | ||
60374688 JK |
518 | static int is_next_segment_free(struct f2fs_sb_info *sbi, int type) |
519 | { | |
520 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
81fb5e87 | 521 | unsigned int segno = curseg->segno + 1; |
60374688 JK |
522 | struct free_segmap_info *free_i = FREE_I(sbi); |
523 | ||
81fb5e87 HL |
524 | if (segno < TOTAL_SEGS(sbi) && segno % sbi->segs_per_sec) |
525 | return !test_bit(segno, free_i->free_segmap); | |
60374688 JK |
526 | return 0; |
527 | } | |
528 | ||
0a8165d7 | 529 | /* |
351df4b2 JK |
530 | * Find a new segment from the free segments bitmap to right order |
531 | * This function should be returned with success, otherwise BUG | |
532 | */ | |
533 | static void get_new_segment(struct f2fs_sb_info *sbi, | |
534 | unsigned int *newseg, bool new_sec, int dir) | |
535 | { | |
536 | struct free_segmap_info *free_i = FREE_I(sbi); | |
351df4b2 | 537 | unsigned int segno, secno, zoneno; |
53cf9522 | 538 | unsigned int total_zones = TOTAL_SECS(sbi) / sbi->secs_per_zone; |
351df4b2 JK |
539 | unsigned int hint = *newseg / sbi->segs_per_sec; |
540 | unsigned int old_zoneno = GET_ZONENO_FROM_SEGNO(sbi, *newseg); | |
541 | unsigned int left_start = hint; | |
542 | bool init = true; | |
543 | int go_left = 0; | |
544 | int i; | |
545 | ||
546 | write_lock(&free_i->segmap_lock); | |
547 | ||
548 | if (!new_sec && ((*newseg + 1) % sbi->segs_per_sec)) { | |
549 | segno = find_next_zero_bit(free_i->free_segmap, | |
550 | TOTAL_SEGS(sbi), *newseg + 1); | |
33afa7fd JK |
551 | if (segno - *newseg < sbi->segs_per_sec - |
552 | (*newseg % sbi->segs_per_sec)) | |
351df4b2 JK |
553 | goto got_it; |
554 | } | |
555 | find_other_zone: | |
53cf9522 JK |
556 | secno = find_next_zero_bit(free_i->free_secmap, TOTAL_SECS(sbi), hint); |
557 | if (secno >= TOTAL_SECS(sbi)) { | |
351df4b2 JK |
558 | if (dir == ALLOC_RIGHT) { |
559 | secno = find_next_zero_bit(free_i->free_secmap, | |
53cf9522 | 560 | TOTAL_SECS(sbi), 0); |
5d56b671 | 561 | f2fs_bug_on(secno >= TOTAL_SECS(sbi)); |
351df4b2 JK |
562 | } else { |
563 | go_left = 1; | |
564 | left_start = hint - 1; | |
565 | } | |
566 | } | |
567 | if (go_left == 0) | |
568 | goto skip_left; | |
569 | ||
570 | while (test_bit(left_start, free_i->free_secmap)) { | |
571 | if (left_start > 0) { | |
572 | left_start--; | |
573 | continue; | |
574 | } | |
575 | left_start = find_next_zero_bit(free_i->free_secmap, | |
53cf9522 | 576 | TOTAL_SECS(sbi), 0); |
5d56b671 | 577 | f2fs_bug_on(left_start >= TOTAL_SECS(sbi)); |
351df4b2 JK |
578 | break; |
579 | } | |
580 | secno = left_start; | |
581 | skip_left: | |
582 | hint = secno; | |
583 | segno = secno * sbi->segs_per_sec; | |
584 | zoneno = secno / sbi->secs_per_zone; | |
585 | ||
586 | /* give up on finding another zone */ | |
587 | if (!init) | |
588 | goto got_it; | |
589 | if (sbi->secs_per_zone == 1) | |
590 | goto got_it; | |
591 | if (zoneno == old_zoneno) | |
592 | goto got_it; | |
593 | if (dir == ALLOC_LEFT) { | |
594 | if (!go_left && zoneno + 1 >= total_zones) | |
595 | goto got_it; | |
596 | if (go_left && zoneno == 0) | |
597 | goto got_it; | |
598 | } | |
599 | for (i = 0; i < NR_CURSEG_TYPE; i++) | |
600 | if (CURSEG_I(sbi, i)->zone == zoneno) | |
601 | break; | |
602 | ||
603 | if (i < NR_CURSEG_TYPE) { | |
604 | /* zone is in user, try another */ | |
605 | if (go_left) | |
606 | hint = zoneno * sbi->secs_per_zone - 1; | |
607 | else if (zoneno + 1 >= total_zones) | |
608 | hint = 0; | |
609 | else | |
610 | hint = (zoneno + 1) * sbi->secs_per_zone; | |
611 | init = false; | |
612 | goto find_other_zone; | |
613 | } | |
614 | got_it: | |
615 | /* set it as dirty segment in free segmap */ | |
5d56b671 | 616 | f2fs_bug_on(test_bit(segno, free_i->free_segmap)); |
351df4b2 JK |
617 | __set_inuse(sbi, segno); |
618 | *newseg = segno; | |
619 | write_unlock(&free_i->segmap_lock); | |
620 | } | |
621 | ||
622 | static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) | |
623 | { | |
624 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
625 | struct summary_footer *sum_footer; | |
626 | ||
627 | curseg->segno = curseg->next_segno; | |
628 | curseg->zone = GET_ZONENO_FROM_SEGNO(sbi, curseg->segno); | |
629 | curseg->next_blkoff = 0; | |
630 | curseg->next_segno = NULL_SEGNO; | |
631 | ||
632 | sum_footer = &(curseg->sum_blk->footer); | |
633 | memset(sum_footer, 0, sizeof(struct summary_footer)); | |
634 | if (IS_DATASEG(type)) | |
635 | SET_SUM_TYPE(sum_footer, SUM_TYPE_DATA); | |
636 | if (IS_NODESEG(type)) | |
637 | SET_SUM_TYPE(sum_footer, SUM_TYPE_NODE); | |
638 | __set_sit_entry_type(sbi, type, curseg->segno, modified); | |
639 | } | |
640 | ||
0a8165d7 | 641 | /* |
351df4b2 JK |
642 | * Allocate a current working segment. |
643 | * This function always allocates a free segment in LFS manner. | |
644 | */ | |
645 | static void new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) | |
646 | { | |
647 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
648 | unsigned int segno = curseg->segno; | |
649 | int dir = ALLOC_LEFT; | |
650 | ||
651 | write_sum_page(sbi, curseg->sum_blk, | |
81fb5e87 | 652 | GET_SUM_BLOCK(sbi, segno)); |
351df4b2 JK |
653 | if (type == CURSEG_WARM_DATA || type == CURSEG_COLD_DATA) |
654 | dir = ALLOC_RIGHT; | |
655 | ||
656 | if (test_opt(sbi, NOHEAP)) | |
657 | dir = ALLOC_RIGHT; | |
658 | ||
659 | get_new_segment(sbi, &segno, new_sec, dir); | |
660 | curseg->next_segno = segno; | |
661 | reset_curseg(sbi, type, 1); | |
662 | curseg->alloc_type = LFS; | |
663 | } | |
664 | ||
665 | static void __next_free_blkoff(struct f2fs_sb_info *sbi, | |
666 | struct curseg_info *seg, block_t start) | |
667 | { | |
668 | struct seg_entry *se = get_seg_entry(sbi, seg->segno); | |
e81c93cf CL |
669 | int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long); |
670 | unsigned long target_map[entries]; | |
671 | unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map; | |
672 | unsigned long *cur_map = (unsigned long *)se->cur_valid_map; | |
673 | int i, pos; | |
674 | ||
675 | for (i = 0; i < entries; i++) | |
676 | target_map[i] = ckpt_map[i] | cur_map[i]; | |
677 | ||
678 | pos = __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start); | |
679 | ||
680 | seg->next_blkoff = pos; | |
351df4b2 JK |
681 | } |
682 | ||
0a8165d7 | 683 | /* |
351df4b2 JK |
684 | * If a segment is written by LFS manner, next block offset is just obtained |
685 | * by increasing the current block offset. However, if a segment is written by | |
686 | * SSR manner, next block offset obtained by calling __next_free_blkoff | |
687 | */ | |
688 | static void __refresh_next_blkoff(struct f2fs_sb_info *sbi, | |
689 | struct curseg_info *seg) | |
690 | { | |
691 | if (seg->alloc_type == SSR) | |
692 | __next_free_blkoff(sbi, seg, seg->next_blkoff + 1); | |
693 | else | |
694 | seg->next_blkoff++; | |
695 | } | |
696 | ||
0a8165d7 | 697 | /* |
351df4b2 JK |
698 | * This function always allocates a used segment (from dirty seglist) by SSR |
699 | * manner, so it should recover the existing segment information of valid blocks | |
700 | */ | |
701 | static void change_curseg(struct f2fs_sb_info *sbi, int type, bool reuse) | |
702 | { | |
703 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
704 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
705 | unsigned int new_segno = curseg->next_segno; | |
706 | struct f2fs_summary_block *sum_node; | |
707 | struct page *sum_page; | |
708 | ||
709 | write_sum_page(sbi, curseg->sum_blk, | |
710 | GET_SUM_BLOCK(sbi, curseg->segno)); | |
711 | __set_test_and_inuse(sbi, new_segno); | |
712 | ||
713 | mutex_lock(&dirty_i->seglist_lock); | |
714 | __remove_dirty_segment(sbi, new_segno, PRE); | |
715 | __remove_dirty_segment(sbi, new_segno, DIRTY); | |
716 | mutex_unlock(&dirty_i->seglist_lock); | |
717 | ||
718 | reset_curseg(sbi, type, 1); | |
719 | curseg->alloc_type = SSR; | |
720 | __next_free_blkoff(sbi, curseg, 0); | |
721 | ||
722 | if (reuse) { | |
723 | sum_page = get_sum_page(sbi, new_segno); | |
724 | sum_node = (struct f2fs_summary_block *)page_address(sum_page); | |
725 | memcpy(curseg->sum_blk, sum_node, SUM_ENTRY_SIZE); | |
726 | f2fs_put_page(sum_page, 1); | |
727 | } | |
728 | } | |
729 | ||
43727527 JK |
730 | static int get_ssr_segment(struct f2fs_sb_info *sbi, int type) |
731 | { | |
732 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
733 | const struct victim_selection *v_ops = DIRTY_I(sbi)->v_ops; | |
734 | ||
735 | if (IS_NODESEG(type) || !has_not_enough_free_secs(sbi, 0)) | |
736 | return v_ops->get_victim(sbi, | |
737 | &(curseg)->next_segno, BG_GC, type, SSR); | |
738 | ||
739 | /* For data segments, let's do SSR more intensively */ | |
740 | for (; type >= CURSEG_HOT_DATA; type--) | |
741 | if (v_ops->get_victim(sbi, &(curseg)->next_segno, | |
742 | BG_GC, type, SSR)) | |
743 | return 1; | |
744 | return 0; | |
745 | } | |
746 | ||
351df4b2 JK |
747 | /* |
748 | * flush out current segment and replace it with new segment | |
749 | * This function should be returned with success, otherwise BUG | |
750 | */ | |
751 | static void allocate_segment_by_default(struct f2fs_sb_info *sbi, | |
752 | int type, bool force) | |
753 | { | |
754 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
351df4b2 | 755 | |
7b405275 | 756 | if (force) |
351df4b2 | 757 | new_curseg(sbi, type, true); |
7b405275 | 758 | else if (type == CURSEG_WARM_NODE) |
351df4b2 | 759 | new_curseg(sbi, type, false); |
60374688 JK |
760 | else if (curseg->alloc_type == LFS && is_next_segment_free(sbi, type)) |
761 | new_curseg(sbi, type, false); | |
351df4b2 JK |
762 | else if (need_SSR(sbi) && get_ssr_segment(sbi, type)) |
763 | change_curseg(sbi, type, true); | |
764 | else | |
765 | new_curseg(sbi, type, false); | |
dcdfff65 JK |
766 | |
767 | stat_inc_seg_type(sbi, curseg); | |
351df4b2 JK |
768 | } |
769 | ||
770 | void allocate_new_segments(struct f2fs_sb_info *sbi) | |
771 | { | |
772 | struct curseg_info *curseg; | |
773 | unsigned int old_curseg; | |
774 | int i; | |
775 | ||
776 | for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { | |
777 | curseg = CURSEG_I(sbi, i); | |
778 | old_curseg = curseg->segno; | |
779 | SIT_I(sbi)->s_ops->allocate_segment(sbi, i, true); | |
780 | locate_dirty_segment(sbi, old_curseg); | |
781 | } | |
782 | } | |
783 | ||
784 | static const struct segment_allocation default_salloc_ops = { | |
785 | .allocate_segment = allocate_segment_by_default, | |
786 | }; | |
787 | ||
788 | static void f2fs_end_io_write(struct bio *bio, int err) | |
789 | { | |
790 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | |
791 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; | |
792 | struct bio_private *p = bio->bi_private; | |
793 | ||
794 | do { | |
795 | struct page *page = bvec->bv_page; | |
796 | ||
797 | if (--bvec >= bio->bi_io_vec) | |
798 | prefetchw(&bvec->bv_page->flags); | |
799 | if (!uptodate) { | |
800 | SetPageError(page); | |
801 | if (page->mapping) | |
802 | set_bit(AS_EIO, &page->mapping->flags); | |
25ca923b | 803 | set_ckpt_flags(p->sbi->ckpt, CP_ERROR_FLAG); |
577e3495 | 804 | p->sbi->sb->s_flags |= MS_RDONLY; |
351df4b2 JK |
805 | } |
806 | end_page_writeback(page); | |
807 | dec_page_count(p->sbi, F2FS_WRITEBACK); | |
808 | } while (bvec >= bio->bi_io_vec); | |
809 | ||
810 | if (p->is_sync) | |
811 | complete(p->wait); | |
e2340887 | 812 | |
fb51b5ef CL |
813 | if (!get_pages(p->sbi, F2FS_WRITEBACK) && |
814 | !list_empty(&p->sbi->cp_wait.task_list)) | |
815 | wake_up(&p->sbi->cp_wait); | |
e2340887 | 816 | |
351df4b2 JK |
817 | kfree(p); |
818 | bio_put(bio); | |
819 | } | |
820 | ||
3cd8a239 | 821 | struct bio *f2fs_bio_alloc(struct block_device *bdev, int npages) |
351df4b2 JK |
822 | { |
823 | struct bio *bio; | |
3cd8a239 JK |
824 | |
825 | /* No failure on bio allocation */ | |
826 | bio = bio_alloc(GFP_NOIO, npages); | |
827 | bio->bi_bdev = bdev; | |
d8207f69 GZ |
828 | bio->bi_private = NULL; |
829 | ||
351df4b2 JK |
830 | return bio; |
831 | } | |
832 | ||
833 | static void do_submit_bio(struct f2fs_sb_info *sbi, | |
834 | enum page_type type, bool sync) | |
835 | { | |
836 | int rw = sync ? WRITE_SYNC : WRITE; | |
837 | enum page_type btype = type > META ? META : type; | |
838 | ||
839 | if (type >= META_FLUSH) | |
840 | rw = WRITE_FLUSH_FUA; | |
841 | ||
8680441c NJ |
842 | if (btype == META) |
843 | rw |= REQ_META; | |
844 | ||
351df4b2 JK |
845 | if (sbi->bio[btype]) { |
846 | struct bio_private *p = sbi->bio[btype]->bi_private; | |
847 | p->sbi = sbi; | |
848 | sbi->bio[btype]->bi_end_io = f2fs_end_io_write; | |
6ec178da NJ |
849 | |
850 | trace_f2fs_do_submit_bio(sbi->sb, btype, sync, sbi->bio[btype]); | |
851 | ||
351df4b2 JK |
852 | if (type == META_FLUSH) { |
853 | DECLARE_COMPLETION_ONSTACK(wait); | |
854 | p->is_sync = true; | |
855 | p->wait = &wait; | |
856 | submit_bio(rw, sbi->bio[btype]); | |
857 | wait_for_completion(&wait); | |
858 | } else { | |
859 | p->is_sync = false; | |
860 | submit_bio(rw, sbi->bio[btype]); | |
861 | } | |
862 | sbi->bio[btype] = NULL; | |
863 | } | |
864 | } | |
865 | ||
866 | void f2fs_submit_bio(struct f2fs_sb_info *sbi, enum page_type type, bool sync) | |
867 | { | |
868 | down_write(&sbi->bio_sem); | |
869 | do_submit_bio(sbi, type, sync); | |
870 | up_write(&sbi->bio_sem); | |
871 | } | |
872 | ||
873 | static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page, | |
874 | block_t blk_addr, enum page_type type) | |
875 | { | |
876 | struct block_device *bdev = sbi->sb->s_bdev; | |
cc7b1bb1 | 877 | int bio_blocks; |
351df4b2 JK |
878 | |
879 | verify_block_addr(sbi, blk_addr); | |
880 | ||
881 | down_write(&sbi->bio_sem); | |
882 | ||
883 | inc_page_count(sbi, F2FS_WRITEBACK); | |
884 | ||
885 | if (sbi->bio[type] && sbi->last_block_in_bio[type] != blk_addr - 1) | |
886 | do_submit_bio(sbi, type, false); | |
887 | alloc_new: | |
3cd8a239 | 888 | if (sbi->bio[type] == NULL) { |
d8207f69 GZ |
889 | struct bio_private *priv; |
890 | retry: | |
891 | priv = kmalloc(sizeof(struct bio_private), GFP_NOFS); | |
892 | if (!priv) { | |
893 | cond_resched(); | |
894 | goto retry; | |
895 | } | |
896 | ||
cc7b1bb1 CY |
897 | bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi)); |
898 | sbi->bio[type] = f2fs_bio_alloc(bdev, bio_blocks); | |
3cd8a239 | 899 | sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); |
d8207f69 | 900 | sbi->bio[type]->bi_private = priv; |
3cd8a239 JK |
901 | /* |
902 | * The end_io will be assigned at the sumbission phase. | |
903 | * Until then, let bio_add_page() merge consecutive IOs as much | |
904 | * as possible. | |
905 | */ | |
906 | } | |
351df4b2 JK |
907 | |
908 | if (bio_add_page(sbi->bio[type], page, PAGE_CACHE_SIZE, 0) < | |
909 | PAGE_CACHE_SIZE) { | |
910 | do_submit_bio(sbi, type, false); | |
911 | goto alloc_new; | |
912 | } | |
913 | ||
914 | sbi->last_block_in_bio[type] = blk_addr; | |
915 | ||
916 | up_write(&sbi->bio_sem); | |
6ec178da | 917 | trace_f2fs_submit_write_page(page, blk_addr, type); |
351df4b2 JK |
918 | } |
919 | ||
a569469e JX |
920 | void f2fs_wait_on_page_writeback(struct page *page, |
921 | enum page_type type, bool sync) | |
922 | { | |
923 | struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb); | |
924 | if (PageWriteback(page)) { | |
925 | f2fs_submit_bio(sbi, type, sync); | |
926 | wait_on_page_writeback(page); | |
927 | } | |
928 | } | |
929 | ||
351df4b2 JK |
930 | static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type) |
931 | { | |
932 | struct curseg_info *curseg = CURSEG_I(sbi, type); | |
933 | if (curseg->next_blkoff < sbi->blocks_per_seg) | |
934 | return true; | |
935 | return false; | |
936 | } | |
937 | ||
938 | static int __get_segment_type_2(struct page *page, enum page_type p_type) | |
939 | { | |
940 | if (p_type == DATA) | |
941 | return CURSEG_HOT_DATA; | |
942 | else | |
943 | return CURSEG_HOT_NODE; | |
944 | } | |
945 | ||
946 | static int __get_segment_type_4(struct page *page, enum page_type p_type) | |
947 | { | |
948 | if (p_type == DATA) { | |
949 | struct inode *inode = page->mapping->host; | |
950 | ||
951 | if (S_ISDIR(inode->i_mode)) | |
952 | return CURSEG_HOT_DATA; | |
953 | else | |
954 | return CURSEG_COLD_DATA; | |
955 | } else { | |
956 | if (IS_DNODE(page) && !is_cold_node(page)) | |
957 | return CURSEG_HOT_NODE; | |
958 | else | |
959 | return CURSEG_COLD_NODE; | |
960 | } | |
961 | } | |
962 | ||
963 | static int __get_segment_type_6(struct page *page, enum page_type p_type) | |
964 | { | |
965 | if (p_type == DATA) { | |
966 | struct inode *inode = page->mapping->host; | |
967 | ||
968 | if (S_ISDIR(inode->i_mode)) | |
969 | return CURSEG_HOT_DATA; | |
354a3399 | 970 | else if (is_cold_data(page) || file_is_cold(inode)) |
351df4b2 JK |
971 | return CURSEG_COLD_DATA; |
972 | else | |
973 | return CURSEG_WARM_DATA; | |
974 | } else { | |
975 | if (IS_DNODE(page)) | |
976 | return is_cold_node(page) ? CURSEG_WARM_NODE : | |
977 | CURSEG_HOT_NODE; | |
978 | else | |
979 | return CURSEG_COLD_NODE; | |
980 | } | |
981 | } | |
982 | ||
983 | static int __get_segment_type(struct page *page, enum page_type p_type) | |
984 | { | |
985 | struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb); | |
986 | switch (sbi->active_logs) { | |
987 | case 2: | |
988 | return __get_segment_type_2(page, p_type); | |
989 | case 4: | |
990 | return __get_segment_type_4(page, p_type); | |
351df4b2 | 991 | } |
12a67146 | 992 | /* NR_CURSEG_TYPE(6) logs by default */ |
5d56b671 | 993 | f2fs_bug_on(sbi->active_logs != NR_CURSEG_TYPE); |
12a67146 | 994 | return __get_segment_type_6(page, p_type); |
351df4b2 JK |
995 | } |
996 | ||
997 | static void do_write_page(struct f2fs_sb_info *sbi, struct page *page, | |
998 | block_t old_blkaddr, block_t *new_blkaddr, | |
999 | struct f2fs_summary *sum, enum page_type p_type) | |
1000 | { | |
1001 | struct sit_info *sit_i = SIT_I(sbi); | |
1002 | struct curseg_info *curseg; | |
1003 | unsigned int old_cursegno; | |
1004 | int type; | |
1005 | ||
1006 | type = __get_segment_type(page, p_type); | |
1007 | curseg = CURSEG_I(sbi, type); | |
1008 | ||
1009 | mutex_lock(&curseg->curseg_mutex); | |
1010 | ||
1011 | *new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); | |
1012 | old_cursegno = curseg->segno; | |
1013 | ||
1014 | /* | |
1015 | * __add_sum_entry should be resided under the curseg_mutex | |
1016 | * because, this function updates a summary entry in the | |
1017 | * current summary block. | |
1018 | */ | |
e79efe3b | 1019 | __add_sum_entry(sbi, type, sum); |
351df4b2 JK |
1020 | |
1021 | mutex_lock(&sit_i->sentry_lock); | |
1022 | __refresh_next_blkoff(sbi, curseg); | |
dcdfff65 JK |
1023 | |
1024 | stat_inc_block_count(sbi, curseg); | |
351df4b2 JK |
1025 | |
1026 | /* | |
1027 | * SIT information should be updated before segment allocation, | |
1028 | * since SSR needs latest valid block information. | |
1029 | */ | |
1030 | refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr); | |
1031 | ||
1032 | if (!__has_curseg_space(sbi, type)) | |
1033 | sit_i->s_ops->allocate_segment(sbi, type, false); | |
1034 | ||
1035 | locate_dirty_segment(sbi, old_cursegno); | |
1036 | locate_dirty_segment(sbi, GET_SEGNO(sbi, old_blkaddr)); | |
1037 | mutex_unlock(&sit_i->sentry_lock); | |
1038 | ||
1039 | if (p_type == NODE) | |
1040 | fill_node_footer_blkaddr(page, NEXT_FREE_BLKADDR(sbi, curseg)); | |
1041 | ||
1042 | /* writeout dirty page into bdev */ | |
1043 | submit_write_page(sbi, page, *new_blkaddr, p_type); | |
1044 | ||
1045 | mutex_unlock(&curseg->curseg_mutex); | |
1046 | } | |
1047 | ||
577e3495 | 1048 | void write_meta_page(struct f2fs_sb_info *sbi, struct page *page) |
351df4b2 | 1049 | { |
351df4b2 JK |
1050 | set_page_writeback(page); |
1051 | submit_write_page(sbi, page, page->index, META); | |
351df4b2 JK |
1052 | } |
1053 | ||
1054 | void write_node_page(struct f2fs_sb_info *sbi, struct page *page, | |
1055 | unsigned int nid, block_t old_blkaddr, block_t *new_blkaddr) | |
1056 | { | |
1057 | struct f2fs_summary sum; | |
1058 | set_summary(&sum, nid, 0, 0); | |
1059 | do_write_page(sbi, page, old_blkaddr, new_blkaddr, &sum, NODE); | |
1060 | } | |
1061 | ||
1062 | void write_data_page(struct inode *inode, struct page *page, | |
1063 | struct dnode_of_data *dn, block_t old_blkaddr, | |
1064 | block_t *new_blkaddr) | |
1065 | { | |
1066 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | |
1067 | struct f2fs_summary sum; | |
1068 | struct node_info ni; | |
1069 | ||
5d56b671 | 1070 | f2fs_bug_on(old_blkaddr == NULL_ADDR); |
351df4b2 JK |
1071 | get_node_info(sbi, dn->nid, &ni); |
1072 | set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); | |
1073 | ||
1074 | do_write_page(sbi, page, old_blkaddr, | |
1075 | new_blkaddr, &sum, DATA); | |
1076 | } | |
1077 | ||
1078 | void rewrite_data_page(struct f2fs_sb_info *sbi, struct page *page, | |
1079 | block_t old_blk_addr) | |
1080 | { | |
1081 | submit_write_page(sbi, page, old_blk_addr, DATA); | |
1082 | } | |
1083 | ||
1084 | void recover_data_page(struct f2fs_sb_info *sbi, | |
1085 | struct page *page, struct f2fs_summary *sum, | |
1086 | block_t old_blkaddr, block_t new_blkaddr) | |
1087 | { | |
1088 | struct sit_info *sit_i = SIT_I(sbi); | |
1089 | struct curseg_info *curseg; | |
1090 | unsigned int segno, old_cursegno; | |
1091 | struct seg_entry *se; | |
1092 | int type; | |
1093 | ||
1094 | segno = GET_SEGNO(sbi, new_blkaddr); | |
1095 | se = get_seg_entry(sbi, segno); | |
1096 | type = se->type; | |
1097 | ||
1098 | if (se->valid_blocks == 0 && !IS_CURSEG(sbi, segno)) { | |
1099 | if (old_blkaddr == NULL_ADDR) | |
1100 | type = CURSEG_COLD_DATA; | |
1101 | else | |
1102 | type = CURSEG_WARM_DATA; | |
1103 | } | |
1104 | curseg = CURSEG_I(sbi, type); | |
1105 | ||
1106 | mutex_lock(&curseg->curseg_mutex); | |
1107 | mutex_lock(&sit_i->sentry_lock); | |
1108 | ||
1109 | old_cursegno = curseg->segno; | |
1110 | ||
1111 | /* change the current segment */ | |
1112 | if (segno != curseg->segno) { | |
1113 | curseg->next_segno = segno; | |
1114 | change_curseg(sbi, type, true); | |
1115 | } | |
1116 | ||
1117 | curseg->next_blkoff = GET_SEGOFF_FROM_SEG0(sbi, new_blkaddr) & | |
1118 | (sbi->blocks_per_seg - 1); | |
e79efe3b | 1119 | __add_sum_entry(sbi, type, sum); |
351df4b2 JK |
1120 | |
1121 | refresh_sit_entry(sbi, old_blkaddr, new_blkaddr); | |
1122 | ||
1123 | locate_dirty_segment(sbi, old_cursegno); | |
1124 | locate_dirty_segment(sbi, GET_SEGNO(sbi, old_blkaddr)); | |
1125 | ||
1126 | mutex_unlock(&sit_i->sentry_lock); | |
1127 | mutex_unlock(&curseg->curseg_mutex); | |
1128 | } | |
1129 | ||
1130 | void rewrite_node_page(struct f2fs_sb_info *sbi, | |
1131 | struct page *page, struct f2fs_summary *sum, | |
1132 | block_t old_blkaddr, block_t new_blkaddr) | |
1133 | { | |
1134 | struct sit_info *sit_i = SIT_I(sbi); | |
1135 | int type = CURSEG_WARM_NODE; | |
1136 | struct curseg_info *curseg; | |
1137 | unsigned int segno, old_cursegno; | |
1138 | block_t next_blkaddr = next_blkaddr_of_node(page); | |
1139 | unsigned int next_segno = GET_SEGNO(sbi, next_blkaddr); | |
1140 | ||
1141 | curseg = CURSEG_I(sbi, type); | |
1142 | ||
1143 | mutex_lock(&curseg->curseg_mutex); | |
1144 | mutex_lock(&sit_i->sentry_lock); | |
1145 | ||
1146 | segno = GET_SEGNO(sbi, new_blkaddr); | |
1147 | old_cursegno = curseg->segno; | |
1148 | ||
1149 | /* change the current segment */ | |
1150 | if (segno != curseg->segno) { | |
1151 | curseg->next_segno = segno; | |
1152 | change_curseg(sbi, type, true); | |
1153 | } | |
1154 | curseg->next_blkoff = GET_SEGOFF_FROM_SEG0(sbi, new_blkaddr) & | |
1155 | (sbi->blocks_per_seg - 1); | |
e79efe3b | 1156 | __add_sum_entry(sbi, type, sum); |
351df4b2 JK |
1157 | |
1158 | /* change the current log to the next block addr in advance */ | |
1159 | if (next_segno != segno) { | |
1160 | curseg->next_segno = next_segno; | |
1161 | change_curseg(sbi, type, true); | |
1162 | } | |
1163 | curseg->next_blkoff = GET_SEGOFF_FROM_SEG0(sbi, next_blkaddr) & | |
1164 | (sbi->blocks_per_seg - 1); | |
1165 | ||
1166 | /* rewrite node page */ | |
1167 | set_page_writeback(page); | |
1168 | submit_write_page(sbi, page, new_blkaddr, NODE); | |
1169 | f2fs_submit_bio(sbi, NODE, true); | |
1170 | refresh_sit_entry(sbi, old_blkaddr, new_blkaddr); | |
1171 | ||
1172 | locate_dirty_segment(sbi, old_cursegno); | |
1173 | locate_dirty_segment(sbi, GET_SEGNO(sbi, old_blkaddr)); | |
1174 | ||
1175 | mutex_unlock(&sit_i->sentry_lock); | |
1176 | mutex_unlock(&curseg->curseg_mutex); | |
1177 | } | |
1178 | ||
1179 | static int read_compacted_summaries(struct f2fs_sb_info *sbi) | |
1180 | { | |
1181 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1182 | struct curseg_info *seg_i; | |
1183 | unsigned char *kaddr; | |
1184 | struct page *page; | |
1185 | block_t start; | |
1186 | int i, j, offset; | |
1187 | ||
1188 | start = start_sum_block(sbi); | |
1189 | ||
1190 | page = get_meta_page(sbi, start++); | |
1191 | kaddr = (unsigned char *)page_address(page); | |
1192 | ||
1193 | /* Step 1: restore nat cache */ | |
1194 | seg_i = CURSEG_I(sbi, CURSEG_HOT_DATA); | |
1195 | memcpy(&seg_i->sum_blk->n_nats, kaddr, SUM_JOURNAL_SIZE); | |
1196 | ||
1197 | /* Step 2: restore sit cache */ | |
1198 | seg_i = CURSEG_I(sbi, CURSEG_COLD_DATA); | |
1199 | memcpy(&seg_i->sum_blk->n_sits, kaddr + SUM_JOURNAL_SIZE, | |
1200 | SUM_JOURNAL_SIZE); | |
1201 | offset = 2 * SUM_JOURNAL_SIZE; | |
1202 | ||
1203 | /* Step 3: restore summary entries */ | |
1204 | for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { | |
1205 | unsigned short blk_off; | |
1206 | unsigned int segno; | |
1207 | ||
1208 | seg_i = CURSEG_I(sbi, i); | |
1209 | segno = le32_to_cpu(ckpt->cur_data_segno[i]); | |
1210 | blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); | |
1211 | seg_i->next_segno = segno; | |
1212 | reset_curseg(sbi, i, 0); | |
1213 | seg_i->alloc_type = ckpt->alloc_type[i]; | |
1214 | seg_i->next_blkoff = blk_off; | |
1215 | ||
1216 | if (seg_i->alloc_type == SSR) | |
1217 | blk_off = sbi->blocks_per_seg; | |
1218 | ||
1219 | for (j = 0; j < blk_off; j++) { | |
1220 | struct f2fs_summary *s; | |
1221 | s = (struct f2fs_summary *)(kaddr + offset); | |
1222 | seg_i->sum_blk->entries[j] = *s; | |
1223 | offset += SUMMARY_SIZE; | |
1224 | if (offset + SUMMARY_SIZE <= PAGE_CACHE_SIZE - | |
1225 | SUM_FOOTER_SIZE) | |
1226 | continue; | |
1227 | ||
1228 | f2fs_put_page(page, 1); | |
1229 | page = NULL; | |
1230 | ||
1231 | page = get_meta_page(sbi, start++); | |
1232 | kaddr = (unsigned char *)page_address(page); | |
1233 | offset = 0; | |
1234 | } | |
1235 | } | |
1236 | f2fs_put_page(page, 1); | |
1237 | return 0; | |
1238 | } | |
1239 | ||
1240 | static int read_normal_summaries(struct f2fs_sb_info *sbi, int type) | |
1241 | { | |
1242 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1243 | struct f2fs_summary_block *sum; | |
1244 | struct curseg_info *curseg; | |
1245 | struct page *new; | |
1246 | unsigned short blk_off; | |
1247 | unsigned int segno = 0; | |
1248 | block_t blk_addr = 0; | |
1249 | ||
1250 | /* get segment number and block addr */ | |
1251 | if (IS_DATASEG(type)) { | |
1252 | segno = le32_to_cpu(ckpt->cur_data_segno[type]); | |
1253 | blk_off = le16_to_cpu(ckpt->cur_data_blkoff[type - | |
1254 | CURSEG_HOT_DATA]); | |
25ca923b | 1255 | if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG)) |
351df4b2 JK |
1256 | blk_addr = sum_blk_addr(sbi, NR_CURSEG_TYPE, type); |
1257 | else | |
1258 | blk_addr = sum_blk_addr(sbi, NR_CURSEG_DATA_TYPE, type); | |
1259 | } else { | |
1260 | segno = le32_to_cpu(ckpt->cur_node_segno[type - | |
1261 | CURSEG_HOT_NODE]); | |
1262 | blk_off = le16_to_cpu(ckpt->cur_node_blkoff[type - | |
1263 | CURSEG_HOT_NODE]); | |
25ca923b | 1264 | if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG)) |
351df4b2 JK |
1265 | blk_addr = sum_blk_addr(sbi, NR_CURSEG_NODE_TYPE, |
1266 | type - CURSEG_HOT_NODE); | |
1267 | else | |
1268 | blk_addr = GET_SUM_BLOCK(sbi, segno); | |
1269 | } | |
1270 | ||
1271 | new = get_meta_page(sbi, blk_addr); | |
1272 | sum = (struct f2fs_summary_block *)page_address(new); | |
1273 | ||
1274 | if (IS_NODESEG(type)) { | |
25ca923b | 1275 | if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG)) { |
351df4b2 JK |
1276 | struct f2fs_summary *ns = &sum->entries[0]; |
1277 | int i; | |
1278 | for (i = 0; i < sbi->blocks_per_seg; i++, ns++) { | |
1279 | ns->version = 0; | |
1280 | ns->ofs_in_node = 0; | |
1281 | } | |
1282 | } else { | |
1283 | if (restore_node_summary(sbi, segno, sum)) { | |
1284 | f2fs_put_page(new, 1); | |
1285 | return -EINVAL; | |
1286 | } | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | /* set uncompleted segment to curseg */ | |
1291 | curseg = CURSEG_I(sbi, type); | |
1292 | mutex_lock(&curseg->curseg_mutex); | |
1293 | memcpy(curseg->sum_blk, sum, PAGE_CACHE_SIZE); | |
1294 | curseg->next_segno = segno; | |
1295 | reset_curseg(sbi, type, 0); | |
1296 | curseg->alloc_type = ckpt->alloc_type[type]; | |
1297 | curseg->next_blkoff = blk_off; | |
1298 | mutex_unlock(&curseg->curseg_mutex); | |
1299 | f2fs_put_page(new, 1); | |
1300 | return 0; | |
1301 | } | |
1302 | ||
1303 | static int restore_curseg_summaries(struct f2fs_sb_info *sbi) | |
1304 | { | |
1305 | int type = CURSEG_HOT_DATA; | |
1306 | ||
25ca923b | 1307 | if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_COMPACT_SUM_FLAG)) { |
351df4b2 JK |
1308 | /* restore for compacted data summary */ |
1309 | if (read_compacted_summaries(sbi)) | |
1310 | return -EINVAL; | |
1311 | type = CURSEG_HOT_NODE; | |
1312 | } | |
1313 | ||
1314 | for (; type <= CURSEG_COLD_NODE; type++) | |
1315 | if (read_normal_summaries(sbi, type)) | |
1316 | return -EINVAL; | |
1317 | return 0; | |
1318 | } | |
1319 | ||
1320 | static void write_compacted_summaries(struct f2fs_sb_info *sbi, block_t blkaddr) | |
1321 | { | |
1322 | struct page *page; | |
1323 | unsigned char *kaddr; | |
1324 | struct f2fs_summary *summary; | |
1325 | struct curseg_info *seg_i; | |
1326 | int written_size = 0; | |
1327 | int i, j; | |
1328 | ||
1329 | page = grab_meta_page(sbi, blkaddr++); | |
1330 | kaddr = (unsigned char *)page_address(page); | |
1331 | ||
1332 | /* Step 1: write nat cache */ | |
1333 | seg_i = CURSEG_I(sbi, CURSEG_HOT_DATA); | |
1334 | memcpy(kaddr, &seg_i->sum_blk->n_nats, SUM_JOURNAL_SIZE); | |
1335 | written_size += SUM_JOURNAL_SIZE; | |
1336 | ||
1337 | /* Step 2: write sit cache */ | |
1338 | seg_i = CURSEG_I(sbi, CURSEG_COLD_DATA); | |
1339 | memcpy(kaddr + written_size, &seg_i->sum_blk->n_sits, | |
1340 | SUM_JOURNAL_SIZE); | |
1341 | written_size += SUM_JOURNAL_SIZE; | |
1342 | ||
351df4b2 JK |
1343 | /* Step 3: write summary entries */ |
1344 | for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { | |
1345 | unsigned short blkoff; | |
1346 | seg_i = CURSEG_I(sbi, i); | |
1347 | if (sbi->ckpt->alloc_type[i] == SSR) | |
1348 | blkoff = sbi->blocks_per_seg; | |
1349 | else | |
1350 | blkoff = curseg_blkoff(sbi, i); | |
1351 | ||
1352 | for (j = 0; j < blkoff; j++) { | |
1353 | if (!page) { | |
1354 | page = grab_meta_page(sbi, blkaddr++); | |
1355 | kaddr = (unsigned char *)page_address(page); | |
1356 | written_size = 0; | |
1357 | } | |
1358 | summary = (struct f2fs_summary *)(kaddr + written_size); | |
1359 | *summary = seg_i->sum_blk->entries[j]; | |
1360 | written_size += SUMMARY_SIZE; | |
351df4b2 JK |
1361 | |
1362 | if (written_size + SUMMARY_SIZE <= PAGE_CACHE_SIZE - | |
1363 | SUM_FOOTER_SIZE) | |
1364 | continue; | |
1365 | ||
e8d61a74 | 1366 | set_page_dirty(page); |
351df4b2 JK |
1367 | f2fs_put_page(page, 1); |
1368 | page = NULL; | |
1369 | } | |
1370 | } | |
e8d61a74 CY |
1371 | if (page) { |
1372 | set_page_dirty(page); | |
351df4b2 | 1373 | f2fs_put_page(page, 1); |
e8d61a74 | 1374 | } |
351df4b2 JK |
1375 | } |
1376 | ||
1377 | static void write_normal_summaries(struct f2fs_sb_info *sbi, | |
1378 | block_t blkaddr, int type) | |
1379 | { | |
1380 | int i, end; | |
1381 | if (IS_DATASEG(type)) | |
1382 | end = type + NR_CURSEG_DATA_TYPE; | |
1383 | else | |
1384 | end = type + NR_CURSEG_NODE_TYPE; | |
1385 | ||
1386 | for (i = type; i < end; i++) { | |
1387 | struct curseg_info *sum = CURSEG_I(sbi, i); | |
1388 | mutex_lock(&sum->curseg_mutex); | |
1389 | write_sum_page(sbi, sum->sum_blk, blkaddr + (i - type)); | |
1390 | mutex_unlock(&sum->curseg_mutex); | |
1391 | } | |
1392 | } | |
1393 | ||
1394 | void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk) | |
1395 | { | |
25ca923b | 1396 | if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_COMPACT_SUM_FLAG)) |
351df4b2 JK |
1397 | write_compacted_summaries(sbi, start_blk); |
1398 | else | |
1399 | write_normal_summaries(sbi, start_blk, CURSEG_HOT_DATA); | |
1400 | } | |
1401 | ||
1402 | void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk) | |
1403 | { | |
25ca923b | 1404 | if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) |
351df4b2 | 1405 | write_normal_summaries(sbi, start_blk, CURSEG_HOT_NODE); |
351df4b2 JK |
1406 | } |
1407 | ||
1408 | int lookup_journal_in_cursum(struct f2fs_summary_block *sum, int type, | |
1409 | unsigned int val, int alloc) | |
1410 | { | |
1411 | int i; | |
1412 | ||
1413 | if (type == NAT_JOURNAL) { | |
1414 | for (i = 0; i < nats_in_cursum(sum); i++) { | |
1415 | if (le32_to_cpu(nid_in_journal(sum, i)) == val) | |
1416 | return i; | |
1417 | } | |
1418 | if (alloc && nats_in_cursum(sum) < NAT_JOURNAL_ENTRIES) | |
1419 | return update_nats_in_cursum(sum, 1); | |
1420 | } else if (type == SIT_JOURNAL) { | |
1421 | for (i = 0; i < sits_in_cursum(sum); i++) | |
1422 | if (le32_to_cpu(segno_in_journal(sum, i)) == val) | |
1423 | return i; | |
1424 | if (alloc && sits_in_cursum(sum) < SIT_JOURNAL_ENTRIES) | |
1425 | return update_sits_in_cursum(sum, 1); | |
1426 | } | |
1427 | return -1; | |
1428 | } | |
1429 | ||
1430 | static struct page *get_current_sit_page(struct f2fs_sb_info *sbi, | |
1431 | unsigned int segno) | |
1432 | { | |
1433 | struct sit_info *sit_i = SIT_I(sbi); | |
1434 | unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno); | |
1435 | block_t blk_addr = sit_i->sit_base_addr + offset; | |
1436 | ||
1437 | check_seg_range(sbi, segno); | |
1438 | ||
1439 | /* calculate sit block address */ | |
1440 | if (f2fs_test_bit(offset, sit_i->sit_bitmap)) | |
1441 | blk_addr += sit_i->sit_blocks; | |
1442 | ||
1443 | return get_meta_page(sbi, blk_addr); | |
1444 | } | |
1445 | ||
1446 | static struct page *get_next_sit_page(struct f2fs_sb_info *sbi, | |
1447 | unsigned int start) | |
1448 | { | |
1449 | struct sit_info *sit_i = SIT_I(sbi); | |
1450 | struct page *src_page, *dst_page; | |
1451 | pgoff_t src_off, dst_off; | |
1452 | void *src_addr, *dst_addr; | |
1453 | ||
1454 | src_off = current_sit_addr(sbi, start); | |
1455 | dst_off = next_sit_addr(sbi, src_off); | |
1456 | ||
1457 | /* get current sit block page without lock */ | |
1458 | src_page = get_meta_page(sbi, src_off); | |
1459 | dst_page = grab_meta_page(sbi, dst_off); | |
5d56b671 | 1460 | f2fs_bug_on(PageDirty(src_page)); |
351df4b2 JK |
1461 | |
1462 | src_addr = page_address(src_page); | |
1463 | dst_addr = page_address(dst_page); | |
1464 | memcpy(dst_addr, src_addr, PAGE_CACHE_SIZE); | |
1465 | ||
1466 | set_page_dirty(dst_page); | |
1467 | f2fs_put_page(src_page, 1); | |
1468 | ||
1469 | set_to_next_sit(sit_i, start); | |
1470 | ||
1471 | return dst_page; | |
1472 | } | |
1473 | ||
1474 | static bool flush_sits_in_journal(struct f2fs_sb_info *sbi) | |
1475 | { | |
1476 | struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); | |
1477 | struct f2fs_summary_block *sum = curseg->sum_blk; | |
1478 | int i; | |
1479 | ||
1480 | /* | |
1481 | * If the journal area in the current summary is full of sit entries, | |
1482 | * all the sit entries will be flushed. Otherwise the sit entries | |
1483 | * are not able to replace with newly hot sit entries. | |
1484 | */ | |
1485 | if (sits_in_cursum(sum) >= SIT_JOURNAL_ENTRIES) { | |
1486 | for (i = sits_in_cursum(sum) - 1; i >= 0; i--) { | |
1487 | unsigned int segno; | |
1488 | segno = le32_to_cpu(segno_in_journal(sum, i)); | |
1489 | __mark_sit_entry_dirty(sbi, segno); | |
1490 | } | |
1491 | update_sits_in_cursum(sum, -sits_in_cursum(sum)); | |
cffbfa66 | 1492 | return true; |
351df4b2 | 1493 | } |
cffbfa66 | 1494 | return false; |
351df4b2 JK |
1495 | } |
1496 | ||
0a8165d7 | 1497 | /* |
351df4b2 JK |
1498 | * CP calls this function, which flushes SIT entries including sit_journal, |
1499 | * and moves prefree segs to free segs. | |
1500 | */ | |
1501 | void flush_sit_entries(struct f2fs_sb_info *sbi) | |
1502 | { | |
1503 | struct sit_info *sit_i = SIT_I(sbi); | |
1504 | unsigned long *bitmap = sit_i->dirty_sentries_bitmap; | |
1505 | struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); | |
1506 | struct f2fs_summary_block *sum = curseg->sum_blk; | |
1507 | unsigned long nsegs = TOTAL_SEGS(sbi); | |
1508 | struct page *page = NULL; | |
1509 | struct f2fs_sit_block *raw_sit = NULL; | |
1510 | unsigned int start = 0, end = 0; | |
1511 | unsigned int segno = -1; | |
1512 | bool flushed; | |
1513 | ||
1514 | mutex_lock(&curseg->curseg_mutex); | |
1515 | mutex_lock(&sit_i->sentry_lock); | |
1516 | ||
1517 | /* | |
1518 | * "flushed" indicates whether sit entries in journal are flushed | |
1519 | * to the SIT area or not. | |
1520 | */ | |
1521 | flushed = flush_sits_in_journal(sbi); | |
1522 | ||
1523 | while ((segno = find_next_bit(bitmap, nsegs, segno + 1)) < nsegs) { | |
1524 | struct seg_entry *se = get_seg_entry(sbi, segno); | |
1525 | int sit_offset, offset; | |
1526 | ||
1527 | sit_offset = SIT_ENTRY_OFFSET(sit_i, segno); | |
1528 | ||
b2955550 JK |
1529 | /* add discard candidates */ |
1530 | if (SM_I(sbi)->nr_discards < SM_I(sbi)->max_discards) | |
1531 | add_discard_addrs(sbi, segno, se); | |
1532 | ||
351df4b2 JK |
1533 | if (flushed) |
1534 | goto to_sit_page; | |
1535 | ||
1536 | offset = lookup_journal_in_cursum(sum, SIT_JOURNAL, segno, 1); | |
1537 | if (offset >= 0) { | |
1538 | segno_in_journal(sum, offset) = cpu_to_le32(segno); | |
1539 | seg_info_to_raw_sit(se, &sit_in_journal(sum, offset)); | |
1540 | goto flush_done; | |
1541 | } | |
1542 | to_sit_page: | |
1543 | if (!page || (start > segno) || (segno > end)) { | |
1544 | if (page) { | |
1545 | f2fs_put_page(page, 1); | |
1546 | page = NULL; | |
1547 | } | |
1548 | ||
1549 | start = START_SEGNO(sit_i, segno); | |
1550 | end = start + SIT_ENTRY_PER_BLOCK - 1; | |
1551 | ||
1552 | /* read sit block that will be updated */ | |
1553 | page = get_next_sit_page(sbi, start); | |
1554 | raw_sit = page_address(page); | |
1555 | } | |
1556 | ||
1557 | /* udpate entry in SIT block */ | |
1558 | seg_info_to_raw_sit(se, &raw_sit->entries[sit_offset]); | |
1559 | flush_done: | |
1560 | __clear_bit(segno, bitmap); | |
1561 | sit_i->dirty_sentries--; | |
1562 | } | |
1563 | mutex_unlock(&sit_i->sentry_lock); | |
1564 | mutex_unlock(&curseg->curseg_mutex); | |
1565 | ||
1566 | /* writeout last modified SIT block */ | |
1567 | f2fs_put_page(page, 1); | |
1568 | ||
1569 | set_prefree_as_free_segments(sbi); | |
1570 | } | |
1571 | ||
1572 | static int build_sit_info(struct f2fs_sb_info *sbi) | |
1573 | { | |
1574 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); | |
1575 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1576 | struct sit_info *sit_i; | |
1577 | unsigned int sit_segs, start; | |
1578 | char *src_bitmap, *dst_bitmap; | |
1579 | unsigned int bitmap_size; | |
1580 | ||
1581 | /* allocate memory for SIT information */ | |
1582 | sit_i = kzalloc(sizeof(struct sit_info), GFP_KERNEL); | |
1583 | if (!sit_i) | |
1584 | return -ENOMEM; | |
1585 | ||
1586 | SM_I(sbi)->sit_info = sit_i; | |
1587 | ||
1588 | sit_i->sentries = vzalloc(TOTAL_SEGS(sbi) * sizeof(struct seg_entry)); | |
1589 | if (!sit_i->sentries) | |
1590 | return -ENOMEM; | |
1591 | ||
1592 | bitmap_size = f2fs_bitmap_size(TOTAL_SEGS(sbi)); | |
1593 | sit_i->dirty_sentries_bitmap = kzalloc(bitmap_size, GFP_KERNEL); | |
1594 | if (!sit_i->dirty_sentries_bitmap) | |
1595 | return -ENOMEM; | |
1596 | ||
1597 | for (start = 0; start < TOTAL_SEGS(sbi); start++) { | |
1598 | sit_i->sentries[start].cur_valid_map | |
1599 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | |
1600 | sit_i->sentries[start].ckpt_valid_map | |
1601 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | |
1602 | if (!sit_i->sentries[start].cur_valid_map | |
1603 | || !sit_i->sentries[start].ckpt_valid_map) | |
1604 | return -ENOMEM; | |
1605 | } | |
1606 | ||
1607 | if (sbi->segs_per_sec > 1) { | |
53cf9522 | 1608 | sit_i->sec_entries = vzalloc(TOTAL_SECS(sbi) * |
351df4b2 JK |
1609 | sizeof(struct sec_entry)); |
1610 | if (!sit_i->sec_entries) | |
1611 | return -ENOMEM; | |
1612 | } | |
1613 | ||
1614 | /* get information related with SIT */ | |
1615 | sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1; | |
1616 | ||
1617 | /* setup SIT bitmap from ckeckpoint pack */ | |
1618 | bitmap_size = __bitmap_size(sbi, SIT_BITMAP); | |
1619 | src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP); | |
1620 | ||
79b5793b | 1621 | dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); |
351df4b2 JK |
1622 | if (!dst_bitmap) |
1623 | return -ENOMEM; | |
351df4b2 JK |
1624 | |
1625 | /* init SIT information */ | |
1626 | sit_i->s_ops = &default_salloc_ops; | |
1627 | ||
1628 | sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr); | |
1629 | sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; | |
1630 | sit_i->written_valid_blocks = le64_to_cpu(ckpt->valid_block_count); | |
1631 | sit_i->sit_bitmap = dst_bitmap; | |
1632 | sit_i->bitmap_size = bitmap_size; | |
1633 | sit_i->dirty_sentries = 0; | |
1634 | sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; | |
1635 | sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time); | |
1636 | sit_i->mounted_time = CURRENT_TIME_SEC.tv_sec; | |
1637 | mutex_init(&sit_i->sentry_lock); | |
1638 | return 0; | |
1639 | } | |
1640 | ||
1641 | static int build_free_segmap(struct f2fs_sb_info *sbi) | |
1642 | { | |
1643 | struct f2fs_sm_info *sm_info = SM_I(sbi); | |
1644 | struct free_segmap_info *free_i; | |
1645 | unsigned int bitmap_size, sec_bitmap_size; | |
1646 | ||
1647 | /* allocate memory for free segmap information */ | |
1648 | free_i = kzalloc(sizeof(struct free_segmap_info), GFP_KERNEL); | |
1649 | if (!free_i) | |
1650 | return -ENOMEM; | |
1651 | ||
1652 | SM_I(sbi)->free_info = free_i; | |
1653 | ||
1654 | bitmap_size = f2fs_bitmap_size(TOTAL_SEGS(sbi)); | |
1655 | free_i->free_segmap = kmalloc(bitmap_size, GFP_KERNEL); | |
1656 | if (!free_i->free_segmap) | |
1657 | return -ENOMEM; | |
1658 | ||
53cf9522 | 1659 | sec_bitmap_size = f2fs_bitmap_size(TOTAL_SECS(sbi)); |
351df4b2 JK |
1660 | free_i->free_secmap = kmalloc(sec_bitmap_size, GFP_KERNEL); |
1661 | if (!free_i->free_secmap) | |
1662 | return -ENOMEM; | |
1663 | ||
1664 | /* set all segments as dirty temporarily */ | |
1665 | memset(free_i->free_segmap, 0xff, bitmap_size); | |
1666 | memset(free_i->free_secmap, 0xff, sec_bitmap_size); | |
1667 | ||
1668 | /* init free segmap information */ | |
1669 | free_i->start_segno = | |
1670 | (unsigned int) GET_SEGNO_FROM_SEG0(sbi, sm_info->main_blkaddr); | |
1671 | free_i->free_segments = 0; | |
1672 | free_i->free_sections = 0; | |
1673 | rwlock_init(&free_i->segmap_lock); | |
1674 | return 0; | |
1675 | } | |
1676 | ||
1677 | static int build_curseg(struct f2fs_sb_info *sbi) | |
1678 | { | |
1042d60f | 1679 | struct curseg_info *array; |
351df4b2 JK |
1680 | int i; |
1681 | ||
1682 | array = kzalloc(sizeof(*array) * NR_CURSEG_TYPE, GFP_KERNEL); | |
1683 | if (!array) | |
1684 | return -ENOMEM; | |
1685 | ||
1686 | SM_I(sbi)->curseg_array = array; | |
1687 | ||
1688 | for (i = 0; i < NR_CURSEG_TYPE; i++) { | |
1689 | mutex_init(&array[i].curseg_mutex); | |
1690 | array[i].sum_blk = kzalloc(PAGE_CACHE_SIZE, GFP_KERNEL); | |
1691 | if (!array[i].sum_blk) | |
1692 | return -ENOMEM; | |
1693 | array[i].segno = NULL_SEGNO; | |
1694 | array[i].next_blkoff = 0; | |
1695 | } | |
1696 | return restore_curseg_summaries(sbi); | |
1697 | } | |
1698 | ||
1699 | static void build_sit_entries(struct f2fs_sb_info *sbi) | |
1700 | { | |
1701 | struct sit_info *sit_i = SIT_I(sbi); | |
1702 | struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); | |
1703 | struct f2fs_summary_block *sum = curseg->sum_blk; | |
1704 | unsigned int start; | |
1705 | ||
1706 | for (start = 0; start < TOTAL_SEGS(sbi); start++) { | |
1707 | struct seg_entry *se = &sit_i->sentries[start]; | |
1708 | struct f2fs_sit_block *sit_blk; | |
1709 | struct f2fs_sit_entry sit; | |
1710 | struct page *page; | |
1711 | int i; | |
1712 | ||
1713 | mutex_lock(&curseg->curseg_mutex); | |
1714 | for (i = 0; i < sits_in_cursum(sum); i++) { | |
1715 | if (le32_to_cpu(segno_in_journal(sum, i)) == start) { | |
1716 | sit = sit_in_journal(sum, i); | |
1717 | mutex_unlock(&curseg->curseg_mutex); | |
1718 | goto got_it; | |
1719 | } | |
1720 | } | |
1721 | mutex_unlock(&curseg->curseg_mutex); | |
1722 | page = get_current_sit_page(sbi, start); | |
1723 | sit_blk = (struct f2fs_sit_block *)page_address(page); | |
1724 | sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)]; | |
1725 | f2fs_put_page(page, 1); | |
1726 | got_it: | |
1727 | check_block_count(sbi, start, &sit); | |
1728 | seg_info_from_raw_sit(se, &sit); | |
1729 | if (sbi->segs_per_sec > 1) { | |
1730 | struct sec_entry *e = get_sec_entry(sbi, start); | |
1731 | e->valid_blocks += se->valid_blocks; | |
1732 | } | |
1733 | } | |
1734 | } | |
1735 | ||
1736 | static void init_free_segmap(struct f2fs_sb_info *sbi) | |
1737 | { | |
1738 | unsigned int start; | |
1739 | int type; | |
1740 | ||
1741 | for (start = 0; start < TOTAL_SEGS(sbi); start++) { | |
1742 | struct seg_entry *sentry = get_seg_entry(sbi, start); | |
1743 | if (!sentry->valid_blocks) | |
1744 | __set_free(sbi, start); | |
1745 | } | |
1746 | ||
1747 | /* set use the current segments */ | |
1748 | for (type = CURSEG_HOT_DATA; type <= CURSEG_COLD_NODE; type++) { | |
1749 | struct curseg_info *curseg_t = CURSEG_I(sbi, type); | |
1750 | __set_test_and_inuse(sbi, curseg_t->segno); | |
1751 | } | |
1752 | } | |
1753 | ||
1754 | static void init_dirty_segmap(struct f2fs_sb_info *sbi) | |
1755 | { | |
1756 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
1757 | struct free_segmap_info *free_i = FREE_I(sbi); | |
8736fbf0 | 1758 | unsigned int segno = 0, offset = 0, total_segs = TOTAL_SEGS(sbi); |
351df4b2 JK |
1759 | unsigned short valid_blocks; |
1760 | ||
8736fbf0 | 1761 | while (1) { |
351df4b2 | 1762 | /* find dirty segment based on free segmap */ |
8736fbf0 NJ |
1763 | segno = find_next_inuse(free_i, total_segs, offset); |
1764 | if (segno >= total_segs) | |
351df4b2 JK |
1765 | break; |
1766 | offset = segno + 1; | |
1767 | valid_blocks = get_valid_blocks(sbi, segno, 0); | |
1768 | if (valid_blocks >= sbi->blocks_per_seg || !valid_blocks) | |
1769 | continue; | |
1770 | mutex_lock(&dirty_i->seglist_lock); | |
1771 | __locate_dirty_segment(sbi, segno, DIRTY); | |
1772 | mutex_unlock(&dirty_i->seglist_lock); | |
1773 | } | |
1774 | } | |
1775 | ||
5ec4e49f | 1776 | static int init_victim_secmap(struct f2fs_sb_info *sbi) |
351df4b2 JK |
1777 | { |
1778 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
5ec4e49f | 1779 | unsigned int bitmap_size = f2fs_bitmap_size(TOTAL_SECS(sbi)); |
351df4b2 | 1780 | |
5ec4e49f JK |
1781 | dirty_i->victim_secmap = kzalloc(bitmap_size, GFP_KERNEL); |
1782 | if (!dirty_i->victim_secmap) | |
351df4b2 JK |
1783 | return -ENOMEM; |
1784 | return 0; | |
1785 | } | |
1786 | ||
1787 | static int build_dirty_segmap(struct f2fs_sb_info *sbi) | |
1788 | { | |
1789 | struct dirty_seglist_info *dirty_i; | |
1790 | unsigned int bitmap_size, i; | |
1791 | ||
1792 | /* allocate memory for dirty segments list information */ | |
1793 | dirty_i = kzalloc(sizeof(struct dirty_seglist_info), GFP_KERNEL); | |
1794 | if (!dirty_i) | |
1795 | return -ENOMEM; | |
1796 | ||
1797 | SM_I(sbi)->dirty_info = dirty_i; | |
1798 | mutex_init(&dirty_i->seglist_lock); | |
1799 | ||
1800 | bitmap_size = f2fs_bitmap_size(TOTAL_SEGS(sbi)); | |
1801 | ||
1802 | for (i = 0; i < NR_DIRTY_TYPE; i++) { | |
1803 | dirty_i->dirty_segmap[i] = kzalloc(bitmap_size, GFP_KERNEL); | |
351df4b2 JK |
1804 | if (!dirty_i->dirty_segmap[i]) |
1805 | return -ENOMEM; | |
1806 | } | |
1807 | ||
1808 | init_dirty_segmap(sbi); | |
5ec4e49f | 1809 | return init_victim_secmap(sbi); |
351df4b2 JK |
1810 | } |
1811 | ||
0a8165d7 | 1812 | /* |
351df4b2 JK |
1813 | * Update min, max modified time for cost-benefit GC algorithm |
1814 | */ | |
1815 | static void init_min_max_mtime(struct f2fs_sb_info *sbi) | |
1816 | { | |
1817 | struct sit_info *sit_i = SIT_I(sbi); | |
1818 | unsigned int segno; | |
1819 | ||
1820 | mutex_lock(&sit_i->sentry_lock); | |
1821 | ||
1822 | sit_i->min_mtime = LLONG_MAX; | |
1823 | ||
1824 | for (segno = 0; segno < TOTAL_SEGS(sbi); segno += sbi->segs_per_sec) { | |
1825 | unsigned int i; | |
1826 | unsigned long long mtime = 0; | |
1827 | ||
1828 | for (i = 0; i < sbi->segs_per_sec; i++) | |
1829 | mtime += get_seg_entry(sbi, segno + i)->mtime; | |
1830 | ||
1831 | mtime = div_u64(mtime, sbi->segs_per_sec); | |
1832 | ||
1833 | if (sit_i->min_mtime > mtime) | |
1834 | sit_i->min_mtime = mtime; | |
1835 | } | |
1836 | sit_i->max_mtime = get_mtime(sbi); | |
1837 | mutex_unlock(&sit_i->sentry_lock); | |
1838 | } | |
1839 | ||
1840 | int build_segment_manager(struct f2fs_sb_info *sbi) | |
1841 | { | |
1842 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); | |
1843 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1042d60f | 1844 | struct f2fs_sm_info *sm_info; |
351df4b2 JK |
1845 | int err; |
1846 | ||
1847 | sm_info = kzalloc(sizeof(struct f2fs_sm_info), GFP_KERNEL); | |
1848 | if (!sm_info) | |
1849 | return -ENOMEM; | |
1850 | ||
1851 | /* init sm info */ | |
1852 | sbi->sm_info = sm_info; | |
1853 | INIT_LIST_HEAD(&sm_info->wblist_head); | |
1854 | spin_lock_init(&sm_info->wblist_lock); | |
1855 | sm_info->seg0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr); | |
1856 | sm_info->main_blkaddr = le32_to_cpu(raw_super->main_blkaddr); | |
1857 | sm_info->segment_count = le32_to_cpu(raw_super->segment_count); | |
1858 | sm_info->reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); | |
1859 | sm_info->ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); | |
1860 | sm_info->main_segments = le32_to_cpu(raw_super->segment_count_main); | |
1861 | sm_info->ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); | |
81eb8d6e | 1862 | sm_info->rec_prefree_segments = DEF_RECLAIM_PREFREE_SEGMENTS; |
351df4b2 | 1863 | |
7fd9e544 JK |
1864 | INIT_LIST_HEAD(&sm_info->discard_list); |
1865 | sm_info->nr_discards = 0; | |
1866 | sm_info->max_discards = 0; | |
1867 | ||
351df4b2 JK |
1868 | err = build_sit_info(sbi); |
1869 | if (err) | |
1870 | return err; | |
1871 | err = build_free_segmap(sbi); | |
1872 | if (err) | |
1873 | return err; | |
1874 | err = build_curseg(sbi); | |
1875 | if (err) | |
1876 | return err; | |
1877 | ||
1878 | /* reinit free segmap based on SIT */ | |
1879 | build_sit_entries(sbi); | |
1880 | ||
1881 | init_free_segmap(sbi); | |
1882 | err = build_dirty_segmap(sbi); | |
1883 | if (err) | |
1884 | return err; | |
1885 | ||
1886 | init_min_max_mtime(sbi); | |
1887 | return 0; | |
1888 | } | |
1889 | ||
1890 | static void discard_dirty_segmap(struct f2fs_sb_info *sbi, | |
1891 | enum dirty_type dirty_type) | |
1892 | { | |
1893 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
1894 | ||
1895 | mutex_lock(&dirty_i->seglist_lock); | |
1896 | kfree(dirty_i->dirty_segmap[dirty_type]); | |
1897 | dirty_i->nr_dirty[dirty_type] = 0; | |
1898 | mutex_unlock(&dirty_i->seglist_lock); | |
1899 | } | |
1900 | ||
5ec4e49f | 1901 | static void destroy_victim_secmap(struct f2fs_sb_info *sbi) |
351df4b2 JK |
1902 | { |
1903 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
5ec4e49f | 1904 | kfree(dirty_i->victim_secmap); |
351df4b2 JK |
1905 | } |
1906 | ||
1907 | static void destroy_dirty_segmap(struct f2fs_sb_info *sbi) | |
1908 | { | |
1909 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | |
1910 | int i; | |
1911 | ||
1912 | if (!dirty_i) | |
1913 | return; | |
1914 | ||
1915 | /* discard pre-free/dirty segments list */ | |
1916 | for (i = 0; i < NR_DIRTY_TYPE; i++) | |
1917 | discard_dirty_segmap(sbi, i); | |
1918 | ||
5ec4e49f | 1919 | destroy_victim_secmap(sbi); |
351df4b2 JK |
1920 | SM_I(sbi)->dirty_info = NULL; |
1921 | kfree(dirty_i); | |
1922 | } | |
1923 | ||
1924 | static void destroy_curseg(struct f2fs_sb_info *sbi) | |
1925 | { | |
1926 | struct curseg_info *array = SM_I(sbi)->curseg_array; | |
1927 | int i; | |
1928 | ||
1929 | if (!array) | |
1930 | return; | |
1931 | SM_I(sbi)->curseg_array = NULL; | |
1932 | for (i = 0; i < NR_CURSEG_TYPE; i++) | |
1933 | kfree(array[i].sum_blk); | |
1934 | kfree(array); | |
1935 | } | |
1936 | ||
1937 | static void destroy_free_segmap(struct f2fs_sb_info *sbi) | |
1938 | { | |
1939 | struct free_segmap_info *free_i = SM_I(sbi)->free_info; | |
1940 | if (!free_i) | |
1941 | return; | |
1942 | SM_I(sbi)->free_info = NULL; | |
1943 | kfree(free_i->free_segmap); | |
1944 | kfree(free_i->free_secmap); | |
1945 | kfree(free_i); | |
1946 | } | |
1947 | ||
1948 | static void destroy_sit_info(struct f2fs_sb_info *sbi) | |
1949 | { | |
1950 | struct sit_info *sit_i = SIT_I(sbi); | |
1951 | unsigned int start; | |
1952 | ||
1953 | if (!sit_i) | |
1954 | return; | |
1955 | ||
1956 | if (sit_i->sentries) { | |
1957 | for (start = 0; start < TOTAL_SEGS(sbi); start++) { | |
1958 | kfree(sit_i->sentries[start].cur_valid_map); | |
1959 | kfree(sit_i->sentries[start].ckpt_valid_map); | |
1960 | } | |
1961 | } | |
1962 | vfree(sit_i->sentries); | |
1963 | vfree(sit_i->sec_entries); | |
1964 | kfree(sit_i->dirty_sentries_bitmap); | |
1965 | ||
1966 | SM_I(sbi)->sit_info = NULL; | |
1967 | kfree(sit_i->sit_bitmap); | |
1968 | kfree(sit_i); | |
1969 | } | |
1970 | ||
1971 | void destroy_segment_manager(struct f2fs_sb_info *sbi) | |
1972 | { | |
1973 | struct f2fs_sm_info *sm_info = SM_I(sbi); | |
3b03f724 CY |
1974 | if (!sm_info) |
1975 | return; | |
351df4b2 JK |
1976 | destroy_dirty_segmap(sbi); |
1977 | destroy_curseg(sbi); | |
1978 | destroy_free_segmap(sbi); | |
1979 | destroy_sit_info(sbi); | |
1980 | sbi->sm_info = NULL; | |
1981 | kfree(sm_info); | |
1982 | } | |
7fd9e544 JK |
1983 | |
1984 | int __init create_segment_manager_caches(void) | |
1985 | { | |
1986 | discard_entry_slab = f2fs_kmem_cache_create("discard_entry", | |
1987 | sizeof(struct discard_entry), NULL); | |
1988 | if (!discard_entry_slab) | |
1989 | return -ENOMEM; | |
1990 | return 0; | |
1991 | } | |
1992 | ||
1993 | void destroy_segment_manager_caches(void) | |
1994 | { | |
1995 | kmem_cache_destroy(discard_entry_slab); | |
1996 | } |