From: Mr NeilBrown Date: Thu, 12 Mar 2020 19:52:56 +0000 (-0400) Subject: LU-9859 libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb() X-Git-Tag: 2.13.53~35 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=721ae5993285a2ac30a20e89079c38df88c134f0;hp=8b78a3ffb5220330f41b4fa8576a05c4e017cfb1 LU-9859 libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb() This function in used twice. In libcfs_debug_init() the usage is pointless as the only place that set libcfs_debug_mb ensures that it does not exceed the maximum. So checking again can never help. So open-code the small function into the only other place that it is used - in cfs_trace_set_debug_mb(), which is used to set libcfs_debug_mb. HPC machines are being deployed with 24 TiB or more memory. Change the variables uses to calculate the max_debug_mb to unsigned long to avoid a potential overflow and change 80 / 100 scaling factors to 4 / 5. Linux-commit: 5b5df84f3582b0e3a2ff70d49867bc3e03f67502 Change-Id: I497502bb7418e0b3d24b24c507029652bc9a9e55 Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/37829 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/debug.c b/libcfs/libcfs/debug.c index e5bff2e..de58fa6 100644 --- a/libcfs/libcfs/debug.c +++ b/libcfs/libcfs/debug.c @@ -443,11 +443,10 @@ int libcfs_debug_init(unsigned long bufsize) sizeof(libcfs_debug_file_path_arr)); } - /* - * If libcfs_debug_mb is set to an invalid value or uninitialized - * then just make the total buffers smp_num_cpus * TCD_MAX_PAGES + /* If libcfs_debug_mb is uninitialized then just make the + * total buffers smp_num_cpus * TCD_MAX_PAGES */ - if (max > cfs_trace_max_debug_mb() || max < num_possible_cpus()) { + if (max < num_possible_cpus()) { max = TCD_MAX_PAGES; } else { max = (max / num_possible_cpus()); diff --git a/libcfs/libcfs/linux-tracefile.c b/libcfs/libcfs/linux-tracefile.c index 5e39fc9..5e6b18b 100644 --- a/libcfs/libcfs/linux-tracefile.c +++ b/libcfs/libcfs/linux-tracefile.c @@ -259,10 +259,3 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, if (mask & D_TTY) cfs_tty_write_message(prefix, mask, buf); } - -int cfs_trace_max_debug_mb(void) -{ - int total_mb = (cfs_totalram_pages() >> (20 - PAGE_SHIFT)); - - return max(512, (total_mb * 80) / 100); -} diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 50d21d6..580c315 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -854,8 +854,9 @@ int cfs_trace_set_debug_mb(int mb) { int i; int j; - int pages; - int limit = cfs_trace_max_debug_mb(); + unsigned long pages; + unsigned long total_mb = (cfs_totalram_pages() >> (20 - PAGE_SHIFT)); + unsigned long limit = max_t(unsigned long, 512, (total_mb * 4) / 5); struct cfs_trace_cpu_data *tcd; if (mb < num_possible_cpus()) { @@ -865,7 +866,7 @@ int cfs_trace_set_debug_mb(int mb) } if (mb > limit) { - pr_warn("Lustre: %d MB is too large for debug buffer size, setting it to %d MB.\n", + pr_warn("Lustre: %d MB is too large for debug buffer size, setting it to %lu MB.\n", mb, limit); mb = limit; } diff --git a/libcfs/libcfs/tracefile.h b/libcfs/libcfs/tracefile.h index 7638bc0..30c5ae2 100644 --- a/libcfs/libcfs/tracefile.h +++ b/libcfs/libcfs/tracefile.h @@ -83,7 +83,6 @@ extern void libcfs_debug_dumplog_internal(void *arg); extern void libcfs_register_panic_notifier(void); extern void libcfs_unregister_panic_notifier(void); extern int libcfs_panic_in_progress; -extern int cfs_trace_max_debug_mb(void); #define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT)) #define TCD_STOCK_PAGES (TCD_MAX_PAGES)