From 02a976b13d16fac7708fbd1827fcc6129b7e20f3 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 24 Sep 2013 11:55:44 -0400 Subject: [PATCH] LU-3974 libcfs: replace num_physpages with totalram_pages Currently lustre uses an exported kernel variable num_physpages but this variable includes also non-ram pages and is not memory hotplug support aware. Also in kernels 3.11 and above this variable is no longer exported. The exported variable totalram_pages handles the the limitations of num_physpages plus its avaliable in all Lustre supported kernels. Signed-off-by: James Simmons Change-Id: I021fbbd99b2c8e538fc0357a676834e26d690702 Reviewed-on: http://review.whamcloud.com/7726 Reviewed-by: Bob Glossman Reviewed-by: Dmitry Eremin Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Peng Tao --- libcfs/include/libcfs/darwin/darwin-mem.h | 6 +++--- libcfs/include/libcfs/linux/linux-mem.h | 4 ++-- libcfs/include/libcfs/winnt/portals_utils.h | 4 ++-- libcfs/libcfs/linux/linux-tracefile.c | 2 +- libcfs/libcfs/winnt/winnt-tracefile.c | 4 ++-- lustre/include/liblustre.h | 4 ++-- lustre/ldlm/ldlm_lib.c | 10 +++++----- lustre/llite/lproc_llite.c | 8 ++++---- lustre/obdclass/class_obd.c | 6 +++--- lustre/obdclass/linux/linux-sysctl.c | 6 +++--- lustre/obdclass/lu_object.c | 2 +- lustre/osc/lproc_osc.c | 2 +- lustre/ptlrpc/lproc_ptlrpc.c | 2 +- lustre/ptlrpc/sec_bulk.c | 4 ++-- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libcfs/include/libcfs/darwin/darwin-mem.h b/libcfs/include/libcfs/darwin/darwin-mem.h index 326268b..b1a6cd5 100644 --- a/libcfs/include/libcfs/darwin/darwin-mem.h +++ b/libcfs/include/libcfs/darwin/darwin-mem.h @@ -263,9 +263,9 @@ void kmem_cache_free(struct kmem_cache *, void *); /* * Misc */ -/* XXX Liang: num_physpages... fix me */ -#define num_physpages (64 * 1024) -#define NUM_CACHEPAGES num_physpages +/* XXX Liang: totalram_pages... fix me */ +#define totalram_pages (64 * 1024) +#define NUM_CACHEPAGES totalram_pages #define DECL_MMSPACE #define MMSPACE_OPEN do {} while (0) diff --git a/libcfs/include/libcfs/linux/linux-mem.h b/libcfs/include/libcfs/linux/linux-mem.h index 3554dfe..c8861d0 100644 --- a/libcfs/include/libcfs/linux/linux-mem.h +++ b/libcfs/include/libcfs/linux/linux-mem.h @@ -69,9 +69,9 @@ #if BITS_PER_LONG == 32 /* limit to lowmem on 32-bit systems */ #define NUM_CACHEPAGES \ - min(num_physpages, 1UL << (30 - PAGE_CACHE_SHIFT) * 3 / 4) + min(totalram_pages, 1UL << (30 - PAGE_CACHE_SHIFT) * 3 / 4) #else -#define NUM_CACHEPAGES num_physpages +#define NUM_CACHEPAGES totalram_pages #endif /* diff --git a/libcfs/include/libcfs/winnt/portals_utils.h b/libcfs/include/libcfs/winnt/portals_utils.h index 79f7bbf..39ab41f 100644 --- a/libcfs/include/libcfs/winnt/portals_utils.h +++ b/libcfs/include/libcfs/winnt/portals_utils.h @@ -297,8 +297,8 @@ clear_user(void __user *to, unsigned long n) 0 \ ) -#define num_physpages (64 * 1024) -#define NUM_CACHEPAGES num_physpages +#define totalram_pages (64 * 1024) +#define NUM_CACHEPAGES totalram_pages #else diff --git a/libcfs/libcfs/linux/linux-tracefile.c b/libcfs/libcfs/linux/linux-tracefile.c index 0266fc9..c67103b 100644 --- a/libcfs/libcfs/linux/linux-tracefile.c +++ b/libcfs/libcfs/linux/linux-tracefile.c @@ -269,7 +269,7 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, int cfs_trace_max_debug_mb(void) { - int total_mb = (num_physpages >> (20 - PAGE_SHIFT)); + int total_mb = (totalram_pages >> (20 - PAGE_SHIFT)); return MAX(512, (total_mb * 80)/100); } diff --git a/libcfs/libcfs/winnt/winnt-tracefile.c b/libcfs/libcfs/winnt/winnt-tracefile.c index 3ff5405..d93cde9 100644 --- a/libcfs/libcfs/winnt/winnt-tracefile.c +++ b/libcfs/libcfs/winnt/winnt-tracefile.c @@ -217,7 +217,7 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, int cfs_trace_max_debug_mb(void) { - int total_mb = (num_physpages >> (20 - PAGE_CACHE_SHIFT)); - + int total_mb = (totalram_pages >> (20 - PAGE_CACHE_SHIFT)); + return MAX(512, (total_mb * 80)/100); } diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h index dbc4c3c..4aa78f0e 100644 --- a/lustre/include/liblustre.h +++ b/lustre/include/liblustre.h @@ -167,8 +167,8 @@ void cfs_get_random_bytes(void *ptr, int size); /* memory */ /* memory size: used for some client tunables */ -#define num_physpages (256 * 1024) /* 1GB */ -#define NUM_CACHEPAGES num_physpages +#define totalram_pages (256 * 1024) /* 1GB */ +#define NUM_CACHEPAGES totalram_pages /* VFS stuff */ diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index a233c3d..7e4da6f 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -343,8 +343,8 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg) cli->cl_avail_grant = 0; /* FIXME: Should limit this for the sum of all cl_dirty_max. */ cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024; - if (cli->cl_dirty_max >> PAGE_CACHE_SHIFT > num_physpages / 8) - cli->cl_dirty_max = num_physpages << (PAGE_CACHE_SHIFT - 3); + if (cli->cl_dirty_max >> PAGE_CACHE_SHIFT > totalram_pages / 8) + cli->cl_dirty_max = totalram_pages << (PAGE_CACHE_SHIFT - 3); CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters); CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list); CFS_INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list); @@ -394,11 +394,11 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg) if (!strcmp(name, LUSTRE_MDC_NAME)) { cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT; - } else if (num_physpages >> (20 - PAGE_CACHE_SHIFT) <= 128 /* MB */) { + } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 128 /* MB */) { cli->cl_max_rpcs_in_flight = 2; - } else if (num_physpages >> (20 - PAGE_CACHE_SHIFT) <= 256 /* MB */) { + } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 256 /* MB */) { cli->cl_max_rpcs_in_flight = 3; - } else if (num_physpages >> (20 - PAGE_CACHE_SHIFT) <= 512 /* MB */) { + } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 512 /* MB */) { cli->cl_max_rpcs_in_flight = 4; } else { if (osc_on_mdt(obddev->obd_name)) diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 4b86d48..18b8cf3 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -293,10 +293,10 @@ static int ll_wr_max_readahead_mb(struct file *file, const char *buffer, if (rc) return rc; - if (pages_number < 0 || pages_number > num_physpages / 2) { + if (pages_number < 0 || pages_number > totalram_pages / 2) { /* 1/2 of RAM */ CERROR("can't set file readahead more than %lu MB\n", - num_physpages >> (20 - PAGE_CACHE_SHIFT + 1)); + totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1)); return -ERANGE; } @@ -439,10 +439,10 @@ static int ll_wr_max_cached_mb(struct file *file, const char *buffer, if (rc) RETURN(rc); - if (pages_number < 0 || pages_number > num_physpages) { + if (pages_number < 0 || pages_number > totalram_pages) { CERROR("%s: can't set max cache more than %lu MB\n", ll_get_fsname(sb, NULL, 0), - num_physpages >> (20 - PAGE_CACHE_SHIFT)); + totalram_pages >> (20 - PAGE_CACHE_SHIFT)); RETURN(-ERANGE); } diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 7df4950..8d2c1ac 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -588,10 +588,10 @@ int init_obdclass(void) /* Default the dirty page cache cap to 1/2 of system memory. * For clients with less memory, a larger fraction is needed * for other purposes (mostly for BGL). */ - if (num_physpages <= 512 << (20 - PAGE_CACHE_SHIFT)) - obd_max_dirty_pages = num_physpages / 4; + if (totalram_pages <= 512 << (20 - PAGE_CACHE_SHIFT)) + obd_max_dirty_pages = totalram_pages / 4; else - obd_max_dirty_pages = num_physpages / 2; + obd_max_dirty_pages = totalram_pages / 2; err = obd_init_caches(); if (err) diff --git a/lustre/obdclass/linux/linux-sysctl.c b/lustre/obdclass/linux/linux-sysctl.c index f6c8ecf..25c7179 100644 --- a/lustre/obdclass/linux/linux-sysctl.c +++ b/lustre/obdclass/linux/linux-sysctl.c @@ -228,12 +228,12 @@ int LL_PROC_PROTO(proc_max_dirty_pages_in_mb) 1 << (20 - PAGE_CACHE_SHIFT)); /* Don't allow them to let dirty pages exceed 90% of system * memory and set a hard minimum of 4MB. */ - if (obd_max_dirty_pages > ((num_physpages / 10) * 9)) { + if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) { CERROR("Refusing to set max dirty pages to %u, which " "is more than 90%% of available RAM; setting " "to %lu\n", obd_max_dirty_pages, - ((num_physpages / 10) * 9)); - obd_max_dirty_pages = ((num_physpages / 10) * 9); + ((totalram_pages / 10) * 9)); + obd_max_dirty_pages = ((totalram_pages / 10) * 9); } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) { obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT); } diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 31c4d72..9842ab2 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -908,7 +908,7 @@ static int lu_htable_order(void) * * Size of lu_object is (arbitrary) taken as 1K (together with inode). */ - cache_size = num_physpages; + cache_size = totalram_pages; #if BITS_PER_LONG == 32 /* limit hashtable size for lowmem systems to low RAM */ diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 986d563..b43dd5b 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -147,7 +147,7 @@ static int osc_wr_max_dirty_mb(struct file *file, const char *buffer, if (pages_number <= 0 || pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) || - pages_number > num_physpages / 4) /* 1/4 of RAM */ + pages_number > totalram_pages / 4) /* 1/4 of RAM */ return -ERANGE; client_obd_list_lock(&cli->cl_loi_list_lock); diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index da5ff2a..897a157 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -310,7 +310,7 @@ ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer, * far. */ bufpages = (svc->srv_buf_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; - if (val > num_physpages/(2 * bufpages)) + if (val > totalram_pages/(2 * bufpages)) return -ERANGE; spin_lock(&svc->srv_lock); diff --git a/lustre/ptlrpc/sec_bulk.c b/lustre/ptlrpc/sec_bulk.c index c4f45aa..504353b 100644 --- a/lustre/ptlrpc/sec_bulk.c +++ b/lustre/ptlrpc/sec_bulk.c @@ -163,7 +163,7 @@ int sptlrpc_proc_read_enc_pool(char *page, char **start, off_t off, int count, "max waitqueue depth: %u\n" "max wait time: "CFS_TIME_T"/%u\n" , - num_physpages, + totalram_pages, PAGES_PER_POOL, page_pools.epp_max_pages, page_pools.epp_max_pools, @@ -711,7 +711,7 @@ 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 = totalram_pages / 8; page_pools.epp_max_pools = npages_to_npools(page_pools.epp_max_pages); init_waitqueue_head(&page_pools.epp_waitq); -- 1.8.3.1