From: Gavin Shan <gshan@redhat.com>
To: linux-mm@kvack.org
Cc: aarcange@redhat.com, akpm@linux-foundation.org, mhocko@suse.com
Subject: [PATCH 2/3] mm: Rework {enabled,defrag}_show()
Date: Thu, 30 Jan 2020 13:24:40 +1100 [thread overview]
Message-ID: <20200130022441.95488-3-gshan@redhat.com> (raw)
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(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 7bd573f1631d..26b47ce8ea17 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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,
--
2.23.0
reply other threads:[~2020-01-30 2:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200130022441.95488-3-gshan@redhat.com \
--to=gshan@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox