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,