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 C283938E8BA for ; Tue, 12 May 2026 12:06:41 +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=1778587605; cv=none; b=RcC7WjX/R9aTTX/kxoFpfL4Q0o251GhSdCpG2+MT8IKvciM57TGn3qIvDomee/4mAUahuC7ulnp3rF/G0FLXm12iGQD9KFXzPWzoF0bBnxVSr5dcGr8POgiRSMEstfHECm4e/sR0G/6hQ5iXnJmXXODLrdRyjorpBcjNIiTyZho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778587605; c=relaxed/simple; bh=p3+DyiijQjVhVyNhV2lILmHdgb9BJal/J/8n1eEzPmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJQ8UzyCrOkyEV5IDSu/7j6OKVBKdtY8iG43h894UOjz/3QjD+eaGZNUu0puozHTDaqMySWRDVwwycpJC1maUbFpCObWDnTaH1kZ/TGDLcyAq/rwy5f6U0OZUaycSD3lbvT6KJxar8I92l5SWkFtcwqyi5diSak95o5H5ba8LB4= 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=HfJ0/TXF; 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="HfJ0/TXF" 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=he 20vJhXuk16wvij8k8XvtMItmz4w87BGjWhCU027KM=; b=HfJ0/TXFolGO8ZyuCO NiyFcwRLLLuaoh+FwqBbZ03eO8/qD6SMe7n1FVbR2sQCixFPkkY8lYI9bWh9JuyR +2a38Wa01ZAj1IwLoC9cK6xYOGglhcibChSiqoKMLTeF3K+mbVRLHUPklK60uLON 2dt0VOhHufZ3U05p6J5hRFL4c= Received: from ubuntu24-z.. (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgCncianFwNqsj3nEA--.14956S3; Tue, 12 May 2026 20:06:07 +0800 (CST) From: ranxiaokai627@163.com To: hughd@google.com, baolin.wang@linux.alibaba.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ran.xiaokai@zte.com.cn, ranxiaokai627@163.com Subject: [PATCH 2/2] mm: huge_memory: refactor thpsize_shmem_enabled_show() with helper arrays Date: Tue, 12 May 2026 12:05:56 +0000 Message-ID: <20260512120557.49995-2-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260512120557.49995-1-ranxiaokai627@163.com> References: <20260512120557.49995-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:PSgvCgCncianFwNqsj3nEA--.14956S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw4UZryfZryfXFW5Xr4xJFb_yoW8uFyfpF yfC3sayrW8JFykt3yxWF48tryYqr4fJw15trW7JayfZwn8Jr1qvF92k34rZa4UA393Ww4a gry8WF9rGFWDtr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piPfQJUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbC7Q9MmGoDF69uKgAA3j 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 0cc7872cc576..93fb0a5dca5c 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