From patchwork Thu Jan 30 02:24:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 11357341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64C791395 for ; Thu, 30 Jan 2020 02:24:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3161D206F0 for ; Thu, 30 Jan 2020 02:24:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SbzWTHzD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3161D206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4D3736B02CB; Wed, 29 Jan 2020 21:24:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 484706B02CC; Wed, 29 Jan 2020 21:24:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 399B66B02CD; Wed, 29 Jan 2020 21:24:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 23F126B02CB for ; Wed, 29 Jan 2020 21:24:55 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B72A3181AEF0B for ; Thu, 30 Jan 2020 02:24:54 +0000 (UTC) X-FDA: 76432707708.18.name24_dbcf7e26e40d X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,gshan@redhat.com,::aarcange@redhat.com:akpm@linux-foundation.org:mhocko@suse.com,RULES_HIT:30012:30054,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: name24_dbcf7e26e40d X-Filterd-Recvd-Size: 9238 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 30 Jan 2020 02:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580351093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hlume1Bkov9GcHxw+RCAA4JqBi7KM0TW+o4ETBlwdwc=; b=SbzWTHzDXNUc3+1JllY2LduwaHw2pYQjqm5Lrj0jCUb8oaCTTa+ZVlzgDWDWzNs/nEXmzw HPEtJ1qYERgaysK4mh1/CvSW8GAvHkLH46DV0HhOeb/OSzOM4l6a8s4pfL9yltq1ETPcE3 IiC7wMD4ELRp9IeQ/rKSxgq6p/LlPHk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-Fk-tHHypO32GHQFQy55GBw-1; Wed, 29 Jan 2020 21:24:52 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6252D13E2; Thu, 30 Jan 2020 02:24:51 +0000 (UTC) Received: from localhost.localdomain.com (vpn2-54-25.bne.redhat.com [10.64.54.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29B7710027BA; Thu, 30 Jan 2020 02:24:48 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: aarcange@redhat.com, akpm@linux-foundation.org, mhocko@suse.com Subject: [PATCH 1/3] mm: Rework {enabled,defrag}_store() Date: Thu, 30 Jan 2020 13:24:39 +1100 Message-Id: <20200130022441.95488-2-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: Fk-tHHypO32GHQFQy55GBw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The suffix of the input buffer is truncated in {enabled,defrag}_store(). With that, the illegal settings can be accepted, as the following example shows. # cat /sys/kernel/mm/transparent_hugepage/enabled always [madvise] never # echo neveroff > /sys/kernel/mm/transparent_hugepage/enabled # cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never] This reworks {enabled,defrag}_store() to fix the issue and make the code a bit more extendible. With this applied, the illegal settings will be rejected: # echo neveroff > /sys/kernel/mm/transparent_hugepage/enabled sh: write error: Invalid argument Signed-off-by: Gavin Shan --- mm/huge_memory.c | 114 ++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a88093213674..7bd573f1631d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -160,6 +160,15 @@ static struct shrinker huge_zero_page_shrinker = { }; #ifdef CONFIG_SYSFS +static const char * const enabled_strings[] = { + "always", "madvise", "never" +}; +static unsigned int enabled_bits[] = { + TRANSPARENT_HUGEPAGE_FLAG, + TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + UINT_MAX +}; + static ssize_t enabled_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -175,29 +184,29 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - ssize_t ret = count; - - if (!memcmp("always", buf, - min(sizeof("always")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("madvise", buf, - min(sizeof("madvise")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("never", buf, - min(sizeof("never")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags); - } else - ret = -EINVAL; + int i, ret; - if (ret > 0) { - int err = start_stop_khugepaged(); - if (err) - ret = err; + for (i = 0; i < ARRAY_SIZE(enabled_strings); i++) { + if ((count - 1) == strlen(enabled_strings[i]) && + !memcmp(buf, enabled_strings[i], count - 1)) + break; } - return ret; + + if (i >= ARRAY_SIZE(enabled_strings)) + return -EINVAL; + + 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); + + ret = start_stop_khugepaged(); + if (ret) + return ret; + + return count; } static struct kobj_attribute enabled_attr = __ATTR(enabled, 0644, enabled_show, enabled_store); @@ -232,6 +241,17 @@ ssize_t single_hugepage_flag_store(struct kobject *kobj, return count; } +static const char * const defrag_strings[] = { + "always", "defer+madvise", "defer", "madvise", "never" +}; +static unsigned int defrag_bits[] = { + TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, + TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, + TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, + TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, + UINT_MAX +}; + static ssize_t defrag_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -250,39 +270,29 @@ static ssize_t defrag_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - if (!memcmp("always", buf, - min(sizeof("always")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("defer+madvise", buf, - min(sizeof("defer+madvise")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("defer", buf, - min(sizeof("defer")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("madvise", buf, - min(sizeof("madvise")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags); - } else if (!memcmp("never", buf, - min(sizeof("never")-1, count))) { - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags); - } else + int i; + + for (i = 0; i < ARRAY_SIZE(defrag_strings); i++) { + if ((count - 1) == strlen(defrag_strings[i]) && + !memcmp(buf, defrag_strings[i], count - 1)) + break; + } + + if (i >= ARRAY_SIZE(defrag_strings)) return -EINVAL; + clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, + &transparent_hugepage_flags); + clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, + &transparent_hugepage_flags); + clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, + &transparent_hugepage_flags); + clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, + &transparent_hugepage_flags); + + if (defrag_bits[i] != UINT_MAX) + set_bit(defrag_bits[i], &transparent_hugepage_flags); + return count; } static struct kobj_attribute defrag_attr = From patchwork Thu Jan 30 02:24:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 11357343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5CE9924 for ; Thu, 30 Jan 2020 02:24:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 82D5D206F0 for ; Thu, 30 Jan 2020 02:24:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NudHis7v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82D5D206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8F1176B02CD; Wed, 29 Jan 2020 21:24:58 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A4476B02CE; Wed, 29 Jan 2020 21:24:58 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DF8F6B02CF; Wed, 29 Jan 2020 21:24:58 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 6866C6B02CD for ; Wed, 29 Jan 2020 21:24:58 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 25FF02C68 for ; Thu, 30 Jan 2020 02:24:58 +0000 (UTC) X-FDA: 76432707876.24.books51_e3f93f987e04 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,gshan@redhat.com,::aarcange@redhat.com:akpm@linux-foundation.org:mhocko@suse.com,RULES_HIT:30054:30070,0,RBL:205.139.110.61:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: books51_e3f93f987e04 X-Filterd-Recvd-Size: 5172 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 30 Jan 2020 02:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580351097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o7TcrGbQV2/em+sZPRoQ+RXd5Eld8+e6PkSjXEyKhbw=; b=NudHis7vIVelj4USi8Z+wC6Hs/CjATGC71zj/cJ3teQuzYahlvVXcUcSRPTVgvTyRu95cb m78fQYFzQgX9cvoHn5S8j63WdpBhMO2jyWz7qyjm3Ux0TB+tZJRT4HgVXcsGaqnYE3Bnhr Yom9sGXxHUBW9RqowrUY2NZPl++ODUw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-6AXJJk_FPBuxLMbFWMNvCA-1; Wed, 29 Jan 2020 21:24:55 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C25D8010C7; Thu, 30 Jan 2020 02:24:54 +0000 (UTC) Received: from localhost.localdomain.com (vpn2-54-25.bne.redhat.com [10.64.54.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDE2A10027BA; Thu, 30 Jan 2020 02:24:52 +0000 (UTC) From: Gavin Shan 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 Message-Id: <20200130022441.95488-3-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 6AXJJk_FPBuxLMbFWMNvCA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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, From patchwork Thu Jan 30 02:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 11357345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A456924 for ; Thu, 30 Jan 2020 02:25:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2030206F0 for ; Thu, 30 Jan 2020 02:25:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ANnY7BeP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2030206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1518F6B02CF; Wed, 29 Jan 2020 21:25:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 103766B02D0; Wed, 29 Jan 2020 21:25:04 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03F9A6B02D1; Wed, 29 Jan 2020 21:25:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id E27B96B02CF for ; Wed, 29 Jan 2020 21:25:03 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 92545180AD806 for ; Thu, 30 Jan 2020 02:25:03 +0000 (UTC) X-FDA: 76432708086.11.turn82_f091644c6427 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,gshan@redhat.com,::aarcange@redhat.com:akpm@linux-foundation.org:mhocko@suse.com,RULES_HIT:30054,0,RBL:205.139.110.61:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: turn82_f091644c6427 X-Filterd-Recvd-Size: 4566 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Thu, 30 Jan 2020 02:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580351102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NTuYvEhtiFRB6YIjUS8XOHKPYlF/jy4sU2HwKlEZEcM=; b=ANnY7BePAbR5Zz4GD+9vmA47ZHQIYKaqDK/i21+eTvQYgrhE6bShZ+2Mm+dWCJFQguCBhg srmEj/ybQzWAbFnUiNNNAftdDLBE8xBC40uADV14MTEOu1GrfirMPxFTt72h+XGG6WuNMw YCtw8ZR0S6UXHqNSo00110N7Cz7abPI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-Vs_wVEAHMMi1ei1Cd4o6QQ-1; Wed, 29 Jan 2020 21:24:59 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70AE5107ACCA; Thu, 30 Jan 2020 02:24:58 +0000 (UTC) Received: from localhost.localdomain.com (vpn2-54-25.bne.redhat.com [10.64.54.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC4D61036B20; Thu, 30 Jan 2020 02:24:56 +0000 (UTC) From: Gavin Shan 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 Message-Id: <20200130022441.95488-4-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: Vs_wVEAHMMi1ei1Cd4o6QQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This reworks setup_transparent_hugepage() to used the declared arrays (enabled_{strings,bits}[]). Signed-off-by: Gavin Shan --- 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);