From: Gavin Shan <gshan@redhat.com>
To: linux-mm@kvack.org
Cc: aarcange@redhat.com, akpm@linux-foundation.org, mhocko@suse.com
Subject: [PATCH 3/3] mm: Rework setup_transparent_hugepage()
Date: Thu, 30 Jan 2020 13:24:41 +1100 [thread overview]
Message-ID: <20200130022441.95488-4-gshan@redhat.com> (raw)
This reworks setup_transparent_hugepage() to used the declared arrays
(enabled_{strings,bits}[]).
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
mm/huge_memory.c | 49 ++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 26b47ce8ea17..228349f4f937 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -159,7 +159,6 @@ static struct shrinker huge_zero_page_shrinker = {
.seeks = DEFAULT_SEEKS,
};
-#ifdef CONFIG_SYSFS
static const char * const enabled_strings[] = {
"always", "madvise", "never"
};
@@ -169,6 +168,7 @@ static unsigned int enabled_bits[] = {
UINT_MAX
};
+#ifdef CONFIG_SYSFS
static ssize_t enabled_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -495,32 +495,31 @@ subsys_initcall(hugepage_init);
static int __init setup_transparent_hugepage(char *str)
{
- int ret = 0;
+ int i;
+
if (!str)
- goto out;
- if (!strcmp(str, "always")) {
- set_bit(TRANSPARENT_HUGEPAGE_FLAG,
- &transparent_hugepage_flags);
- clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
- &transparent_hugepage_flags);
- ret = 1;
- } else if (!strcmp(str, "madvise")) {
- clear_bit(TRANSPARENT_HUGEPAGE_FLAG,
- &transparent_hugepage_flags);
- set_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
- &transparent_hugepage_flags);
- ret = 1;
- } else if (!strcmp(str, "never")) {
- clear_bit(TRANSPARENT_HUGEPAGE_FLAG,
- &transparent_hugepage_flags);
- clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
- &transparent_hugepage_flags);
- ret = 1;
+ goto error;
+
+ for (i = 0; i < ARRAY_SIZE(enabled_strings); i++) {
+ if (!strcmp(str, enabled_strings[i]))
+ break;
}
-out:
- if (!ret)
- pr_warn("transparent_hugepage= cannot parse, ignored\n");
- return ret;
+
+ if (i >= ARRAY_SIZE(enabled_strings))
+ goto error;
+
+ clear_bit(TRANSPARENT_HUGEPAGE_FLAG,
+ &transparent_hugepage_flags);
+ clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
+ &transparent_hugepage_flags);
+ if (enabled_bits[i] != UINT_MAX)
+ set_bit(enabled_bits[i], &transparent_hugepage_flags);
+
+ return 1;
+
+error:
+ pr_warn("transparent_hugepage= cannot parse, ignored\n");
+ return 0;
}
__setup("transparent_hugepage=", setup_transparent_hugepage);
--
2.23.0
reply other threads:[~2020-01-30 2:25 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-4-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