* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
/*
* in-pool pages bookkeeping
*/
- spinlock_t epp_lock; /* protect following fields */
+ cfs_spinlock_t epp_lock; /* protect following fields */
unsigned long epp_total_pages; /* total pages in pools */
unsigned long epp_free_pages; /* current pages available */
/*
* memory shrinker
*/
-const int pools_shrinker_seeks = DEFAULT_SEEKS;
-static struct shrinker *pools_shrinker = NULL;
+const int pools_shrinker_seeks = CFS_DEFAULT_SEEKS;
+static struct cfs_shrinker *pools_shrinker = NULL;
/*
{
int rc;
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
rc = snprintf(page, count,
"physical pages: %lu\n"
"max waitqueue depth: %u\n"
"max wait time: "CFS_TIME_T"/%u\n"
,
- num_physpages,
+ cfs_num_physpages,
PAGES_PER_POOL,
page_pools.epp_max_pages,
page_pools.epp_max_pools,
page_pools.epp_st_missings,
page_pools.epp_st_lowfree,
page_pools.epp_st_max_wqlen,
- page_pools.epp_st_max_wait, HZ
+ page_pools.epp_st_max_wait, CFS_HZ
);
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
return rc;
}
* could be called frequently for query (@nr_to_scan == 0).
* we try to keep at least PTLRPC_MAX_BRW_PAGES pages in the pool.
*/
-static int enc_pools_shrink(int nr_to_scan, unsigned int gfp_mask)
+static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask))
{
- if (unlikely(nr_to_scan != 0)) {
- spin_lock(&page_pools.epp_lock);
- nr_to_scan = min(nr_to_scan, (int) page_pools.epp_free_pages -
- PTLRPC_MAX_BRW_PAGES);
- if (nr_to_scan > 0) {
- enc_pools_release_free_pages(nr_to_scan);
- CDEBUG(D_SEC, "released %d pages, %ld left\n",
- nr_to_scan, page_pools.epp_free_pages);
+ if (unlikely(shrink_param(sc, nr_to_scan) != 0)) {
+ cfs_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 -
+ PTLRPC_MAX_BRW_PAGES);
+ if (shrink_param(sc, nr_to_scan) > 0) {
+ enc_pools_release_free_pages(shrink_param(sc,
+ nr_to_scan));
+ CDEBUG(D_SEC, "released %ld pages, %ld left\n",
+ (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();
}
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
}
/*
*/
if (unlikely(cfs_time_current_sec() - page_pools.epp_last_access >
CACHE_QUIESCENT_PERIOD)) {
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
page_pools.epp_idle_idx = IDLE_IDX_MAX;
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
}
LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX);
LASSERT(npages_to_npools(npages) == npools);
LASSERT(page_pools.epp_growing);
- spin_lock(&page_pools.epp_lock);
+ cfs_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);
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
}
static int enc_pools_add_pages(int npages)
{
- static DECLARE_MUTEX(sem_add_pages);
+ static CFS_DECLARE_MUTEX(sem_add_pages);
cfs_page_t ***pools;
int npools, alloced = 0;
int i, j, rc = -ENOMEM;
if (npages < PTLRPC_MAX_BRW_PAGES)
npages = PTLRPC_MAX_BRW_PAGES;
- down(&sem_add_pages);
+ cfs_down(&sem_add_pages);
if (npages + page_pools.epp_total_pages > page_pools.epp_max_pages)
npages = page_pools.epp_max_pages - page_pools.epp_total_pages;
CERROR("Failed to allocate %d enc pages\n", npages);
}
- up(&sem_add_pages);
+ cfs_up(&sem_add_pages);
return rc;
}
if (desc->bd_enc_iov == NULL)
return -ENOMEM;
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
page_pools.epp_st_access++;
again:
if (enc_pools_should_grow(desc->bd_iov_count, now)) {
page_pools.epp_growing = 1;
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
enc_pools_add_pages(page_pools.epp_pages_short / 2);
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
page_pools.epp_growing = 0;
page_pools.epp_st_max_wqlen =
page_pools.epp_waitqlen;
- set_current_state(CFS_TASK_UNINT);
+ cfs_set_current_state(CFS_TASK_UNINT);
cfs_waitlink_init(&waitlink);
cfs_waitq_add(&page_pools.epp_waitq, &waitlink);
- spin_unlock(&page_pools.epp_lock);
+ 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);
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
page_pools.epp_waitqlen--;
}
page_pools.epp_last_access = cfs_time_current_sec();
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
return 0;
}
EXPORT_SYMBOL(sptlrpc_enc_pool_get_pages);
LASSERT(desc->bd_iov_count > 0);
- spin_lock(&page_pools.epp_lock);
+ cfs_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();
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
OBD_FREE(desc->bd_enc_iov,
desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
{
int need_grow = 0;
- spin_lock(&page_pools.epp_lock);
+ 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;
}
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
if (need_grow) {
enc_pools_add_pages(PTLRPC_MAX_BRW_PAGES +
PTLRPC_MAX_BRW_PAGES);
- spin_lock(&page_pools.epp_lock);
+ cfs_spin_lock(&page_pools.epp_lock);
page_pools.epp_growing = 0;
enc_pools_wakeup();
- spin_unlock(&page_pools.epp_lock);
+ cfs_spin_unlock(&page_pools.epp_lock);
}
return 0;
}
static inline void enc_pools_alloc(void)
{
LASSERT(page_pools.epp_max_pools);
- /*
- * on system with huge memory but small page size, this might lead to
- * high-order allocation. but it's not common, and we suppose memory
- * be not too much fragmented at module loading time.
- */
- OBD_ALLOC(page_pools.epp_pools,
- page_pools.epp_max_pools * sizeof(*page_pools.epp_pools));
+ OBD_ALLOC_LARGE(page_pools.epp_pools,
+ page_pools.epp_max_pools *
+ sizeof(*page_pools.epp_pools));
}
static inline void enc_pools_free(void)
LASSERT(page_pools.epp_max_pools);
LASSERT(page_pools.epp_pools);
- OBD_FREE(page_pools.epp_pools,
- page_pools.epp_max_pools * sizeof(*page_pools.epp_pools));
+ OBD_FREE_LARGE(page_pools.epp_pools,
+ page_pools.epp_max_pools *
+ sizeof(*page_pools.epp_pools));
}
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 = num_physpages / 8;
+ page_pools.epp_max_pages = cfs_num_physpages / 8;
page_pools.epp_max_pools = npages_to_npools(page_pools.epp_max_pages);
cfs_waitq_init(&page_pools.epp_waitq);
page_pools.epp_last_shrink = cfs_time_current_sec();
page_pools.epp_last_access = cfs_time_current_sec();
- spin_lock_init(&page_pools.epp_lock);
+ cfs_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 = set_shrinker(pools_shrinker_seeks, enc_pools_shrink);
+ pools_shrinker = cfs_set_shrinker(pools_shrinker_seeks,
+ enc_pools_shrink);
if (pools_shrinker == NULL) {
enc_pools_free();
return -ENOMEM;
LASSERT(page_pools.epp_pools);
LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages);
- remove_shrinker(pools_shrinker);
+ cfs_remove_shrinker(pools_shrinker);
npools = npages_to_npools(page_pools.epp_total_pages);
cleaned = enc_pools_cleanup(page_pools.epp_pools, npools);
enc_pools_free();
if (page_pools.epp_st_access > 0) {
- CWARN("max pages %lu, grows %u, grow fails %u, shrinks %u, "
- "access %lu, missing %lu, max qlen %u, max wait "
- 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, HZ);
+ CDEBUG(D_SEC,
+ "max pages %lu, grows %u, grow fails %u, shrinks %u, "
+ "access %lu, missing %lu, max qlen %u, max wait "
+ 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);
}
}