Linux-mm Archive mirror
 help / color / mirror / Atom feed
*  [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input
@ 2024-05-11  6:40 xu.xin16
  2024-05-11 16:05 ` Matthew Wilcox
  2024-05-13 15:58 ` David Hildenbrand
  0 siblings, 2 replies; 4+ messages in thread
From: xu.xin16 @ 2024-05-11  6:40 UTC (permalink / raw
  To: akpm; +Cc: david, willy, shy828301, linux-kernel, linux-mm

From: Ran Xiaokai <ran.xiaokai@zte.com.cn>

Since sysfs_streq() only performs a simple memory comparison operation
and will not introduce any sleepable operation, So there is no
need to drop the lock when parsing input. Remove redundant lock
and unlock operations to make code cleaner.

Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
 mm/huge_memory.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 89f58c7603b2..87123a87cb21 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -478,32 +478,26 @@ static ssize_t thpsize_enabled_store(struct kobject *kobj,
 	int order = to_thpsize(kobj)->order;
 	ssize_t ret = count;

+	spin_lock(&huge_anon_orders_lock);
 	if (sysfs_streq(buf, "always")) {
-		spin_lock(&huge_anon_orders_lock);
 		clear_bit(order, &huge_anon_orders_inherit);
 		clear_bit(order, &huge_anon_orders_madvise);
 		set_bit(order, &huge_anon_orders_always);
-		spin_unlock(&huge_anon_orders_lock);
 	} else if (sysfs_streq(buf, "inherit")) {
-		spin_lock(&huge_anon_orders_lock);
 		clear_bit(order, &huge_anon_orders_always);
 		clear_bit(order, &huge_anon_orders_madvise);
 		set_bit(order, &huge_anon_orders_inherit);
-		spin_unlock(&huge_anon_orders_lock);
 	} else if (sysfs_streq(buf, "madvise")) {
-		spin_lock(&huge_anon_orders_lock);
 		clear_bit(order, &huge_anon_orders_always);
 		clear_bit(order, &huge_anon_orders_inherit);
 		set_bit(order, &huge_anon_orders_madvise);
-		spin_unlock(&huge_anon_orders_lock);
 	} else if (sysfs_streq(buf, "never")) {
-		spin_lock(&huge_anon_orders_lock);
 		clear_bit(order, &huge_anon_orders_always);
 		clear_bit(order, &huge_anon_orders_inherit);
 		clear_bit(order, &huge_anon_orders_madvise);
-		spin_unlock(&huge_anon_orders_lock);
 	} else
 		ret = -EINVAL;
+	spin_unlock(&huge_anon_orders_lock);

 	return ret;
 }
-- 
2.15.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re:  [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input
  2024-05-11  6:40 [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input xu.xin16
@ 2024-05-11 16:05 ` Matthew Wilcox
  2024-05-11 21:35   ` Andrew Morton
  2024-05-13 15:58 ` David Hildenbrand
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2024-05-11 16:05 UTC (permalink / raw
  To: xu.xin16; +Cc: akpm, david, shy828301, linux-kernel, linux-mm

On Sat, May 11, 2024 at 02:40:48PM +0800, xu.xin16@zte.com.cn wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> Since sysfs_streq() only performs a simple memory comparison operation
> and will not introduce any sleepable operation, So there is no
> need to drop the lock when parsing input. Remove redundant lock
> and unlock operations to make code cleaner.

i disagree that it makes the code cleaner.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re:  [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input
  2024-05-11 16:05 ` Matthew Wilcox
@ 2024-05-11 21:35   ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2024-05-11 21:35 UTC (permalink / raw
  To: Matthew Wilcox
  Cc: xu.xin16, david, shy828301, linux-kernel, linux-mm, Muchun Song


(cc Muchun)

On Sat, 11 May 2024 17:05:13 +0100 Matthew Wilcox <willy@infradead.org> wrote:

> On Sat, May 11, 2024 at 02:40:48PM +0800, xu.xin16@zte.com.cn wrote:
> > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> > 
> > Since sysfs_streq() only performs a simple memory comparison operation
> > and will not introduce any sleepable operation, So there is no
> > need to drop the lock when parsing input. Remove redundant lock
> > and unlock operations to make code cleaner.
> 
> i disagree that it makes the code cleaner.

Oh.  Why is that?  The end result looks nice to me and saves a bit of
.text.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input
  2024-05-11  6:40 [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input xu.xin16
  2024-05-11 16:05 ` Matthew Wilcox
@ 2024-05-13 15:58 ` David Hildenbrand
  1 sibling, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2024-05-13 15:58 UTC (permalink / raw
  To: xu.xin16, akpm; +Cc: willy, shy828301, linux-kernel, linux-mm

On 11.05.24 08:40, xu.xin16@zte.com.cn wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> Since sysfs_streq() only performs a simple memory comparison operation
> and will not introduce any sleepable operation, So there is no
> need to drop the lock when parsing input. Remove redundant lock
> and unlock operations to make code cleaner.
> 
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
>   mm/huge_memory.c | 10 ++--------
>   1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 89f58c7603b2..87123a87cb21 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -478,32 +478,26 @@ static ssize_t thpsize_enabled_store(struct kobject *kobj,
>   	int order = to_thpsize(kobj)->order;
>   	ssize_t ret = count;
> 
> +	spin_lock(&huge_anon_orders_lock);
>   	if (sysfs_streq(buf, "always")) {
> -		spin_lock(&huge_anon_orders_lock);
>   		clear_bit(order, &huge_anon_orders_inherit);
>   		clear_bit(order, &huge_anon_orders_madvise);
>   		set_bit(order, &huge_anon_orders_always);
> -		spin_unlock(&huge_anon_orders_lock);
>   	} else if (sysfs_streq(buf, "inherit")) {
> -		spin_lock(&huge_anon_orders_lock);
>   		clear_bit(order, &huge_anon_orders_always);
>   		clear_bit(order, &huge_anon_orders_madvise);
>   		set_bit(order, &huge_anon_orders_inherit);
> -		spin_unlock(&huge_anon_orders_lock);
>   	} else if (sysfs_streq(buf, "madvise")) {
> -		spin_lock(&huge_anon_orders_lock);
>   		clear_bit(order, &huge_anon_orders_always);
>   		clear_bit(order, &huge_anon_orders_inherit);
>   		set_bit(order, &huge_anon_orders_madvise);
> -		spin_unlock(&huge_anon_orders_lock);
>   	} else if (sysfs_streq(buf, "never")) {
> -		spin_lock(&huge_anon_orders_lock);
>   		clear_bit(order, &huge_anon_orders_always);
>   		clear_bit(order, &huge_anon_orders_inherit);
>   		clear_bit(order, &huge_anon_orders_madvise);
> -		spin_unlock(&huge_anon_orders_lock);
>   	} else
>   		ret = -EINVAL;
> +	spin_unlock(&huge_anon_orders_lock);
> 
>   	return ret;
>   }

No strong opinion

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-13 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-11  6:40 [PATCH linux-next] mm/huge_memory: remove redundant locking when parsing THP sysfs input xu.xin16
2024-05-11 16:05 ` Matthew Wilcox
2024-05-11 21:35   ` Andrew Morton
2024-05-13 15:58 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).