public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage()
@ 2023-05-16  9:50 Alexey Romanov
  2023-05-16  9:50 ` [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK Alexey Romanov
  2023-05-16  9:53 ` [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Sergey Senozhatsky
  0 siblings, 2 replies; 6+ messages in thread
From: Alexey Romanov @ 2023-05-16  9:50 UTC (permalink / raw)
  To: minchan, senozhatsky, akpm; +Cc: linux-mm, linux-kernel, kernel, Alexey Romanov

Better not to use hardcoded constants.

Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
---
 mm/zsmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 702bc3fd687a..f23c2da55368 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1888,7 +1888,7 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)
 		fg[1] = ZS_ALMOST_EMPTY;
 	}
 
-	for (i = 0; i < 2; i++) {
+	for (i = 0; i < ARRAY_SIZE(fg); i++) {
 		zspage = list_first_entry_or_null(&class->fullness_list[fg[i]],
 							struct zspage, list);
 		if (zspage) {
-- 
2.38.1


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

* [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK
  2023-05-16  9:50 [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Alexey Romanov
@ 2023-05-16  9:50 ` Alexey Romanov
  2023-05-16  9:56   ` Sergey Senozhatsky
  2023-05-16  9:53 ` [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Sergey Senozhatsky
  1 sibling, 1 reply; 6+ messages in thread
From: Alexey Romanov @ 2023-05-16  9:50 UTC (permalink / raw)
  To: minchan, senozhatsky, akpm; +Cc: linux-mm, linux-kernel, kernel, Alexey Romanov

Use offset_in_page() macro instead of 'val & ~PAGE_MASK'

Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
---
 mm/zsmalloc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index f23c2da55368..0a3b11aa07a9 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1425,7 +1425,7 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
 	spin_unlock(&pool->lock);
 
 	class = zspage_class(pool, zspage);
-	off = (class->size * obj_idx) & ~PAGE_MASK;
+	off = offset_in_page(class->size * obj_idx);
 
 	local_lock(&zs_map_area.lock);
 	area = this_cpu_ptr(&zs_map_area);
@@ -1465,7 +1465,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
 	obj_to_location(obj, &page, &obj_idx);
 	zspage = get_zspage(page);
 	class = zspage_class(pool, zspage);
-	off = (class->size * obj_idx) & ~PAGE_MASK;
+	off = offset_in_page(class->size * obj_idx);
 
 	area = this_cpu_ptr(&zs_map_area);
 	if (off + class->size <= PAGE_SIZE)
@@ -1522,7 +1522,7 @@ static unsigned long obj_malloc(struct zs_pool *pool,
 
 	offset = obj * class->size;
 	nr_page = offset >> PAGE_SHIFT;
-	m_offset = offset & ~PAGE_MASK;
+	m_offset = offset_in_page(offset);
 	m_page = get_first_page(zspage);
 
 	for (i = 0; i < nr_page; i++)
@@ -1626,7 +1626,7 @@ static void obj_free(int class_size, unsigned long obj, unsigned long *handle)
 	void *vaddr;
 
 	obj_to_location(obj, &f_page, &f_objidx);
-	f_offset = (class_size * f_objidx) & ~PAGE_MASK;
+	f_offset = offset_in_page(class_size * f_objidx);
 	zspage = get_zspage(f_page);
 
 	vaddr = kmap_atomic(f_page);
@@ -1718,8 +1718,8 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,
 	obj_to_location(src, &s_page, &s_objidx);
 	obj_to_location(dst, &d_page, &d_objidx);
 
-	s_off = (class->size * s_objidx) & ~PAGE_MASK;
-	d_off = (class->size * d_objidx) & ~PAGE_MASK;
+	s_off = offset_in_page(class->size * s_objidx);
+	d_off = offset_in_page(class->size * d_objidx);
 
 	if (s_off + class->size > PAGE_SIZE)
 		s_size = PAGE_SIZE - s_off;
-- 
2.38.1


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

* Re: [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage()
  2023-05-16  9:50 [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Alexey Romanov
  2023-05-16  9:50 ` [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK Alexey Romanov
@ 2023-05-16  9:53 ` Sergey Senozhatsky
  2023-05-16 10:11   ` Alexey Romanov
  1 sibling, 1 reply; 6+ messages in thread
From: Sergey Senozhatsky @ 2023-05-16  9:53 UTC (permalink / raw)
  To: Alexey Romanov; +Cc: minchan, senozhatsky, akpm, linux-mm, linux-kernel, kernel

On (23/05/16 12:50), Alexey Romanov wrote:
>  mm/zsmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 702bc3fd687a..f23c2da55368 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1888,7 +1888,7 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)
>  		fg[1] = ZS_ALMOST_EMPTY;
>  	}
>  
> -	for (i = 0; i < 2; i++) {
> +	for (i = 0; i < ARRAY_SIZE(fg); i++) {
>  		zspage = list_first_entry_or_null(&class->fullness_list[fg[i]],
>  							struct zspage, list);
>  		if (zspage) {

This patch needs to be dropped. We don't have that function anymore.

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

* Re: [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK
  2023-05-16  9:50 ` [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK Alexey Romanov
@ 2023-05-16  9:56   ` Sergey Senozhatsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2023-05-16  9:56 UTC (permalink / raw)
  To: Andrew Morton, Minchan Kim
  Cc: senozhatsky, linux-mm, linux-kernel, kernel, Alexey Romanov

On (23/05/16 12:50), Alexey Romanov wrote:
> 
> Use offset_in_page() macro instead of 'val & ~PAGE_MASK'
> 
> Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

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

* Re: [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage()
  2023-05-16  9:53 ` [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Sergey Senozhatsky
@ 2023-05-16 10:11   ` Alexey Romanov
  2023-05-16 12:29     ` Sergey Senozhatsky
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Romanov @ 2023-05-16 10:11 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: minchan@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org

Hello!

On Tue, May 16, 2023 at 06:53:27PM +0900, Sergey Senozhatsky wrote:
> On (23/05/16 12:50), Alexey Romanov wrote:
> >  mm/zsmalloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > index 702bc3fd687a..f23c2da55368 100644
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -1888,7 +1888,7 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)
> >  		fg[1] = ZS_ALMOST_EMPTY;
> >  	}
> >  
> > -	for (i = 0; i < 2; i++) {
> > +	for (i = 0; i < ARRAY_SIZE(fg); i++) {
> >  		zspage = list_first_entry_or_null(&class->fullness_list[fg[i]],
> >  							struct zspage, list);
> >  		if (zspage) {
> 
> This patch needs to be dropped. We don't have that function anymore.

Do I need to sumbit v2 without this patch, or will Andrew just take
only the 2/2 patch into the branch?

-- 
Thank you,
Alexey

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

* Re: [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage()
  2023-05-16 10:11   ` Alexey Romanov
@ 2023-05-16 12:29     ` Sergey Senozhatsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2023-05-16 12:29 UTC (permalink / raw)
  To: Alexey Romanov
  Cc: Sergey Senozhatsky, minchan@kernel.org, akpm@linux-foundation.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org

On (23/05/16 10:11), Alexey Romanov wrote:
> > > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > > index 702bc3fd687a..f23c2da55368 100644
> > > --- a/mm/zsmalloc.c
> > > +++ b/mm/zsmalloc.c
> > > @@ -1888,7 +1888,7 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)
> > >  		fg[1] = ZS_ALMOST_EMPTY;
> > >  	}
> > >  
> > > -	for (i = 0; i < 2; i++) {
> > > +	for (i = 0; i < ARRAY_SIZE(fg); i++) {
> > >  		zspage = list_first_entry_or_null(&class->fullness_list[fg[i]],
> > >  							struct zspage, list);
> > >  		if (zspage) {
> > 
> > This patch needs to be dropped. We don't have that function anymore.
> 
> Do I need to sumbit v2 without this patch, or will Andrew just take
> only the 2/2 patch into the branch?

Let's hear from Andrew, but I think v2 won't be necessary.

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

end of thread, other threads:[~2023-05-16 12:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16  9:50 [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Alexey Romanov
2023-05-16  9:50 ` [PATCH v1 2/2] mm/zsmalloc: get rid of PAGE_MASK Alexey Romanov
2023-05-16  9:56   ` Sergey Senozhatsky
2023-05-16  9:53 ` [PATCH v1 1/2] mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() Sergey Senozhatsky
2023-05-16 10:11   ` Alexey Romanov
2023-05-16 12:29     ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox