linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] z3fold: avoid modifying HEADLESS page and minor cleanup
@ 2016-05-27 16:06 Vitaly Wool
  2016-05-27 18:37 ` Dan Streetman
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Wool @ 2016-05-27 16:06 UTC (permalink / raw)
  To: Linux-MM, linux-kernel; +Cc: Seth Jennings, Dan Streetman, Andrew Morton

This patch fixes erroneous z3fold header access in a HEADLESS page
in reclaim function, and changes one remaining direct
handle-to-buddy conversion to use the appropriate helper.

Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
---
  mm/z3fold.c | 24 ++++++++++++++----------
  1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 34917d5..8f9e89c 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -412,7 +412,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
  		/* HEADLESS page stored */
  		bud = HEADLESS;
  	} else {
-		bud = (handle - zhdr->first_num) & BUDDY_MASK;
+		bud = handle_to_buddy(handle);
  
  		switch (bud) {
  		case FIRST:
@@ -572,15 +572,19 @@ next:
  			pool->pages_nr--;
  			spin_unlock(&pool->lock);
  			return 0;
-		} else if (zhdr->first_chunks != 0 &&
-			   zhdr->last_chunks != 0 && zhdr->middle_chunks != 0) {
-			/* Full, add to buddied list */
-			list_add(&zhdr->buddy, &pool->buddied);
-		} else if (!test_bit(PAGE_HEADLESS, &page->private)) {
-			z3fold_compact_page(zhdr);
-			/* add to unbuddied list */
-			freechunks = num_free_chunks(zhdr);
-			list_add(&zhdr->buddy, &pool->unbuddied[freechunks]);
+		}  else if (!test_bit(PAGE_HEADLESS, &page->private)) {
+			if (zhdr->first_chunks != 0 &&
+			    zhdr->last_chunks != 0 &&
+			    zhdr->middle_chunks != 0) {
+				/* Full, add to buddied list */
+				list_add(&zhdr->buddy, &pool->buddied);
+			} else {
+				z3fold_compact_page(zhdr);
+				/* add to unbuddied list */
+				freechunks = num_free_chunks(zhdr);
+				list_add(&zhdr->buddy,
+					 &pool->unbuddied[freechunks]);
+			}
  		}
  
  		/* add to beginning of LRU */
-- 
2.5.0

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

* Re: [PATCH] z3fold: avoid modifying HEADLESS page and minor cleanup
  2016-05-27 16:06 [PATCH] z3fold: avoid modifying HEADLESS page and minor cleanup Vitaly Wool
@ 2016-05-27 18:37 ` Dan Streetman
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Streetman @ 2016-05-27 18:37 UTC (permalink / raw)
  To: Vitaly Wool; +Cc: Linux-MM, linux-kernel, Seth Jennings, Andrew Morton

On Fri, May 27, 2016 at 12:06 PM, Vitaly Wool <vitalywool@gmail.com> wrote:
> This patch fixes erroneous z3fold header access in a HEADLESS page
> in reclaim function, and changes one remaining direct
> handle-to-buddy conversion to use the appropriate helper.
>
> Signed-off-by: Vitaly Wool <vitalywool@gmail.com>

Reviewed-by: Dan Streetman <ddstreet@ieee.org>

> ---
>  mm/z3fold.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/mm/z3fold.c b/mm/z3fold.c
> index 34917d5..8f9e89c 100644
> --- a/mm/z3fold.c
> +++ b/mm/z3fold.c
> @@ -412,7 +412,7 @@ static void z3fold_free(struct z3fold_pool *pool,
> unsigned long handle)
>                 /* HEADLESS page stored */
>                 bud = HEADLESS;
>         } else {
> -               bud = (handle - zhdr->first_num) & BUDDY_MASK;
> +               bud = handle_to_buddy(handle);
>                 switch (bud) {
>                 case FIRST:
> @@ -572,15 +572,19 @@ next:
>                         pool->pages_nr--;
>                         spin_unlock(&pool->lock);
>                         return 0;
> -               } else if (zhdr->first_chunks != 0 &&
> -                          zhdr->last_chunks != 0 && zhdr->middle_chunks !=
> 0) {
> -                       /* Full, add to buddied list */
> -                       list_add(&zhdr->buddy, &pool->buddied);
> -               } else if (!test_bit(PAGE_HEADLESS, &page->private)) {
> -                       z3fold_compact_page(zhdr);
> -                       /* add to unbuddied list */
> -                       freechunks = num_free_chunks(zhdr);
> -                       list_add(&zhdr->buddy,
> &pool->unbuddied[freechunks]);
> +               }  else if (!test_bit(PAGE_HEADLESS, &page->private)) {
> +                       if (zhdr->first_chunks != 0 &&
> +                           zhdr->last_chunks != 0 &&
> +                           zhdr->middle_chunks != 0) {
> +                               /* Full, add to buddied list */
> +                               list_add(&zhdr->buddy, &pool->buddied);
> +                       } else {
> +                               z3fold_compact_page(zhdr);
> +                               /* add to unbuddied list */
> +                               freechunks = num_free_chunks(zhdr);
> +                               list_add(&zhdr->buddy,
> +                                        &pool->unbuddied[freechunks]);
> +                       }
>                 }
>                 /* add to beginning of LRU */
> --
> 2.5.0
>

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

end of thread, other threads:[~2016-05-27 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-27 16:06 [PATCH] z3fold: avoid modifying HEADLESS page and minor cleanup Vitaly Wool
2016-05-27 18:37 ` Dan Streetman

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 NNTP newsgroup(s).