Merge tag 'rdma-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[firefly-linux-kernel-4.4.55.git] / fs / f2fs / segment.h
index 552dadbb23272e8b2c3e10a04cfa3d0c0262de2d..062424a0e4c3a1ab912e0008c1eaa836f29af85f 100644 (file)
@@ -8,10 +8,13 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/blkdev.h>
+
 /* constant macro */
 #define NULL_SEGNO                     ((unsigned int)(~0))
+#define NULL_SECNO                     ((unsigned int)(~0))
 
-/* V: Logical segment # in volume, R: Relative segment # in main area */
+/* L: Logical segment # in volume, R: Relative segment # in main area */
 #define GET_L2R_SEGNO(free_i, segno)   (segno - free_i->start_segno)
 #define GET_R2L_SEGNO(free_i, segno)   (segno + free_i->start_segno)
 
        ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) ||           \
        (t == CURSEG_WARM_NODE))
 
-#define IS_CURSEG(sbi, segno)                                          \
-       ((segno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) ||    \
-        (segno == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) ||   \
-        (segno == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) ||   \
-        (segno == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) ||    \
-        (segno == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) ||   \
-        (segno == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno))
+#define IS_CURSEG(sbi, seg)                                            \
+       ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) ||      \
+        (seg == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) ||     \
+        (seg == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) ||     \
+        (seg == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) ||      \
+        (seg == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) ||     \
+        (seg == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno))
 
 #define IS_CURSEC(sbi, secno)                                          \
        ((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno /              \
 #define f2fs_bitmap_size(nr)                   \
        (BITS_TO_LONGS(nr) * sizeof(unsigned long))
 #define TOTAL_SEGS(sbi)        (SM_I(sbi)->main_segments)
+#define TOTAL_SECS(sbi)        (sbi->total_sections)
 
 #define SECTOR_FROM_BLOCK(sbi, blk_addr)                               \
        (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
+#define SECTOR_TO_BLOCK(sbi, sectors)                                  \
+       (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
 
 /* during checkpoint, bio_private is used to synchronize the last bio */
 struct bio_private {
@@ -213,7 +219,7 @@ struct dirty_seglist_info {
        unsigned long *dirty_segmap[NR_DIRTY_TYPE];
        struct mutex seglist_lock;              /* lock for segment bitmaps */
        int nr_dirty[NR_DIRTY_TYPE];            /* # of dirty segments */
-       unsigned long *victim_segmap[2];        /* BG_GC, FG_GC */
+       unsigned long *victim_secmap;           /* background GC victims */
 };
 
 /* victim selection function for cleaning and SSR */
@@ -464,8 +470,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
 
 static inline int utilization(struct f2fs_sb_info *sbi)
 {
-       return (long int)valid_user_blocks(sbi) * 100 /
-                       (long int)sbi->user_block_count;
+       return div_u64(valid_user_blocks(sbi) * 100, sbi->user_block_count);
 }
 
 /*
@@ -616,3 +621,17 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type)
                le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count)
                                - (base + 1) + type;
 }
+
+static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
+{
+       if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno))
+               return true;
+       return false;
+}
+
+static inline unsigned int max_hw_blocks(struct f2fs_sb_info *sbi)
+{
+       struct block_device *bdev = sbi->sb->s_bdev;
+       struct request_queue *q = bdev_get_queue(bdev);
+       return SECTOR_TO_BLOCK(sbi, queue_max_sectors(q));
+}