* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#ifdef __KERNEL__
-#define PTRS_PER_PAGE (CFS_PAGE_SIZE / sizeof(void *))
+#define PTRS_PER_PAGE (PAGE_CACHE_SIZE / sizeof(void *))
#define PAGES_PER_POOL (PTRS_PER_PAGE)
#define IDLE_IDX_MAX (100)
unsigned long epp_max_pages; /* maximum pages can hold, const */
unsigned int epp_max_pools; /* number of pools, const */
- /*
- * wait queue in case of not enough free pages.
- */
- cfs_waitq_t epp_waitq; /* waiting threads */
- unsigned int epp_waitqlen; /* wait queue length */
- unsigned long epp_pages_short; /* # of pages wanted of in-q users */
- unsigned int epp_growing:1; /* during adding pages */
+ /*
+ * wait queue in case of not enough free pages.
+ */
+ wait_queue_head_t epp_waitq; /* waiting threads */
+ unsigned int epp_waitqlen; /* wait queue length */
+ unsigned long epp_pages_short; /* # of pages wanted of in-q users */
+ unsigned int epp_growing:1; /* during adding pages */
/*
* indicating how idle the pools are, from 0 to MAX_IDLE_IDX
/*
* in-pool pages bookkeeping
*/
- cfs_spinlock_t epp_lock; /* protect following fields */
+ spinlock_t epp_lock; /* protect following fields */
unsigned long epp_total_pages; /* total pages in pools */
unsigned long epp_free_pages; /* current pages available */
unsigned long epp_st_lowfree; /* lowest free pages reached */
unsigned int epp_st_max_wqlen; /* highest waitqueue length */
cfs_time_t epp_st_max_wait; /* in jeffies */
- /*
- * pointers to pools
- */
- cfs_page_t ***epp_pools;
+ /*
+ * pointers to pools
+ */
+ struct page ***epp_pools;
} page_pools;
/*
* memory shrinker
*/
-const int pools_shrinker_seeks = CFS_DEFAULT_SEEKS;
-static struct cfs_shrinker *pools_shrinker = NULL;
+const int pools_shrinker_seeks = DEFAULT_SEEKS;
+static struct shrinker *pools_shrinker;
/*
* /proc/fs/lustre/sptlrpc/encrypt_page_pools
*/
-int sptlrpc_proc_read_enc_pool(char *page, char **start, off_t off, int count,
- int *eof, void *data)
+int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
{
int rc;
- cfs_spin_lock(&page_pools.epp_lock);
+ spin_lock(&page_pools.epp_lock);
- rc = snprintf(page, count,
+ rc = seq_printf(m,
"physical pages: %lu\n"
"pages per pool: %lu\n"
"max pages: %lu\n"
"max waitqueue depth: %u\n"
"max wait time: "CFS_TIME_T"/%u\n"
,
- cfs_num_physpages,
+ totalram_pages,
PAGES_PER_POOL,
page_pools.epp_max_pages,
page_pools.epp_max_pools,
page_pools.epp_st_grow_fails,
page_pools.epp_st_shrinks,
page_pools.epp_st_access,
- page_pools.epp_st_missings,
- page_pools.epp_st_lowfree,
- page_pools.epp_st_max_wqlen,
- page_pools.epp_st_max_wait, CFS_HZ
- );
-
- cfs_spin_unlock(&page_pools.epp_lock);
- return rc;
+ page_pools.epp_st_missings,
+ page_pools.epp_st_lowfree,
+ page_pools.epp_st_max_wqlen,
+ page_pools.epp_st_max_wait, HZ
+ );
+
+ spin_unlock(&page_pools.epp_lock);
+ return rc;
}
static void enc_pools_release_free_pages(long npages)
LASSERT(page_pools.epp_pools[p_idx]);
LASSERT(page_pools.epp_pools[p_idx][g_idx] != NULL);
- cfs_free_page(page_pools.epp_pools[p_idx][g_idx]);
+ __free_page(page_pools.epp_pools[p_idx][g_idx]);
page_pools.epp_pools[p_idx][g_idx] = NULL;
if (++g_idx == PAGES_PER_POOL) {
p_idx++;
g_idx = 0;
}
- };
+ }
/* 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], CFS_PAGE_SIZE);
+ OBD_FREE(page_pools.epp_pools[p_idx_max2], PAGE_CACHE_SIZE);
page_pools.epp_pools[p_idx_max2] = NULL;
p_idx_max2--;
}
*/
static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask))
{
- if (unlikely(shrink_param(sc, nr_to_scan) != 0)) {
- cfs_spin_lock(&page_pools.epp_lock);
+ if (unlikely(shrink_param(sc, nr_to_scan) != 0)) {
+ spin_lock(&page_pools.epp_lock);
shrink_param(sc, nr_to_scan) = min_t(unsigned long,
shrink_param(sc, nr_to_scan),
page_pools.epp_free_pages -
page_pools.epp_st_shrinks++;
page_pools.epp_last_shrink = cfs_time_current_sec();
}
- cfs_spin_unlock(&page_pools.epp_lock);
- }
+ spin_unlock(&page_pools.epp_lock);
+ }
- /*
- * 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 >
- CACHE_QUIESCENT_PERIOD)) {
- cfs_spin_lock(&page_pools.epp_lock);
- page_pools.epp_idle_idx = IDLE_IDX_MAX;
- cfs_spin_unlock(&page_pools.epp_lock);
- }
+ /*
+ * 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 >
+ CACHE_QUIESCENT_PERIOD)) {
+ spin_lock(&page_pools.epp_lock);
+ page_pools.epp_idle_idx = IDLE_IDX_MAX;
+ spin_unlock(&page_pools.epp_lock);
+ }
- LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX);
- return max((int) page_pools.epp_free_pages - PTLRPC_MAX_BRW_PAGES, 0) *
- (IDLE_IDX_MAX - page_pools.epp_idle_idx) / IDLE_IDX_MAX;
+ LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX);
+ return max((int)page_pools.epp_free_pages - PTLRPC_MAX_BRW_PAGES, 0) *
+ (IDLE_IDX_MAX - page_pools.epp_idle_idx) / IDLE_IDX_MAX;
}
static inline
/*
* return how many pages cleaned up.
*/
-static unsigned long enc_pools_cleanup(cfs_page_t ***pools, int npools)
+static unsigned long enc_pools_cleanup(struct page ***pools, int npools)
{
- unsigned long cleaned = 0;
- int i, j;
-
- for (i = 0; i < npools; i++) {
- if (pools[i]) {
- for (j = 0; j < PAGES_PER_POOL; j++) {
- if (pools[i][j]) {
- cfs_free_page(pools[i][j]);
- cleaned++;
- }
- }
- OBD_FREE(pools[i], CFS_PAGE_SIZE);
- pools[i] = NULL;
- }
- }
+ unsigned long cleaned = 0;
+ int i, j;
+
+ for (i = 0; i < npools; i++) {
+ if (pools[i]) {
+ for (j = 0; j < PAGES_PER_POOL; j++) {
+ if (pools[i][j]) {
+ __free_page(pools[i][j]);
+ cleaned++;
+ }
+ }
+ OBD_FREE(pools[i], PAGE_CACHE_SIZE);
+ pools[i] = NULL;
+ }
+ }
- return cleaned;
+ return cleaned;
}
/*
* we have options to avoid most memory copy with some tricks. but we choose
* the simplest way to avoid complexity. It's not frequently called.
*/
-static void enc_pools_insert(cfs_page_t ***pools, int npools, int npages)
+static void enc_pools_insert(struct page ***pools, int npools, int npages)
{
int freeslot;
int op_idx, np_idx, og_idx, ng_idx;
LASSERT(npages_to_npools(npages) == npools);
LASSERT(page_pools.epp_growing);
- cfs_spin_lock(&page_pools.epp_lock);
+ spin_lock(&page_pools.epp_lock);
/*
* (1) fill all the free slots of current pools.
CDEBUG(D_SEC, "add %d pages to total %lu\n", npages,
page_pools.epp_total_pages);
- cfs_spin_unlock(&page_pools.epp_lock);
+ spin_unlock(&page_pools.epp_lock);
}
static int enc_pools_add_pages(int npages)
{
- static CFS_DEFINE_MUTEX(add_pages_mutex);
- cfs_page_t ***pools;
- int npools, alloced = 0;
- int i, j, rc = -ENOMEM;
+ static DEFINE_MUTEX(add_pages_mutex);
+ struct page ***pools;
+ int npools, alloced = 0;
+ int i, j, rc = -ENOMEM;
- if (npages < PTLRPC_MAX_BRW_PAGES)
- npages = PTLRPC_MAX_BRW_PAGES;
+ if (npages < PTLRPC_MAX_BRW_PAGES)
+ npages = PTLRPC_MAX_BRW_PAGES;
- cfs_mutex_lock(&add_pages_mutex);
+ mutex_lock(&add_pages_mutex);
if (npages + page_pools.epp_total_pages > page_pools.epp_max_pages)
npages = page_pools.epp_max_pages - page_pools.epp_total_pages;
if (pools == NULL)
goto out;
- for (i = 0; i < npools; i++) {
- OBD_ALLOC(pools[i], CFS_PAGE_SIZE);
- if (pools[i] == NULL)
- goto out_pools;
+ for (i = 0; i < npools; i++) {
+ OBD_ALLOC(pools[i], PAGE_CACHE_SIZE);
+ if (pools[i] == NULL)
+ goto out_pools;
- for (j = 0; j < PAGES_PER_POOL && alloced < npages; j++) {
- pools[i][j] = cfs_alloc_page(CFS_ALLOC_IO |
- CFS_ALLOC_HIGHMEM);
- if (pools[i][j] == NULL)
- goto out_pools;
+ for (j = 0; j < PAGES_PER_POOL && alloced < npages; j++) {
+ pools[i][j] = alloc_page(GFP_NOFS |
+ __GFP_HIGHMEM);
+ if (pools[i][j] == NULL)
+ goto out_pools;
- alloced++;
- }
- }
- LASSERT(alloced == npages);
+ alloced++;
+ }
+ }
+ LASSERT(alloced == npages);
enc_pools_insert(pools, npools, npages);
CDEBUG(D_SEC, "added %d pages into pools\n", npages);
CERROR("Failed to allocate %d enc pages\n", npages);
}
- cfs_mutex_unlock(&add_pages_mutex);
+ mutex_unlock(&add_pages_mutex);
return rc;
}
static inline void enc_pools_wakeup(void)
{
- LASSERT_SPIN_LOCKED(&page_pools.epp_lock);
- LASSERT(page_pools.epp_waitqlen >= 0);
+ assert_spin_locked(&page_pools.epp_lock);
- if (unlikely(page_pools.epp_waitqlen)) {
- LASSERT(cfs_waitq_active(&page_pools.epp_waitq));
- cfs_waitq_broadcast(&page_pools.epp_waitq);
- }
+ if (unlikely(page_pools.epp_waitqlen)) {
+ LASSERT(waitqueue_active(&page_pools.epp_waitq));
+ wake_up_all(&page_pools.epp_waitq);
+ }
}
static int enc_pools_should_grow(int page_needed, long now)
*/
int sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc)
{
- cfs_waitlink_t waitlink;
- unsigned long this_idle = -1;
- cfs_time_t tick = 0;
- long now;
- int p_idx, g_idx;
- int i;
+ wait_queue_t waitlink;
+ unsigned long this_idle = -1;
+ cfs_time_t tick = 0;
+ long now;
+ int p_idx, g_idx;
+ int i;
- LASSERT(desc->bd_iov_count > 0);
- LASSERT(desc->bd_iov_count <= page_pools.epp_max_pages);
+ LASSERT(desc->bd_iov_count > 0);
+ LASSERT(desc->bd_iov_count <= page_pools.epp_max_pages);
- /* resent bulk, enc iov might have been allocated previously */
- if (desc->bd_enc_iov != NULL)
- return 0;
+ /* resent bulk, enc iov might have been allocated previously */
+ if (desc->bd_enc_iov != NULL)
+ return 0;
- OBD_ALLOC(desc->bd_enc_iov,
- desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
- if (desc->bd_enc_iov == NULL)
- return -ENOMEM;
+ OBD_ALLOC(desc->bd_enc_iov,
+ desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
+ if (desc->bd_enc_iov == NULL)
+ return -ENOMEM;
- cfs_spin_lock(&page_pools.epp_lock);
+ spin_lock(&page_pools.epp_lock);
- page_pools.epp_st_access++;
+ page_pools.epp_st_access++;
again:
- if (unlikely(page_pools.epp_free_pages < desc->bd_iov_count)) {
- if (tick == 0)
- tick = cfs_time_current();
+ if (unlikely(page_pools.epp_free_pages < desc->bd_iov_count)) {
+ if (tick == 0)
+ tick = cfs_time_current();
- now = cfs_time_current_sec();
+ now = cfs_time_current_sec();
- page_pools.epp_st_missings++;
- page_pools.epp_pages_short += desc->bd_iov_count;
+ page_pools.epp_st_missings++;
+ page_pools.epp_pages_short += desc->bd_iov_count;
- if (enc_pools_should_grow(desc->bd_iov_count, now)) {
- page_pools.epp_growing = 1;
+ if (enc_pools_should_grow(desc->bd_iov_count, now)) {
+ page_pools.epp_growing = 1;
- cfs_spin_unlock(&page_pools.epp_lock);
- enc_pools_add_pages(page_pools.epp_pages_short / 2);
- cfs_spin_lock(&page_pools.epp_lock);
+ spin_unlock(&page_pools.epp_lock);
+ enc_pools_add_pages(page_pools.epp_pages_short / 2);
+ spin_lock(&page_pools.epp_lock);
- page_pools.epp_growing = 0;
+ page_pools.epp_growing = 0;
- enc_pools_wakeup();
- } else {
- if (++page_pools.epp_waitqlen >
- page_pools.epp_st_max_wqlen)
- page_pools.epp_st_max_wqlen =
- page_pools.epp_waitqlen;
+ enc_pools_wakeup();
+ } else {
+ if (++page_pools.epp_waitqlen >
+ page_pools.epp_st_max_wqlen)
+ page_pools.epp_st_max_wqlen =
+ page_pools.epp_waitqlen;
- cfs_set_current_state(CFS_TASK_UNINT);
- cfs_waitlink_init(&waitlink);
- cfs_waitq_add(&page_pools.epp_waitq, &waitlink);
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ init_waitqueue_entry_current(&waitlink);
+ add_wait_queue(&page_pools.epp_waitq, &waitlink);
- cfs_spin_unlock(&page_pools.epp_lock);
- cfs_waitq_wait(&waitlink, CFS_TASK_UNINT);
- cfs_waitq_del(&page_pools.epp_waitq, &waitlink);
- LASSERT(page_pools.epp_waitqlen > 0);
- cfs_spin_lock(&page_pools.epp_lock);
- page_pools.epp_waitqlen--;
- }
+ spin_unlock(&page_pools.epp_lock);
+ waitq_wait(&waitlink, TASK_UNINTERRUPTIBLE);
+ remove_wait_queue(&page_pools.epp_waitq, &waitlink);
+ LASSERT(page_pools.epp_waitqlen > 0);
+ spin_lock(&page_pools.epp_lock);
+ page_pools.epp_waitqlen--;
+ }
- LASSERT(page_pools.epp_pages_short >= desc->bd_iov_count);
- page_pools.epp_pages_short -= desc->bd_iov_count;
+ LASSERT(page_pools.epp_pages_short >= desc->bd_iov_count);
+ page_pools.epp_pages_short -= desc->bd_iov_count;
- this_idle = 0;
- goto again;
- }
+ this_idle = 0;
+ goto again;
+ }
/* record max wait time */
if (unlikely(tick != 0)) {
page_pools.epp_last_access = cfs_time_current_sec();
- cfs_spin_unlock(&page_pools.epp_lock);
- return 0;
+ spin_unlock(&page_pools.epp_lock);
+ return 0;
}
EXPORT_SYMBOL(sptlrpc_enc_pool_get_pages);
LASSERT(desc->bd_iov_count > 0);
- cfs_spin_lock(&page_pools.epp_lock);
+ spin_lock(&page_pools.epp_lock);
p_idx = page_pools.epp_free_pages / PAGES_PER_POOL;
g_idx = page_pools.epp_free_pages % PAGES_PER_POOL;
enc_pools_wakeup();
- cfs_spin_unlock(&page_pools.epp_lock);
+ spin_unlock(&page_pools.epp_lock);
- OBD_FREE(desc->bd_enc_iov,
- desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
- desc->bd_enc_iov = NULL;
+ OBD_FREE(desc->bd_enc_iov,
+ desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
+ desc->bd_enc_iov = NULL;
}
EXPORT_SYMBOL(sptlrpc_enc_pool_put_pages);
*/
int sptlrpc_enc_pool_add_user(void)
{
- int need_grow = 0;
+ int need_grow = 0;
- cfs_spin_lock(&page_pools.epp_lock);
- if (page_pools.epp_growing == 0 && page_pools.epp_total_pages == 0) {
- page_pools.epp_growing = 1;
- need_grow = 1;
- }
- cfs_spin_unlock(&page_pools.epp_lock);
+ spin_lock(&page_pools.epp_lock);
+ if (page_pools.epp_growing == 0 && page_pools.epp_total_pages == 0) {
+ page_pools.epp_growing = 1;
+ need_grow = 1;
+ }
+ spin_unlock(&page_pools.epp_lock);
- if (need_grow) {
- enc_pools_add_pages(PTLRPC_MAX_BRW_PAGES +
- PTLRPC_MAX_BRW_PAGES);
+ if (need_grow) {
+ enc_pools_add_pages(PTLRPC_MAX_BRW_PAGES +
+ PTLRPC_MAX_BRW_PAGES);
- cfs_spin_lock(&page_pools.epp_lock);
- page_pools.epp_growing = 0;
- enc_pools_wakeup();
- cfs_spin_unlock(&page_pools.epp_lock);
- }
- return 0;
+ spin_lock(&page_pools.epp_lock);
+ page_pools.epp_growing = 0;
+ enc_pools_wakeup();
+ spin_unlock(&page_pools.epp_lock);
+ }
+ return 0;
}
EXPORT_SYMBOL(sptlrpc_enc_pool_add_user);
int sptlrpc_enc_pool_init(void)
{
- /*
- * maximum capacity is 1/8 of total physical memory.
- * is the 1/8 a good number?
- */
- page_pools.epp_max_pages = cfs_num_physpages / 8;
- page_pools.epp_max_pools = npages_to_npools(page_pools.epp_max_pages);
+ /*
+ * maximum capacity is 1/8 of total physical memory.
+ * is the 1/8 a good number?
+ */
+ page_pools.epp_max_pages = totalram_pages / 8;
+ page_pools.epp_max_pools = npages_to_npools(page_pools.epp_max_pages);
- cfs_waitq_init(&page_pools.epp_waitq);
- page_pools.epp_waitqlen = 0;
- page_pools.epp_pages_short = 0;
+ init_waitqueue_head(&page_pools.epp_waitq);
+ page_pools.epp_waitqlen = 0;
+ page_pools.epp_pages_short = 0;
page_pools.epp_growing = 0;
page_pools.epp_last_shrink = cfs_time_current_sec();
page_pools.epp_last_access = cfs_time_current_sec();
- cfs_spin_lock_init(&page_pools.epp_lock);
+ spin_lock_init(&page_pools.epp_lock);
page_pools.epp_total_pages = 0;
page_pools.epp_free_pages = 0;
if (page_pools.epp_pools == NULL)
return -ENOMEM;
- pools_shrinker = cfs_set_shrinker(pools_shrinker_seeks,
+ pools_shrinker = set_shrinker(pools_shrinker_seeks,
enc_pools_shrink);
if (pools_shrinker == NULL) {
enc_pools_free();
LASSERT(page_pools.epp_pools);
LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages);
- cfs_remove_shrinker(pools_shrinker);
+ remove_shrinker(pools_shrinker);
npools = npages_to_npools(page_pools.epp_total_pages);
cleaned = enc_pools_cleanup(page_pools.epp_pools, npools);
CFS_TIME_T"/%d\n",
page_pools.epp_st_max_pages, page_pools.epp_st_grows,
page_pools.epp_st_grow_fails,
- page_pools.epp_st_shrinks, page_pools.epp_st_access,
- page_pools.epp_st_missings, page_pools.epp_st_max_wqlen,
- page_pools.epp_st_max_wait, CFS_HZ);
- }
+ page_pools.epp_st_shrinks, page_pools.epp_st_access,
+ page_pools.epp_st_missings, page_pools.epp_st_max_wqlen,
+ page_pools.epp_st_max_wait, HZ);
+ }
}
#else /* !__KERNEL__ */