extern struct lprocfs_stats *obd_memory;
enum {
OBD_MEMORY_STAT = 0,
- OBD_MEMORY_PAGES_STAT = 1,
OBD_STATS_NUM,
};
extern unsigned long obd_max_dirty_pages;
extern atomic_long_t obd_dirty_pages;
extern atomic_long_t obd_dirty_transit_pages;
-extern unsigned int obd_alloc_fail_rate;
extern char obd_jobid_var[];
-/* lvfs.c */
-int obd_alloc_fail(const void *ptr, const char *name, const char *type,
- size_t size, const char *file, int line);
-
/* Some hash init argument constants */
#define HASH_POOLS_BKT_BITS 3
#define HASH_POOLS_CUR_BITS 3
#define OBD_FAIL_LPROC_REMOVE 0xB00
-#define OBD_FAIL_GENERAL_ALLOC 0xC00
-
#define OBD_FAIL_SEQ 0x1000
#define OBD_FAIL_SEQ_QUERY_NET 0x1001
#define OBD_FAIL_SEQ_EXHAUST 0x1002
#define obd_memory_sum() \
lprocfs_stats_collector(obd_memory, OBD_MEMORY_STAT, \
LPROCFS_FIELDS_FLAGS_SUM)
-#define obd_pages_add(order) \
- lprocfs_counter_add(obd_memory, OBD_MEMORY_PAGES_STAT, \
- (long)(1 << (order)))
-#define obd_pages_sub(order) \
- lprocfs_counter_sub(obd_memory, OBD_MEMORY_PAGES_STAT, \
- (long)(1 << (order)))
-#define obd_pages_sum() \
- lprocfs_stats_collector(obd_memory, OBD_MEMORY_PAGES_STAT, \
- LPROCFS_FIELDS_FLAGS_SUM)
extern void obd_update_maxusage(void);
extern __u64 obd_memory_max(void);
-extern __u64 obd_pages_max(void);
#else /* CONFIG_PROC_FS */
extern __u64 obd_alloc;
-extern __u64 obd_pages;
extern __u64 obd_max_alloc;
-extern __u64 obd_max_pages;
static inline void obd_memory_add(long size)
{
obd_alloc -= size;
}
-static inline void obd_pages_add(int order)
-{
- obd_pages += 1<< order;
- if (obd_pages > obd_max_pages)
- obd_max_pages = obd_pages;
-}
-
-static inline void obd_pages_sub(int order)
-{
- obd_pages -= 1<< order;
-}
-
#define obd_memory_sum() (obd_alloc)
-#define obd_pages_sum() (obd_pages)
#define obd_memory_max() (obd_max_alloc)
-#define obd_pages_max() (obd_max_pages)
#endif /* !CONFIG_PROC_FS */
#endif /* !OBD_DEBUG_MEMUSAGE */
-#ifdef RANDOM_FAIL_ALLOC
-#define HAS_FAIL_ALLOC_FLAG OBD_FAIL_CHECK(OBD_FAIL_GENERAL_ALLOC)
-#else
-#define HAS_FAIL_ALLOC_FLAG 0
-#endif
-
-#define OBD_ALLOC_FAIL_BITS 24
-#define OBD_ALLOC_FAIL_MASK ((1 << OBD_ALLOC_FAIL_BITS) - 1)
-#define OBD_ALLOC_FAIL_MULT (OBD_ALLOC_FAIL_MASK / 100)
-
-#define OBD_FREE_RTN0(ptr) \
-({ \
- kfree(ptr); \
- (ptr) = NULL; \
- 0; \
-})
-
#define __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, flags) \
do { \
(ptr) = (cptab) == NULL ? \
kmalloc(size, flags | __GFP_ZERO) : \
cfs_cpt_malloc(cptab, cpt, size, flags | __GFP_ZERO); \
- if (likely((ptr) != NULL && \
- (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 || \
- !obd_alloc_fail(ptr, #ptr, "km", size, \
- __FILE__, __LINE__) || \
- OBD_FREE_RTN0(ptr)))){ \
- OBD_ALLOC_POST(ptr, size, "kmalloced"); \
- } \
+ if (likely((ptr) != NULL)) \
+ OBD_ALLOC_POST(ptr, size, "kmalloced"); \
} while (0)
#define OBD_ALLOC_GFP(ptr, size, gfp_mask) \
(ptr) = (cptab) == NULL ? \
kmem_cache_alloc(slab, type | __GFP_ZERO) : \
cfs_mem_cache_cpt_alloc(slab, cptab, cpt, type | __GFP_ZERO); \
- if (likely((ptr) != NULL && \
- (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 || \
- !obd_alloc_fail(ptr, #ptr, "slab-", size, \
- __FILE__, __LINE__) || \
- OBD_SLAB_FREE_RTN0(ptr, slab)))) { \
- OBD_ALLOC_POST(ptr, size, "slab-alloced"); \
- } \
+ if (likely((ptr))) \
+ OBD_ALLOC_POST(ptr, size, "slab-alloced"); \
} while(0)
#define OBD_SLAB_ALLOC_GFP(ptr, slab, size, flags) \
#define KEY_IS(str) \
(keylen >= (sizeof(str)-1) && memcmp(key, str, (sizeof(str)-1)) == 0)
-/* Wrapper for contiguous page frame allocation */
-#define __OBD_PAGE_ALLOC_VERBOSE(ptr, cptab, cpt, gfp_mask) \
-do { \
- (ptr) = (cptab) == NULL ? \
- alloc_page(gfp_mask) : \
- cfs_page_cpt_alloc(cptab, cpt, gfp_mask); \
- if (unlikely((ptr) == NULL)) { \
- CERROR("alloc_pages of '" #ptr "' %d page(s) / "LPU64" bytes "\
- "failed\n", (int)1, \
- (__u64)(1 << PAGE_CACHE_SHIFT)); \
- CERROR(LPU64" total bytes and "LPU64" total pages " \
- "("LPU64" bytes) allocated by Lustre, " \
- "%d total bytes by LNET\n", \
- obd_memory_sum(), \
- obd_pages_sum() << PAGE_CACHE_SHIFT, \
- obd_pages_sum(), \
- atomic_read(&libcfs_kmemory)); \
- } else { \
- obd_pages_add(0); \
- CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / " \
- LPU64" bytes at %p.\n", \
- (int)1, \
- (__u64)(1 << PAGE_CACHE_SHIFT), ptr); \
- } \
-} while (0)
-
-#define OBD_PAGE_ALLOC(ptr, gfp_mask) \
- __OBD_PAGE_ALLOC_VERBOSE(ptr, NULL, 0, gfp_mask)
-#define OBD_PAGE_CPT_ALLOC(ptr, cptab, cpt, gfp_mask) \
- __OBD_PAGE_ALLOC_VERBOSE(ptr, cptab, cpt, gfp_mask)
-
-#define OBD_PAGE_FREE(ptr) \
-do { \
- LASSERT(ptr); \
- obd_pages_sub(0); \
- CDEBUG(D_MALLOC, "free_pages '" #ptr "': %d page(s) / "LPU64" bytes " \
- "at %p.\n", \
- (int)1, (__u64)(1 << PAGE_CACHE_SHIFT), \
- ptr); \
- __free_page(ptr); \
- (ptr) = (void *)0xdeadbeef; \
-} while (0)
-
#endif
DEFINE_RWLOCK(obd_dev_lock);
#ifdef CONFIG_PROC_FS
-static __u64 obd_max_pages;
static __u64 obd_max_alloc;
#else
-__u64 obd_max_pages;
__u64 obd_max_alloc;
#endif
static DEFINE_SPINLOCK(obd_updatemax_lock);
/* The following are visible and mutable through /proc/sys/lustre/. */
-unsigned int obd_alloc_fail_rate = 0;
-EXPORT_SYMBOL(obd_alloc_fail_rate);
unsigned int obd_debug_peer_on_timeout;
EXPORT_SYMBOL(obd_debug_peer_on_timeout);
unsigned int obd_dump_on_timeout;
}
EXPORT_SYMBOL(lustre_get_jobid);
-int obd_alloc_fail(const void *ptr, const char *name, const char *type,
- size_t size, const char *file, int line)
-{
- if (ptr == NULL ||
- (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
- CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n",
- ptr ? "force " :"", type, name, (__u64)size, file,
- line);
- CERROR(LPU64" total bytes and "LPU64" total pages "
- "("LPU64" bytes) allocated by Lustre, "
- "%d total bytes by LNET\n",
- obd_memory_sum(),
- obd_pages_sum() << PAGE_CACHE_SHIFT,
- obd_pages_sum(),
- atomic_read(&libcfs_kmemory));
- return 1;
- }
- return 0;
-}
-EXPORT_SYMBOL(obd_alloc_fail);
-
static int class_resolve_dev_name(__u32 len, const char *name)
{
int rc;
lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
LPROCFS_CNTR_AVGMINMAX,
"memused", "bytes");
- lprocfs_counter_init(obd_memory, OBD_MEMORY_PAGES_STAT,
- LPROCFS_CNTR_AVGMINMAX,
- "pagesused", "pages");
#endif
err = obd_init_checks();
if (err == -EOVERFLOW)
void obd_update_maxusage(void)
{
- __u64 max1, max2;
+ __u64 max;
- max1 = obd_pages_sum();
- max2 = obd_memory_sum();
+ max = obd_memory_sum();
spin_lock(&obd_updatemax_lock);
- if (max1 > obd_max_pages)
- obd_max_pages = max1;
- if (max2 > obd_max_alloc)
- obd_max_alloc = max2;
+ if (max > obd_max_alloc)
+ obd_max_alloc = max;
spin_unlock(&obd_updatemax_lock);
}
EXPORT_SYMBOL(obd_update_maxusage);
{
__u64 ret;
+ obd_update_maxusage();
spin_lock(&obd_updatemax_lock);
ret = obd_max_alloc;
spin_unlock(&obd_updatemax_lock);
return ret;
}
-
-__u64 obd_pages_max(void)
-{
- __u64 ret;
-
- spin_lock(&obd_updatemax_lock);
- ret = obd_max_pages;
- spin_unlock(&obd_updatemax_lock);
-
- return ret;
-}
#endif /* CONFIG_PROC_FS */
/* liblustre doesn't call cleanup_obdclass, apparently. we carry on in this
* ifdef to the end of the file to cover module and versioning goo.*/
static void cleanup_obdclass(void)
{
- __u64 memory_leaked, pages_leaked;
- __u64 memory_max, pages_max;
- ENTRY;
+ __u64 memory_leaked;
+ __u64 memory_max;
+ ENTRY;
- lustre_unregister_fs();
+ lustre_unregister_fs();
misc_deregister(&obd_psdev);
llog_info_fini();
obd_zombie_impexp_stop();
memory_leaked = obd_memory_sum();
- pages_leaked = obd_pages_sum();
memory_max = obd_memory_max();
- pages_max = obd_pages_max();
lprocfs_free_stats(&obd_memory);
CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
"obd_memory max: "LPU64", leaked: "LPU64"\n",
memory_max, memory_leaked);
- CDEBUG((pages_leaked) ? D_ERROR : D_INFO,
- "obd_memory_pages max: "LPU64", leaked: "LPU64"\n",
- pages_max, pages_leaked);
EXIT;
}
}
static int
-proc_pages_alloc(struct ctl_table *table, int write, void __user *buffer,
- size_t *lenp, loff_t *ppos)
-{
- char buf[22];
- int len;
-
- if (!*lenp || (*ppos && !write)) {
- *lenp = 0;
- return 0;
- }
- if (write)
- return -EINVAL;
-
- len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
- if (len > *lenp)
- len = *lenp;
- buf[len] = '\0';
- if (copy_to_user(buffer, buf, len))
- return -EFAULT;
- *lenp = len;
- *ppos += *lenp;
- return 0;
-}
-
-static int
proc_mem_max(struct ctl_table *table, int write, void __user *buffer,
size_t *lenp, loff_t *ppos)
{
}
static int
-proc_pages_max(struct ctl_table *table, int write, void __user *buffer,
- size_t *lenp, loff_t *ppos)
-{
- char buf[22];
- int len;
-
- if (!*lenp || (*ppos && !write)) {
- *lenp = 0;
- return 0;
- }
- if (write)
- return -EINVAL;
-
- len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
- if (len > *lenp)
- len = *lenp;
- buf[len] = '\0';
- if (copy_to_user(buffer, buf, len))
- return -EFAULT;
- *lenp = len;
- *ppos += *lenp;
- return 0;
-}
-
-static int
proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
return rc;
}
-#ifdef RANDOM_FAIL_ALLOC
-static int proc_alloc_fail_rate(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- int rc = 0;
-
- if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
- *lenp = 0;
- return 0;
- }
- if (write) {
- rc = lprocfs_write_frac_helper(buffer, *lenp,
- (unsigned int*)table->data,
- OBD_ALLOC_FAIL_MULT);
- } else {
- char buf[21];
- int len;
-
- len = lprocfs_read_frac_helper(buf, 21,
- *(unsigned int*)table->data,
- OBD_ALLOC_FAIL_MULT);
- if (len > *lenp)
- len = *lenp;
- buf[len] = '\0';
- if (copy_to_user(buffer, buf, len))
- return -EFAULT;
- *lenp = len;
- }
- *ppos += *lenp;
- return rc;
-}
-#endif
-
#ifdef CONFIG_SYSCTL
static struct ctl_table obd_table[] = {
{
},
{
INIT_CTL_NAME
- .procname = "pagesused",
- .data = NULL,
- .maxlen = 0,
- .mode = 0444,
- .proc_handler = &proc_pages_alloc
- },
- {
- INIT_CTL_NAME
.procname = "memused_max",
.data = NULL,
.maxlen = 0,
},
{
INIT_CTL_NAME
- .procname = "pagesused_max",
- .data = NULL,
- .maxlen = 0,
- .mode = 0444,
- .proc_handler = &proc_pages_max
- },
- {
- INIT_CTL_NAME
.procname = "ldlm_timeout",
.data = &ldlm_timeout,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = &proc_set_timeout
},
-#ifdef RANDOM_FAIL_ALLOC
- {
- INIT_CTL_NAME
- .procname = "alloc_fail_rate",
- .data = &obd_alloc_fail_rate,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = &proc_alloc_fail_rate
- },
-#endif
{
INIT_CTL_NAME
.procname = "max_dirty_mb",
/* Take extra ref so __free_pages() can be called OK */
get_page(res->lnb_page);
} else {
- OBD_PAGE_ALLOC(res->lnb_page, gfp_mask);
+ res->lnb_page = alloc_page(gfp_mask);
if (res->lnb_page == NULL) {
CERROR("can't get page for id " DOSTID"\n",
POSTID(&obj->ioo_oid));
kunmap(page);
/* NB see comment above regarding persistent pages */
- OBD_PAGE_FREE(page);
+ __free_page(page);
}
return rc;
CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
for (i = 0; i < *pages; i++) {
kunmap(res[i].lnb_page);
- /* NB if this is a persistent page, __free_pages will just
+ /* NB if this is a persistent page, __free_page() will just
* lose the extra ref gained above */
- OBD_PAGE_FREE(res[i].lnb_page);
+ __free_page(res[i].lnb_page);
res[i].lnb_page = NULL;
atomic_dec(&obd->u.echo.eo_prep);
}
commitrw_cleanup:
atomic_sub(pgs, &obd->u.echo.eo_prep);
- CERROR("cleaning up %d pages (%d obdos)\n",
- niocount - pgs - 1, objcount);
+ CERROR("cleaning up %d pages (%d obdos)\n",
+ niocount - pgs - 1, objcount);
- while (pgs < niocount) {
+ while (pgs < niocount) {
struct page *page = res[pgs++].lnb_page;
- if (page == NULL)
- continue;
+ if (page == NULL)
+ continue;
- /* NB see comment above regarding persistent pages */
- OBD_PAGE_FREE(page);
+ /* NB see comment above regarding persistent pages */
+ __free_page(page);
atomic_dec(&obd->u.echo.eo_prep);
- }
- return rc;
+ }
+ return rc;
}
LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
void echo_persistent_pages_fini(void)
{
- int i;
+ int i;
- for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
- if (echo_persistent_pages[i] != NULL) {
- OBD_PAGE_FREE(echo_persistent_pages[i]);
- echo_persistent_pages[i] = NULL;
- }
+ for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
+ if (echo_persistent_pages[i] != NULL) {
+ __free_page(echo_persistent_pages[i]);
+ echo_persistent_pages[i] = NULL;
+ }
}
int echo_persistent_pages_init(void)
gfp_t gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
GFP_IOFS : GFP_HIGHUSER;
- OBD_PAGE_ALLOC(pg, gfp_mask);
+ pg = alloc_page(gfp_mask);
if (pg == NULL) {
echo_persistent_pages_fini();
return -ENOMEM;
RETURN(-ENOMEM);
}
- for (i = 0, pgp = pga, off = offset;
- i < npages;
+ for (i = 0, pgp = pga, off = offset;
+ i < npages;
i++, pgp++, off += PAGE_CACHE_SIZE) {
- LASSERT (pgp->pg == NULL); /* for cleanup */
+ LASSERT(pgp->pg == NULL); /* for cleanup */
- rc = -ENOMEM;
- OBD_PAGE_ALLOC(pgp->pg, gfp_mask);
- if (pgp->pg == NULL)
- goto out;
+ rc = -ENOMEM;
+ pgp->pg = alloc_page(gfp_mask);
+ if (pgp->pg == NULL)
+ goto out;
- pages[i] = pgp->pg;
+ pages[i] = pgp->pg;
pgp->count = PAGE_CACHE_SIZE;
- pgp->off = off;
- pgp->flag = brw_flags;
+ pgp->off = off;
+ pgp->flag = brw_flags;
if (verify)
echo_client_page_debug_setup(pgp->pg, rw,
ostid_id(&oa->o_oi), off,
pgp->count);
- }
+ }
/* brw mode can only be used at client */
LASSERT(ed->ed_next != NULL);
if (vrc != 0 && rc == 0)
rc = vrc;
}
- OBD_PAGE_FREE(pgp->pg);
+ __free_page(pgp->pg);
}
OBD_FREE(pga, npages * sizeof(*pga));
OBD_FREE(pages, npages * sizeof(*pages));
if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
force_over_128tb = 1;
- OBD_PAGE_ALLOC(__page, GFP_IOFS);
+ __page = alloc_page(GFP_IOFS);
if (__page == NULL)
GOTO(out, rc = -ENOMEM);
page = (unsigned long)page_address(__page);
out:
if (__page)
- OBD_PAGE_FREE(__page);
+ __free_page(__page);
return rc;
}