From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4A013859FC for ; Wed, 13 May 2026 09:46:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778665570; cv=none; b=M8oJW7BVqAOuF356xedd8zHRAbk9KptNvtyPv38YzS2oANSlYNz+iN3iKDR91Zn6IwcICb9yDlzQPGZGmc38/lzIpvWgQqlPZhoBT/0vAQ+rFrNg5PghCAeyqsQsl5w4zmaZ1yTFCsEBus8kCPnifJ1j7mZ+ek0MBhHpCTNpWOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778665570; c=relaxed/simple; bh=+WYbvfYvW464BG9XXtSL2qe8bqF0LcumRV1RlzKJJQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lkSMCe2nu9MksJnK5/Bfbbghid722u06B0LhnacFJeAB0s6FEpBYOR7QZIHkLbTSeHRwbqeMhpb3sR/e+rdvV8W8YBRPFv5N3Z0udQw3/ojGeEYcelxxhFsU1gAkd3oGVGITsFR61YUEQsIuRQHK0qWZFS5ViKu3we5pR/ANWoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=PNAu9Vy+; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="PNAu9Vy+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=8b vOMnKJfXNE5YsXe8vkEmmolNaOOCgms3KMkV0kHLM=; b=PNAu9Vy+2P2ttq0AjQ f3XqpCAZ02qoluw6QAjTqhgvWXZL4yZBQrATb4ZqbkYv7NBprx2BFkbXFB5OUUOD RNNDwvmMPYWJWiw4JKoAIQ8LyX8Sq6kzweVZ5nznFv8tKEOp/JTp+sxhtL5YQvqz dfu9+POWf0kOyc6S6tuK57yIo= Received: from ubuntu24-z.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgBXXvImSARqv3FNDg--.31S3; Wed, 13 May 2026 17:45:16 +0800 (CST) From: ranxiaokai627@163.com To: hughd@google.com, baolin.wang@linux.alibaba.com, akpm@linux-foundation.org Cc: leitao@debian.org, ljs@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ran.xiaokai@zte.com.cn, ranxiaokai627@163.com Subject: [PATCH v2 2/2] mm: huge_memory: refactor thpsize_shmem_enabled_show() with helper arrays Date: Wed, 13 May 2026 09:45:08 +0000 Message-ID: <20260513094508.50888-2-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260513094508.50888-1-ranxiaokai627@163.com> References: <20260513094508.50888-1-ranxiaokai627@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:PygvCgBXXvImSARqv3FNDg--.31S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw4UZryfZryfXFW5Xr4xJFb_yoW8uFyfpF Z3C3sayrW8JFykt3yxWF48tryYgr4fJw15trZrJaySvwn8Jr1qvF92k34rZa4UA3yfWw4S gry8WF9rGFWDtr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piqjg7UUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbC7Qy4BWoESCy46wAA3F From: Ran Xiaokai Replace the hardcoded if/else chain of test_bit() calls and string literals in thpsize_shmem_enabled_show() with a loop over huge_shmem_orders_by_mode[] and huge_shmem_enabled_mode_strings[] arrays. This makes thpsize_shmem_enabled_show() consistent with thpsize_shmem_enabled_store() and eliminates duplicated mode name strings. Signed-off-by: Ran Xiaokai --- mm/shmem.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 60cb10854f11..086762e6de71 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5553,20 +5553,30 @@ static ssize_t thpsize_shmem_enabled_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { int order = to_thpsize(kobj)->order; - const char *output; - - if (test_bit(order, &huge_shmem_orders_always)) - output = "[always] inherit within_size advise never"; - else if (test_bit(order, &huge_shmem_orders_inherit)) - output = "always [inherit] within_size advise never"; - else if (test_bit(order, &huge_shmem_orders_within_size)) - output = "always inherit [within_size] advise never"; - else if (test_bit(order, &huge_shmem_orders_madvise)) - output = "always inherit within_size [advise] never"; - else - output = "always inherit within_size advise [never]"; + int active = HUGE_SHMEM_ENABLED_NEVER; + int len = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(huge_shmem_orders_by_mode); i++) { + if (test_bit(order, huge_shmem_orders_by_mode[i])) { + active = i; + break; + } + } + + for (i = 0; i < ARRAY_SIZE(huge_shmem_enabled_mode_strings); i++) { + if (i == active) + len += sysfs_emit_at(buf, len, "[%s] ", + huge_shmem_enabled_mode_strings[i]); + else + len += sysfs_emit_at(buf, len, "%s ", + huge_shmem_enabled_mode_strings[i]); + } + + /* Replace trailing space with newline */ + buf[len - 1] = '\n'; - return sysfs_emit(buf, "%s\n", output); + return len; } static ssize_t thpsize_shmem_enabled_store(struct kobject *kobj, -- 2.25.1