diff --git a/lnet/libcfs/tracefile.c b/lnet/libcfs/tracefile.c
index aca4c41339f11fc1672908b3544dcc3abe18db56..f0c06e55942298e537b6b71bddb77cc6d82c3869 100644
--- a/lnet/libcfs/tracefile.c
+++ b/lnet/libcfs/tracefile.c
@@ -782,16 +782,16 @@ int trace_write_debug_mb(struct file *file, const char *buffer,
         max = simple_strtoul(string, NULL, 0);
         if (max == 0)
                 return -EINVAL;
-        max /= smp_num_cpus;
 
-        if (max * smp_num_cpus > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5) {
+        if (max > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5 || max >= 512) {
                 printk(KERN_ERR "Lustre: Refusing to set debug buffer size to "
-                       "%d MB, which is more than 80%% of physical RAM "
-                       "(%lu).\n", max * smp_num_cpus,
-                       (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
+                       "%dMB, which is more than 80%% of available RAM (%lu)\n",
+                       max, (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
                 return -EINVAL;
         }
 
+        max /= smp_num_cpus;
+
         for (i = 0; i < NR_CPUS; i++) {
                 struct trace_cpu_data *tcd;
                 tcd = &trace_data[i].tcd;
diff --git a/lustre/portals/libcfs/tracefile.c b/lustre/portals/libcfs/tracefile.c
index aca4c41339f11fc1672908b3544dcc3abe18db56..f0c06e55942298e537b6b71bddb77cc6d82c3869 100644
--- a/lustre/portals/libcfs/tracefile.c
+++ b/lustre/portals/libcfs/tracefile.c
@@ -782,16 +782,16 @@ int trace_write_debug_mb(struct file *file, const char *buffer,
         max = simple_strtoul(string, NULL, 0);
         if (max == 0)
                 return -EINVAL;
-        max /= smp_num_cpus;
 
-        if (max * smp_num_cpus > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5) {
+        if (max > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5 || max >= 512) {
                 printk(KERN_ERR "Lustre: Refusing to set debug buffer size to "
-                       "%d MB, which is more than 80%% of physical RAM "
-                       "(%lu).\n", max * smp_num_cpus,
-                       (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
+                       "%dMB, which is more than 80%% of available RAM (%lu)\n",
+                       max, (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
                 return -EINVAL;
         }
 
+        max /= smp_num_cpus;
+
         for (i = 0; i < NR_CPUS; i++) {
                 struct trace_cpu_data *tcd;
                 tcd = &trace_data[i].tcd;