block: fix revalidate performance regression
[platform/kernel/linux-starfive.git] / block / blk-iocost.c
index 4953964..00d59d2 100644 (file)
@@ -232,7 +232,9 @@ enum {
 
        /* 1/64k is granular enough and can easily be handled w/ u32 */
        WEIGHT_ONE              = 1 << 16,
+};
 
+enum {
        /*
         * As vtime is used to calculate the cost of each IO, it needs to
         * be fairly high precision.  For example, it should be able to
@@ -256,6 +258,11 @@ enum {
        VRATE_MIN               = VTIME_PER_USEC * VRATE_MIN_PPM / MILLION,
        VRATE_CLAMP_ADJ_PCT     = 4,
 
+       /* switch iff the conditions are met for longer than this */
+       AUTOP_CYCLE_NSEC        = 10LLU * NSEC_PER_SEC,
+};
+
+enum {
        /* if IOs end up waiting for requests, issue less */
        RQ_WAIT_BUSY_PCT        = 5,
 
@@ -294,9 +301,6 @@ enum {
        /* don't let cmds which take a very long time pin lagging for too long */
        MAX_LAGGING_PERIODS     = 10,
 
-       /* switch iff the conditions are met for longer than this */
-       AUTOP_CYCLE_NSEC        = 10LLU * NSEC_PER_SEC,
-
        /*
         * Count IO size in 4k pages.  The 12bit shift helps keeping
         * size-proportional components of cost calculation in closer
@@ -865,9 +869,14 @@ static void calc_lcoefs(u64 bps, u64 seqiops, u64 randiops,
 
        *page = *seqio = *randio = 0;
 
-       if (bps)
-               *page = DIV64_U64_ROUND_UP(VTIME_PER_SEC,
-                                          DIV_ROUND_UP_ULL(bps, IOC_PAGE_SIZE));
+       if (bps) {
+               u64 bps_pages = DIV_ROUND_UP_ULL(bps, IOC_PAGE_SIZE);
+
+               if (bps_pages)
+                       *page = DIV64_U64_ROUND_UP(VTIME_PER_SEC, bps_pages);
+               else
+                       *page = 1;
+       }
 
        if (seqiops) {
                v = DIV64_U64_ROUND_UP(VTIME_PER_SEC, seqiops);