Whamcloud - gitweb
LU-4423 ptlrpc: use 64-bit times in ptlrpc_enc_page_pool
[fs/lustre-release.git] / lustre / ptlrpc / sec_bulk.c
index 87b570e..15c4f9b 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #include "ptlrpc_internal.h"
 
-static int mult = 20 - PAGE_CACHE_SHIFT;
+static int mult = 20 - PAGE_SHIFT;
 static int enc_pool_max_memory_mb;
-CFS_MODULE_PARM(enc_pool_max_memory_mb, "i", int, 0644,
-               "Encoding pool max memory (MB), 1/8 of total physical memory by default");
-
+module_param(enc_pool_max_memory_mb, int, 0644);
+MODULE_PARM_DESC(enc_pool_max_memory_mb,
+                "Encoding pool max memory (MB), 1/8 of total physical memory by default");
 
 /****************************************
  * bulk encryption page pools           *
  ****************************************/
 
 
-#define PTRS_PER_PAGE   (PAGE_CACHE_SIZE / sizeof(void *))
+#define PTRS_PER_PAGE   (PAGE_SIZE / sizeof(void *))
 #define PAGES_PER_POOL  (PTRS_PER_PAGE)
 
 #define IDLE_IDX_MAX            (100)
@@ -97,8 +93,8 @@ static struct ptlrpc_enc_page_pool {
         unsigned long    epp_idle_idx;
 
         /* last shrink time due to mem tight */
-        long             epp_last_shrink;
-        long             epp_last_access;
+       time64_t        epp_last_shrink;
+       time64_t        epp_last_access;
 
         /*
          * in-pool pages bookkeeping
@@ -165,8 +161,8 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
                   page_pools.epp_total_pages,
                   page_pools.epp_free_pages,
                   page_pools.epp_idle_idx,
-                  cfs_time_current_sec() - page_pools.epp_last_shrink,
-                  cfs_time_current_sec() - page_pools.epp_last_access,
+                  (long)(ktime_get_seconds() - page_pools.epp_last_shrink),
+                  (long)(ktime_get_seconds() - page_pools.epp_last_access),
                   page_pools.epp_st_max_pages,
                   page_pools.epp_st_grows,
                   page_pools.epp_st_grow_fails,
@@ -222,7 +218,7 @@ static void enc_pools_release_free_pages(long npages)
         /* free unused pools */
         while (p_idx_max1 < p_idx_max2) {
                 LASSERT(page_pools.epp_pools[p_idx_max2]);
-               OBD_FREE(page_pools.epp_pools[p_idx_max2], PAGE_CACHE_SIZE);
+               OBD_FREE(page_pools.epp_pools[p_idx_max2], PAGE_SIZE);
                 page_pools.epp_pools[p_idx_max2] = NULL;
                 p_idx_max2--;
         }
@@ -238,7 +234,7 @@ static unsigned long enc_pools_shrink_count(struct shrinker *s,
         * if no pool access for a long time, we consider it's fully idle.
         * a little race here is fine.
         */
-       if (unlikely(cfs_time_current_sec() - page_pools.epp_last_access >
+       if (unlikely(ktime_get_real_seconds() - page_pools.epp_last_access >
                     CACHE_QUIESCENT_PERIOD)) {
                spin_lock(&page_pools.epp_lock);
                page_pools.epp_idle_idx = IDLE_IDX_MAX;
@@ -265,7 +261,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s,
                       (long)sc->nr_to_scan, page_pools.epp_free_pages);
 
                page_pools.epp_st_shrinks++;
-               page_pools.epp_last_shrink = cfs_time_current_sec();
+               page_pools.epp_last_shrink = ktime_get_real_seconds();
        }
        spin_unlock(&page_pools.epp_lock);
 
@@ -273,7 +269,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s,
         * if no pool access for a long time, we consider it's fully idle.
         * a little race here is fine.
         */
-       if (unlikely(cfs_time_current_sec() - page_pools.epp_last_access >
+       if (unlikely(ktime_get_real_seconds() - page_pools.epp_last_access >
                     CACHE_QUIESCENT_PERIOD)) {
                spin_lock(&page_pools.epp_lock);
                page_pools.epp_idle_idx = IDLE_IDX_MAX;
@@ -328,7 +324,7 @@ static unsigned long enc_pools_cleanup(struct page ***pools, int npools)
                                        cleaned++;
                                }
                        }
-                       OBD_FREE(pools[i], PAGE_CACHE_SIZE);
+                       OBD_FREE(pools[i], PAGE_SIZE);
                        pools[i] = NULL;
                }
        }
@@ -448,7 +444,7 @@ static int enc_pools_add_pages(int npages)
                 goto out;
 
        for (i = 0; i < npools; i++) {
-               OBD_ALLOC(pools[i], PAGE_CACHE_SIZE);
+               OBD_ALLOC(pools[i], PAGE_SIZE);
                if (pools[i] == NULL)
                        goto out_pools;
 
@@ -490,36 +486,32 @@ static inline void enc_pools_wakeup(void)
        }
 }
 
-static int enc_pools_should_grow(int page_needed, long now)
+static int enc_pools_should_grow(int page_needed, time64_t now)
 {
-        /* don't grow if someone else is growing the pools right now,
-         * or the pools has reached its full capacity
-         */
-        if (page_pools.epp_growing ||
-            page_pools.epp_total_pages == page_pools.epp_max_pages)
-                return 0;
+       /* don't grow if someone else is growing the pools right now,
+        * or the pools has reached its full capacity
+        */
+       if (page_pools.epp_growing ||
+           page_pools.epp_total_pages == page_pools.epp_max_pages)
+               return 0;
 
-        /* if total pages is not enough, we need to grow */
-        if (page_pools.epp_total_pages < page_needed)
-                return 1;
+       /* if total pages is not enough, we need to grow */
+       if (page_pools.epp_total_pages < page_needed)
+               return 1;
 
-        /*
-         * we wanted to return 0 here if there was a shrink just happened
-         * moment ago, but this may cause deadlock if both client and ost
-         * live on single node.
-         */
-#if 0
-        if (now - page_pools.epp_last_shrink < 2)
-                return 0;
-#endif
+       /*
+        * we wanted to return 0 here if there was a shrink just
+        * happened a moment ago, but this may cause deadlock if both
+        * client and ost live on single node.
+        */
 
-        /*
-         * here we perhaps need consider other factors like wait queue
-         * length, idle index, etc. ?
-         */
+       /*
+        * here we perhaps need consider other factors like wait queue
+        * length, idle index, etc. ?
+        */
 
-        /* grow the pools in any other cases */
-        return 1;
+       /* grow the pools in any other cases */
+       return 1;
 }
 
 /*
@@ -560,7 +552,7 @@ int sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc)
        if (GET_ENC_KIOV(desc) != NULL)
                return 0;
 
-       OBD_ALLOC(GET_ENC_KIOV(desc),
+       OBD_ALLOC_LARGE(GET_ENC_KIOV(desc),
                  desc->bd_iov_count * sizeof(*GET_ENC_KIOV(desc)));
        if (GET_ENC_KIOV(desc) == NULL)
                return -ENOMEM;
@@ -573,7 +565,7 @@ again:
                if (tick == 0)
                        tick = cfs_time_current();
 
-               now = cfs_time_current_sec();
+               now = ktime_get_real_seconds();
 
                page_pools.epp_st_missings++;
                page_pools.epp_pages_short += desc->bd_iov_count;
@@ -614,8 +606,8 @@ again:
                                 * will put request back in queue. */
                                page_pools.epp_st_outofmem++;
                                spin_unlock(&page_pools.epp_lock);
-                               OBD_FREE(GET_ENC_KIOV(desc),
-                                        desc->bd_iov_count *
+                               OBD_FREE_LARGE(GET_ENC_KIOV(desc),
+                                              desc->bd_iov_count *
                                                sizeof(*GET_ENC_KIOV(desc)));
                                GET_ENC_KIOV(desc) = NULL;
                                return -ENOMEM;
@@ -668,7 +660,7 @@ again:
                                    this_idle) /
                                   (IDLE_IDX_WEIGHT + 1);
 
-        page_pools.epp_last_access = cfs_time_current_sec();
+       page_pools.epp_last_access = ktime_get_real_seconds();
 
        spin_unlock(&page_pools.epp_lock);
        return 0;
@@ -716,7 +708,7 @@ void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc)
 
        spin_unlock(&page_pools.epp_lock);
 
-       OBD_FREE(GET_ENC_KIOV(desc),
+       OBD_FREE_LARGE(GET_ENC_KIOV(desc),
                 desc->bd_iov_count * sizeof(*GET_ENC_KIOV(desc)));
        GET_ENC_KIOV(desc) = NULL;
 }
@@ -793,8 +785,8 @@ int sptlrpc_enc_pool_init(void)
         page_pools.epp_growing = 0;
 
         page_pools.epp_idle_idx = 0;
-        page_pools.epp_last_shrink = cfs_time_current_sec();
-        page_pools.epp_last_access = cfs_time_current_sec();
+       page_pools.epp_last_shrink = ktime_get_real_seconds();
+       page_pools.epp_last_access = ktime_get_real_seconds();
 
        spin_lock_init(&page_pools.epp_lock);
         page_pools.epp_total_pages = 0;