linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Wool <vitalywool@gmail.com>
To: Dan Streetman <ddstreet@ieee.org>
Cc: Linux-MM <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Dave Chinner <david@fromorbit.com>
Subject: Re: [PATCH v5 2/3] z3fold: remove redundant locking
Date: Tue, 18 Oct 2016 04:55:01 +0200	[thread overview]
Message-ID: <CAMJBoFNGO=ZwoVDAbEyJKRP3ojdohSLJUbxJe9c6tD_MFuiMfQ@mail.gmail.com> (raw)
In-Reply-To: <CALZtONCfJ_NQAmekyQQTY9umfKMR1DK5aycQZ5fOohAJ69L9Xg@mail.gmail.com>

On Mon, Oct 17, 2016 at 10:48 PM, Dan Streetman <ddstreet@ieee.org> wrote:
> On Sat, Oct 15, 2016 at 7:59 AM, Vitaly Wool <vitalywool@gmail.com> wrote:
>> The per-pool z3fold spinlock should generally be taken only when
>> a non-atomic pool variable is modified. There's no need to take it
>> to map/unmap an object.
>
> no.  it absolutely needs to be taken, because z3fold_compact_page
> could move the middle bud's contents to the first bud, and if the
> middle bud gets mapped while it's being moved really bad things will
> happen.
>
> you can change that to a per-page lock in the z3fold_header, but some
> locking needs to happen between mapping and middle bud moving (and
> handle encoding/decoding and first_num access).

Yep, probably per-page lock is the way to go. I was thinking of making
first_num atomic but that obviously creates more problems than it solves.

~vitaly

>
>
>>
>> Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
>> ---
>>  mm/z3fold.c | 17 +++++------------
>>  1 file changed, 5 insertions(+), 12 deletions(-)
>>
>> diff --git a/mm/z3fold.c b/mm/z3fold.c
>> index 5197d7b..10513b5 100644
>> --- a/mm/z3fold.c
>> +++ b/mm/z3fold.c
>> @@ -580,6 +580,7 @@ next:
>>                 if ((test_bit(PAGE_HEADLESS, &page->private) && ret == 0) ||
>>                     (zhdr->first_chunks == 0 && zhdr->last_chunks == 0 &&
>>                      zhdr->middle_chunks == 0)) {
>> +                       spin_unlock(&pool->lock);
>>                         /*
>>                          * All buddies are now free, free the z3fold page and
>>                          * return success.
>> @@ -587,7 +588,6 @@ next:
>>                         clear_bit(PAGE_HEADLESS, &page->private);
>>                         free_z3fold_page(zhdr);
>>                         atomic64_dec(&pool->pages_nr);
>> -                       spin_unlock(&pool->lock);
>>                         return 0;
>>                 }  else if (!test_bit(PAGE_HEADLESS, &page->private)) {
>>                         if (zhdr->first_chunks != 0 &&
>> @@ -629,7 +629,6 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle)
>>         void *addr;
>>         enum buddy buddy;
>>
>> -       spin_lock(&pool->lock);
>>         zhdr = handle_to_z3fold_header(handle);
>>         addr = zhdr;
>>         page = virt_to_page(zhdr);
>> @@ -656,7 +655,6 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle)
>>                 break;
>>         }
>>  out:
>> -       spin_unlock(&pool->lock);
>>         return addr;
>>  }
>>
>> @@ -671,19 +669,14 @@ static void z3fold_unmap(struct z3fold_pool *pool, unsigned long handle)
>>         struct page *page;
>>         enum buddy buddy;
>>
>> -       spin_lock(&pool->lock);
>>         zhdr = handle_to_z3fold_header(handle);
>>         page = virt_to_page(zhdr);
>>
>> -       if (test_bit(PAGE_HEADLESS, &page->private)) {
>> -               spin_unlock(&pool->lock);
>> -               return;
>> +       if (!test_bit(PAGE_HEADLESS, &page->private)) {
>> +               buddy = handle_to_buddy(handle);
>> +               if (buddy == MIDDLE)
>> +                       clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
>>         }
>> -
>> -       buddy = handle_to_buddy(handle);
>> -       if (buddy == MIDDLE)
>> -               clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
>> -       spin_unlock(&pool->lock);
>>  }
>>
>>  /**
>> --
>> 2.4.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-10-18  2:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-15 11:56 [PATCH v5] z3fold: add shrinker Vitaly Wool
2016-10-15 11:58 ` [PATCH v5 1/3] z3fold: make counters atomic Vitaly Wool
2016-10-17 20:37   ` Dan Streetman
2016-10-15 11:59 ` [PATCH v5 2/3] z3fold: remove redundant locking Vitaly Wool
2016-10-17 20:48   ` Dan Streetman
2016-10-18  2:55     ` Vitaly Wool [this message]
2016-10-15 12:05 ` [PATCH v5 3/3] z3fold: add shrinker Vitaly Wool
2016-10-18  2:06   ` Dan Streetman
2016-10-18  2:45     ` Vitaly Wool
2016-10-18 14:27       ` Dan Streetman
2016-10-18 14:51         ` Vitaly Wool
2016-10-18 15:29           ` Dan Streetman
2016-10-18 16:26             ` [PATCH v5] " Vitaly Wool
2016-10-18 17:35               ` Dan Streetman
2016-10-18 18:36                 ` Vitaly Wool

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMJBoFNGO=ZwoVDAbEyJKRP3ojdohSLJUbxJe9c6tD_MFuiMfQ@mail.gmail.com' \
    --to=vitalywool@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=ddstreet@ieee.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox