@@ -172,12 +172,26 @@ static unsigned int enabled_bits[] = {
static ssize_t enabled_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
- if (test_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "[always] madvise never\n");
- else if (test_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "always [madvise] never\n");
- else
- return sprintf(buf, "always madvise [never]\n");
+ char *p = buf;
+ bool found = false;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(enabled_bits); i++) {
+ if (enabled_bits[i] == UINT_MAX) {
+ p += sprintf(p, found ? "%s\n" : "[%s]\n",
+ enabled_strings[i]);
+ continue;
+ }
+
+ if (test_bit(enabled_bits[i], &transparent_hugepage_flags)) {
+ p += sprintf(p, "[%s] ", enabled_strings[i]);
+ found = true;
+ } else {
+ p += sprintf(p, "%s ", enabled_strings[i]);
+ }
+ }
+
+ return p - buf;
}
static ssize_t enabled_store(struct kobject *kobj,
@@ -255,15 +269,26 @@ static unsigned int defrag_bits[] = {
static ssize_t defrag_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
- if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "[always] defer defer+madvise madvise never\n");
- if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "always [defer] defer+madvise madvise never\n");
- if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "always defer [defer+madvise] madvise never\n");
- if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags))
- return sprintf(buf, "always defer defer+madvise [madvise] never\n");
- return sprintf(buf, "always defer defer+madvise madvise [never]\n");
+ char *p = buf;
+ bool found = false;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(defrag_bits); i++) {
+ if (defrag_bits[i] == UINT_MAX) {
+ p += sprintf(p, found ? "%s\n" : "[%s]\n",
+ defrag_strings[i]);
+ continue;
+ }
+
+ if (test_bit(defrag_bits[i], &transparent_hugepage_flags)) {
+ p += sprintf(p, "[%s] ", defrag_strings[i]);
+ found = true;
+ } else {
+ p += sprintf(p, "%s ", defrag_strings[i]);
+ }
+ }
+
+ return p - buf;
}
static ssize_t defrag_store(struct kobject *kobj,
This reworks {enabled,defrag}_show() to reuse the arrays declared in previous patch, so that {enabled,defrag}_{show,store}() looks similar in structure. Signed-off-by: Gavin Shan <gshan@redhat.com> --- mm/huge_memory.c | 55 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 15 deletions(-)