On Mon, Jun 05, 2017 at 03:38:19PM -0700, Andrew Morton wrote: > It's better to just move memfmt() to the right place. After all, you > have revealed that it was in the wrong place, no? > > (Am a bit surprised that something as general as memfmt is private to > hugetlb.c) Oh, hey, look, memory management people and storage people have their own ideas about "general" code. Storage people have been using string_get_size() for a while. It feels a bit over-engineered to me, but since we already have it, we should use it. ---- 8< ---- Subject: [PATCH] Replace memfmt with string_get_size The hugetlb code has its own function to report human-readable sizes. Convert it to use the shared string_get_size function. This will lead to a minor difference in user visible output (MiB/GiB instead of MB/GB), but some would argue that's desirable anyway. Signed-off-by: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx> diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e5828875f7bb..7f2b7d9f1f45 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -20,6 +20,7 @@ #include <linux/slab.h> #include <linux/sched/signal.h> #include <linux/rmap.h> +#include <linux/string_helpers.h> #include <linux/swap.h> #include <linux/swapops.h> #include <linux/page-isolation.h> @@ -2207,26 +2208,15 @@ static void __init hugetlb_init_hstates(void) VM_BUG_ON(minimum_order == UINT_MAX); } -static char * __init memfmt(char *buf, unsigned long n) -{ - if (n >= (1UL << 30)) - sprintf(buf, "%lu GB", n >> 30); - else if (n >= (1UL << 20)) - sprintf(buf, "%lu MB", n >> 20); - else - sprintf(buf, "%lu KB", n >> 10); - return buf; -} - static void __init report_hugepages(void) { struct hstate *h; for_each_hstate(h) { char buf[32]; + string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); pr_info("HugeTLB registered %s page size, pre-allocated %ld pages\n", - memfmt(buf, huge_page_size(h)), - h->free_huge_pages); + buf, h->free_huge_pages); } } -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>