linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] z3fold: discourage use of pages that weren't compacted
@ 2016-11-11 13:02 Vitaly Wool
  2016-11-15  0:33 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Vitaly Wool @ 2016-11-11 13:02 UTC (permalink / raw)
  To: Linux-MM, linux-kernel; +Cc: Dan Streetman, Andrew Morton

If a z3fold page couldn't be compacted, we don't want it to be
used for next object allocation in the first place. It makes more
sense to add it to the end of the relevant unbuddied list. If that
page gets compacted later, it will be added to the beginning of
the list then.

This simple idea gives 5-7% improvement in randrw fio tests and
about 10% improvement in fio sequential read/write.

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

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 5fe2652..eb8f9a0 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -277,10 +277,10 @@ static inline void *mchunk_memmove(struct z3fold_header *zhdr,
 
 #define BIG_CHUNK_GAP	3
 /* Has to be called with lock held */
-static int z3fold_compact_page(struct z3fold_header *zhdr)
+static bool z3fold_compact_page(struct z3fold_header *zhdr)
 {
 	struct page *page = virt_to_page(zhdr);
-	int ret = 0;
+	bool ret = false;
 
 	if (test_bit(MIDDLE_CHUNK_MAPPED, &page->private))
 		goto out;
@@ -292,7 +292,7 @@ static int z3fold_compact_page(struct z3fold_header *zhdr)
 			zhdr->middle_chunks = 0;
 			zhdr->start_middle = 0;
 			zhdr->first_num++;
-			ret = 1;
+			ret = true;
 			goto out;
 		}
 
@@ -304,7 +304,7 @@ static int z3fold_compact_page(struct z3fold_header *zhdr)
 		    zhdr->start_middle > zhdr->first_chunks + BIG_CHUNK_GAP) {
 			mchunk_memmove(zhdr, zhdr->first_chunks + 1);
 			zhdr->start_middle = zhdr->first_chunks + 1;
-			ret = 1;
+			ret = true;
 			goto out;
 		}
 		if (zhdr->last_chunks != 0 && zhdr->first_chunks == 0 &&
@@ -314,7 +314,7 @@ static int z3fold_compact_page(struct z3fold_header *zhdr)
 				zhdr->middle_chunks;
 			mchunk_memmove(zhdr, new_start);
 			zhdr->start_middle = new_start;
-			ret = 1;
+			ret = true;
 			goto out;
 		}
 	}
@@ -535,11 +535,19 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		free_z3fold_page(zhdr);
 		atomic64_dec(&pool->pages_nr);
 	} else {
-		z3fold_compact_page(zhdr);
+		bool compacted = z3fold_compact_page(zhdr);
 		/* Add to the unbuddied list */
 		spin_lock(&pool->lock);
 		freechunks = num_free_chunks(zhdr);
-		list_add(&zhdr->buddy, &pool->unbuddied[freechunks]);
+		/*
+		 * If the page has been compacted, we want to use it
+		 * in the first place.
+		 */
+		if (compacted)
+			list_add(&zhdr->buddy, &pool->unbuddied[freechunks]);
+		else
+			list_add_tail(&zhdr->buddy,
+				      &pool->unbuddied[freechunks]);
 		spin_unlock(&pool->lock);
 		z3fold_page_unlock(zhdr);
 	}
@@ -668,12 +676,16 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 				spin_lock(&pool->lock);
 				list_add(&zhdr->buddy, &pool->buddied);
 			} else {
-				z3fold_compact_page(zhdr);
+				bool compacted = z3fold_compact_page(zhdr);
 				/* add to unbuddied list */
 				spin_lock(&pool->lock);
 				freechunks = num_free_chunks(zhdr);
-				list_add(&zhdr->buddy,
-					 &pool->unbuddied[freechunks]);
+				if (compacted)
+					list_add(&zhdr->buddy,
+						&pool->unbuddied[freechunks]);
+				else
+					list_add_tail(&zhdr->buddy,
+						&pool->unbuddied[freechunks]);
 			}
 		}
 
-- 
2.4.2

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

* Re: [PATCH] z3fold: discourage use of pages that weren't compacted
  2016-11-11 13:02 [PATCH] z3fold: discourage use of pages that weren't compacted Vitaly Wool
@ 2016-11-15  0:33 ` Andrew Morton
  2016-11-15 13:35   ` Vitaly Wool
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2016-11-15  0:33 UTC (permalink / raw)
  To: Vitaly Wool; +Cc: Linux-MM, linux-kernel, Dan Streetman

On Fri, 11 Nov 2016 14:02:07 +0100 Vitaly Wool <vitalywool@gmail.com> wrote:

> If a z3fold page couldn't be compacted, we don't want it to be
> used for next object allocation in the first place. It makes more
> sense to add it to the end of the relevant unbuddied list. If that
> page gets compacted later, it will be added to the beginning of
> the list then.
> 
> This simple idea gives 5-7% improvement in randrw fio tests and
> about 10% improvement in fio sequential read/write.

This patch appears to require "z3fold: use per-page spinlock", and
"z3fold: use per-page spinlock" doesn't apply properly.

So things are in a bit of a mess.

I presently have

z3fold-limit-first_num-to-the-actual-range-of-possible-buddy-indexes.patch
z3fold-make-pages_nr-atomic.patch
z3fold-extend-compaction-function.patch

Please take a look, figure out what we should do.  Perhaps do it all as
a coherent series rather than an interdependent dribble?

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

* Re: [PATCH] z3fold: discourage use of pages that weren't compacted
  2016-11-15  0:33 ` Andrew Morton
@ 2016-11-15 13:35   ` Vitaly Wool
  0 siblings, 0 replies; 3+ messages in thread
From: Vitaly Wool @ 2016-11-15 13:35 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux-MM, LKML, Dan Streetman

On Tue, Nov 15, 2016 at 1:33 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Fri, 11 Nov 2016 14:02:07 +0100 Vitaly Wool <vitalywool@gmail.com> wrote:
>
>> If a z3fold page couldn't be compacted, we don't want it to be
>> used for next object allocation in the first place. It makes more
>> sense to add it to the end of the relevant unbuddied list. If that
>> page gets compacted later, it will be added to the beginning of
>> the list then.
>>
>> This simple idea gives 5-7% improvement in randrw fio tests and
>> about 10% improvement in fio sequential read/write.
>
> This patch appears to require "z3fold: use per-page spinlock", and
> "z3fold: use per-page spinlock" doesn't apply properly.
>
> So things are in a bit of a mess.

Yep, sorry about that.

> I presently have
>
> z3fold-limit-first_num-to-the-actual-range-of-possible-buddy-indexes.patch
> z3fold-make-pages_nr-atomic.patch
> z3fold-extend-compaction-function.patch

These are not interdependent.

> Please take a look, figure out what we should do.  Perhaps do it all as
> a coherent series rather than an interdependent dribble?

I'll come up with a 2-patch update in a short while.

~vitaly

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

end of thread, other threads:[~2016-11-15 13:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-11 13:02 [PATCH] z3fold: discourage use of pages that weren't compacted Vitaly Wool
2016-11-15  0:33 ` Andrew Morton
2016-11-15 13:35   ` Vitaly Wool

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).