From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2012D47B43A for ; Fri, 15 May 2026 11:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778844866; cv=none; b=sDVcVP5guLGLUstOm1WrH2pHBdWIDBnAKwEYXejuupGWN6AsS7ShiSiFIY3avtCbIl3L/a/N+wZpD0DJyDWXUOYnmov4BUl+XcAT91PZnEV/ahUGbQeSWFsfBXxDPGDMEHW/IoKnap3LCqmOFIxu/v3Wn+I284l636XXFTfA75w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778844866; c=relaxed/simple; bh=dV3f4iOgUU/KkC0ZeemZIzRwGsXHk9M9r9YxVxZg+k4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CKRW5xPz0cS201wPJ0oWuAM/dy9gItRr+bU8qn3qvw4vnfZeToqj7tmyqGMuu8BxUBo3AIDkoa/BXgcuBoMrJEOAVaR/wgcY56SdKNpwhqPnAeDsMWWYz9mUJqK0z+2zfuE7ftWX4arTY+YgAgLhbb8YZGYId+YGpYdBAnucCjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ia2ne/27; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ia2ne/27" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A0CC2BCB0; Fri, 15 May 2026 11:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778844866; bh=dV3f4iOgUU/KkC0ZeemZIzRwGsXHk9M9r9YxVxZg+k4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ia2ne/27anPGvbhjlp0aCfY48oj2uM+eBY81Y61x6na3lMWrls36u2Tazi5d8hFZ1 Qx9uhpUDWfDZ/R8AO/iDzRHWzmjE+6/3kUIhbquezsKrmGSSJ9vGbX8//fB4KffcQE 5aprOJLm/B/50MLso3xMIOeWLrgrpF0yB2LI2+qqtlRCiahvgrPF8M1dnFB0IqQrTh BtFG0vQHugDsmThgCRS6xG9YdkXkniJ5qa36UcTUq5CrvJAJNmnXHc6YU3CCtpeHu3 d+DNOZZTxEY4YeSSVceQMS2HhtXWyw3btRKdzX+7dsOc97dHjWEilYzJyAhuj1L/Bv zp5HMazgY5eJQ== Date: Fri, 15 May 2026 12:34:21 +0100 From: Lorenzo Stoakes To: ranxiaokai627@163.com 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 Subject: Re: [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string() Message-ID: References: <20260515072336.53287-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260515072336.53287-1-ranxiaokai627@163.com> On Fri, May 15, 2026 at 07:23:36AM +0000, ranxiaokai627@163.com wrote: > >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 ? Ah yeah ok, in that case keep that separated out, but the other points in the review stand! Thanks :) > > >> +}; > > > >> > >> + 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 >