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);