From 33754bef1a26b40687f2bb8677fb3aadcc2d5c23 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sat, 27 Jun 2015 13:47:35 -0600 Subject: [PATCH] LU-5988 obdclass: drop malloc fault and page accounting Remove the OBD_ALLOC() memory allocation fault injection since this is also possible with existing kernel mechanisms and it is no longer useful to have Lustre-specific code to do this. Remove the page allocation counters and OBD_PAGE_{ALLOC,FREE} helpers that are almost entirely unused since the move to CLIO. Update the max memory allocation counter on /proc read, so that it doesn't show as lower than the current allocation, in case it hasn't been updated since the previous ping. Signed-off-by: Andreas Dilger Change-Id: I024919d1e81730a9388e7999938a4cca1e1cab07 Reviewed-on: http://review.whamcloud.com/15110 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Niu Yawei Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/obd_support.h | 112 ++--------------------------------- lustre/obdclass/class_obd.c | 64 +++----------------- lustre/obdclass/linux/linux-sysctl.c | 109 ---------------------------------- lustre/obdecho/echo.c | 40 ++++++------- lustre/obdecho/echo_client.c | 24 ++++---- lustre/osd-ldiskfs/osd_handler.c | 4 +- 6 files changed, 47 insertions(+), 306 deletions(-) diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index ed20d85..272b87b 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -54,7 +54,6 @@ extern struct lprocfs_stats *obd_memory; enum { OBD_MEMORY_STAT = 0, - OBD_MEMORY_PAGES_STAT = 1, OBD_STATS_NUM, }; @@ -76,13 +75,8 @@ extern int at_extra; 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 @@ -467,8 +461,6 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type, #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 @@ -629,27 +621,15 @@ extern atomic_t libcfs_kmemory; #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) { @@ -663,23 +643,9 @@ static inline void obd_memory_sub(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 */ @@ -705,35 +671,13 @@ static inline void obd_pages_sub(int order) #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) \ @@ -848,13 +792,8 @@ do { \ (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) \ @@ -895,47 +834,4 @@ do { \ #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 diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 9855708..672c90e 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -62,18 +62,14 @@ struct list_head obd_types; 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; @@ -176,27 +172,6 @@ int lustre_get_jobid(char *jobid) } 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; @@ -529,9 +504,6 @@ static int __init init_obdclass(void) 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) @@ -598,16 +570,13 @@ static int __init init_obdclass(void) 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); @@ -617,34 +586,24 @@ __u64 obd_memory_max(void) { __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(); @@ -665,18 +624,13 @@ static void cleanup_obdclass(void) 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; } diff --git a/lustre/obdclass/linux/linux-sysctl.c b/lustre/obdclass/linux/linux-sysctl.c index a7c5ac5..0a648a6 100644 --- a/lustre/obdclass/linux/linux-sysctl.c +++ b/lustre/obdclass/linux/linux-sysctl.c @@ -96,31 +96,6 @@ proc_memory_alloc(struct ctl_table *table, int write, void __user *buffer, } 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) { @@ -146,31 +121,6 @@ proc_mem_max(struct ctl_table *table, int write, void __user *buffer, } 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) { @@ -216,39 +166,6 @@ proc_max_dirty_pages_in_mb(struct ctl_table *table, int write, 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[] = { { @@ -293,14 +210,6 @@ 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, @@ -309,30 +218,12 @@ static struct ctl_table obd_table[] = { }, { 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", diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index e9e7697..00163bb 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -309,7 +309,7 @@ static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj, /* 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)); @@ -380,7 +380,7 @@ static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj, kunmap(page); /* NB see comment above regarding persistent pages */ - OBD_PAGE_FREE(page); + __free_page(page); } return rc; @@ -450,9 +450,9 @@ preprw_cleanup: 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); } @@ -522,20 +522,20 @@ static int echo_commitrw(const struct lu_env *env, int cmd, 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); @@ -632,13 +632,13 @@ struct obd_ops echo_obd_ops = { 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) @@ -650,7 +650,7 @@ 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; diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index c117b7a..c4909a1 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -2358,27 +2358,27 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa, 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); @@ -2400,7 +2400,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa, 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)); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 9ce5774..738dceb 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -5706,7 +5706,7 @@ static int osd_mount(const struct lu_env *env, 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); @@ -5821,7 +5821,7 @@ out_mnt: out: if (__page) - OBD_PAGE_FREE(__page); + __free_page(__page); return rc; } -- 1.8.3.1