linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Marchand <jmarchan@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, Minchan Kim <minchan@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2)
Date: Mon, 09 Sep 2013 18:10:07 +0200	[thread overview]
Message-ID: <522DF2DF.5060407@redhat.com> (raw)
In-Reply-To: <522DD125.1030607@redhat.com>

On 09/09/2013 03:46 PM, Jerome Marchand wrote:
> On 09/09/2013 03:21 PM, Dan Carpenter wrote:
>> On Mon, Sep 09, 2013 at 03:49:42PM +0300, Sergey Senozhatsky wrote:
>>>>> Calling handle_pending_slot_free() for every RW operation may
>>>>> cause unneccessary slot_free_lock locking, because most likely
>>>>> process will see NULL slot_free_rq. handle_pending_slot_free()
>>>>> only when current detects that slot_free_rq is not NULL.
>>>>>
>>>>> v2: protect handle_pending_slot_free() with zram rw_lock.
>>>>>
>>>>
>>>> zram->slot_free_lock protects zram->slot_free_rq but shouldn't the zram
>>>> rw_lock be wrapped around the whole operation like the original code
>>>> does?  I don't know the zram code, but the original looks like it makes
>>>> sense but in this one it looks like the locks are duplicative.
>>>>
>>>> Is the down_read() in the original code be changed to down_write()?
>>>>
>>>
>>> I'm not touching locking around existing READ/WRITE commands.
>>>
>>
>> Your patch does change the locking because now instead of taking the
>> zram lock once it takes it and then drops it and then retakes it.  This
>> looks potentially racy to me but I don't know the code so I will defer
>> to any zram maintainer.
> 
> You're right. Nothing prevents zram_slot_free_notify() to repopulate the
> free slot queue while we drop the lock.
> 
> Actually, the original code is already racy. handle_pending_slot_free()
> modifies zram->table while holding only a read lock. It needs to hold a
> write lock to do that. Using down_write for all requests would obviously
> fix that, but at the cost of read performance.

Now I think we can drop the call to handle_pending_slot_free() in
zram_bvec_rw() altogether. As long as the write lock is held when
handle_pending_slot_free() is called, there is no race. It's no different
from any write request and the current code handles R/W concurrency
already.

Jerome

> 
>>
>> 1) You haven't given us any performance numbers so it's not clear if the
>>    locking is even a problem.
>>
>> 2) The v2 patch introduces an obvious deadlock in zram_slot_free()
>>    because now we take the rw_lock twice.  Fix your testing to catch
>>    this kind of bug next time.
>>
>> 3) Explain why it is safe to test zram->slot_free_rq when we are not
>>    holding the lock.  I think it is unsafe.  I don't want to even think
>>    about it without the numbers.
>>
>> regards,
>> dan carpenter
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


  reply	other threads:[~2013-09-09 16:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-06 15:12 [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 12:33 ` Dan Carpenter
2013-09-09 12:49   ` Sergey Senozhatsky
2013-09-09 13:21     ` Dan Carpenter
2013-09-09 13:46       ` Jerome Marchand
2013-09-09 16:10         ` Jerome Marchand [this message]
2013-09-10 14:34           ` Sergey Senozhatsky
2013-09-10 14:58             ` Dan Carpenter
2013-09-10 15:15               ` Greg Kroah-Hartman
2013-09-10 23:12               ` [PATCH 1/2] staging: zram: fix handle_pending_slot_free() and zram_reset_device() race Sergey Senozhatsky
2013-09-12 22:12                 ` Greg KH
2013-09-13  9:17                   ` Sergey Senozhatsky
2013-09-16  0:02                 ` Minchan Kim
2013-09-17 17:24                   ` Sergey Senozhatsky
2013-09-23  4:24                     ` Minchan Kim
2013-09-23  8:42                       ` Sergey Senozhatsky
2013-09-10 23:19               ` [PATCH 2/2] staging: zram: remove init_done from zram struct (v3) Sergey Senozhatsky
2013-09-10 23:27             ` [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 14:42       ` Sergey Senozhatsky
2013-09-09 14:52         ` Dan Carpenter
2013-09-09 15:09           ` Sergey Senozhatsky

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=522DF2DF.5060407@redhat.com \
    --to=jmarchan@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=sergey.senozhatsky@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).