From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 53A0B3E3C78 for ; Fri, 15 May 2026 07:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778829869; cv=none; b=SxgGZI3FaJNmJ87WxuBijukDIiq9UAhk3Rz0mK4RtqKJVtyF2ESFS8yCUT3tL4Jz7XaRZW63peJYCsCF2NUZ9QEVAQP2m/rCTf8B2gyxCnspeecJTxrCZRMpzlKd16o2qesHUBZypRRy8cGUGXao7SCLVmvC3ErVYPXV8D+Lo9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778829869; c=relaxed/simple; bh=2vmQeMXM7gBIce8Pu0p2uaCLfkQvG7dCKba8RPzCeY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TTJoyGrtptIU5X8jdcJPkp/kSEHzHcYieVO8xsoGFm9Olkj5rIT6F6AWYoaTabuSGBTDSxY4ZTrJqzEIKGLrawu4Qr9u4KryCVjnNdBF17JKNXxALeqnmRlMnYSV0d2GUZENt56wBtNj4LBgtN8k8O6qphvoUFlpVQEWOHwBRQU= 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=DHs8heJl; arc=none smtp.client-ip=117.135.210.4 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="DHs8heJl" 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 QWalTB7WrDJ6Z53lviHBLjV/r4fpMOX4vRdUEy52U=; b=DHs8heJlfJtLbU1Ajt /jDHVcfgRbc05FA0+XwxAFkcvTWoc7b526a9mQHwg1hoB1EIEPxmH+8i/PnV19lA RkVBTEzmMrp/JAO+ORknAT95+O1NvrPdY/zMQmrCnVdhkRRtvF/xJrsq+aTrJROl 33bOb2C44YP6jdKF/AlFWC2FM= Received: from ubuntu24-z.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wD3n+z4yQZqiwcBBg--.6646S2; Fri, 15 May 2026 15:23:37 +0800 (CST) From: ranxiaokai627@163.com To: ljs@kernel.org Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, hughd@google.com, leitao@debian.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ran.xiaokai@zte.com.cn, ranxiaokai627@163.com Subject: Re: [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string() Date: Fri, 15 May 2026 07:23:36 +0000 Message-ID: <20260515072336.53287-1-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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:_____wD3n+z4yQZqiwcBBg--.6646S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFWfuFW5WFy8Jr43Jw1kZrb_yoW8uFy5pr 9rJF1SyFy8Xr97Kr1IqF48Gryrt3yfJw48try5Ga4Sk3ZxXrnakr1v93yY9a4DAryIqw4I vr4UWasrXw1qy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUpa0kUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbC7hnMGWoGyfmI1AAA3i >On Wed, May 13, 2026 at 09:45:07AM +0000, ranxiaokai627@163.com wrote: >> From: Ran Xiaokai >> >> Inspired by commit 82d9ff648c6c ("mm: huge_memory: refactor >> anon_enabled_store() with set_anon_enabled_mode()"), refactor >> thpsize_shmem_enabled_store() using sysfs_match_string(). >> This eliminates the duplicated spin_lock/unlock(), set/clear_bit(), >> calls across all branches, reducing code duplication. > >> + /* Do not override huge allocation policy with non-PMD sized mTHP */ >> + if (mode == HUGE_SHMEM_ENABLED_INHERIT && >> + shmem_huge == SHMEM_HUGE_FORCE && !is_pmd_order(order)) >> + return -EINVAL; >> >> - if (ret > 0) { >> - int err = start_stop_khugepaged(); >> + spin_lock(&huge_shmem_orders_lock); >> + for (m = 0; m < ARRAY_SIZE(huge_shmem_orders_by_mode); m++) { >> + if (m == mode) >> + changed |= !__test_and_set_bit(order, huge_shmem_orders_by_mode[m]); >> + else >> + changed |= __test_and_clear_bit(order, huge_shmem_orders_by_mode[m]); >> + } >> + spin_unlock(&huge_shmem_orders_lock); > >You're copy/pasta'ing anon_enabled_store() but not the nicer refactoring that's >there. > >Please split this out like set_anon_enabled_mode() does. And put: > > static unsigned long *enabled_orders[] = { > &huge_shmem_orders_always, > &huge_shmem_orders_inherit, > &huge_shmem_orders_within_size, > &huge_shmem_orders_madvise, > }; > >At the start of it like that does also. > >Please don't reproduce the single letter var name though :) > Arrays huge_shmem_orders_by_mode are shared by both store() and show() in patch2, so we should keeping at file scope to avoid duplication, what do you think ? >> +}; > >> >> + if (changed) { >> + err = start_stop_khugepaged(); >> if (err) >> ret = err; > > >> + } else { >> + /* >> + * Recalculate watermarks even when the mode hasn't changed >> + * to preserve the legacy behavior, as this is always called >> + * inside start_stop_khugepaged(). >> + */ >> + set_recommended_min_free_kbytes(); >> } >> + >> return ret; > >return count; > >> } >> >> -- >> 2.25.1 >> >> > >Cheers, Lorenzo