public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiang Liu <liuj97@gmail.com>
To: Jerome Marchand <jmarchan@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nitin Gupta <ngupta@vflare.org>, Minchan Kim <minchan@kernel.org>,
	Yijing Wang <wangyijing@huawei.com>,
	Jiang Liu <jiang.liu@huawei.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 10/10] zram: use atomic64_xxx() to replace zram_stat64_xxx()
Date: Thu, 06 Jun 2013 23:56:46 +0800	[thread overview]
Message-ID: <51B0B13E.8030305@gmail.com> (raw)
In-Reply-To: <51B0A5A1.1040805@redhat.com>

On Thu 06 Jun 2013 11:07:13 PM CST, Jerome Marchand wrote:
> On 06/06/2013 04:36 PM, Jiang Liu wrote:
>> On Thu 06 Jun 2013 05:37:19 PM CST, Jerome Marchand wrote:
>>> On 06/05/2013 06:21 PM, Jiang Liu wrote:
>>>> On Wed 05 Jun 2013 08:02:12 PM CST, Jerome Marchand wrote:
>>>>> On 06/04/2013 06:06 PM, Jiang Liu wrote:
>>>>>> Use atomic64_xxx() to replace open-coded zram_stat64_xxx().
>>>>>> Some architectures have native support of atomic64 operations,
>>>>>> so we can get rid of the spin_lock() in zram_stat64_xxx().
>>>>>> On the other hand, for platforms use generic version of atomic64
>>>>>> implement, it may cause an extra save/restore of the interrupt
>>>>>> flag.  So it's a tradeoff.
>>>>>>
>>>>>> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
>>>>>
>>>>> Before optimizing stats, I'd like to make sure that they're correct.
>>>>> What makes 64 bits fields so different that they need atomicity while
>>>>> 32 bits wouldn't? Actually all of them save compr_size only increase,
>>>>> which would make a race less critical than for 32 bits fields that all
>>>>> can go up and down (if a decrement overwrites a increment, the counter
>>>>> can wrap around zero).
>>>>>
>>>>> Jerome
>>>>>
>>>> Hi Jerome,
>>>>           I'm not sure about the design decision, but I could give a
>>>> guess here.
>>>> 1) All 32-bit counters are only modified by
>>>> zram_bvec_write()/zram_page_free()
>>>> and is/should be protected by down_write(&zram->lock).
>>>
>>> Good point!
>>>
>>>> 2) __zram_make_request() modifies some 64-bit counters without
>>>> protection.
>>>> 3) zram_bvec_write() modifies some 64-bit counters and it's protected
>>>> with
>>>>      down_read(&zram->lock).
>>>
>>> I assume you mean down_write().
>> Actually I mean "zram_bvec_read()" instead of "zram_bvec_write()".
>
> Indeed, failed_reads is updated there.
>
>> Read side is protected by down_read(&zram->lock).
>
> which does not prevent concurrent read access. The counter isn't
> protected by zram_lock here.
Hi Jerome,
     Yeah, it's true. The down_read(&zram->lock) can't protect 
modification
to stat counters because there may be multiple readers. So zram uses
zram_stat_inc() here.
Regards!
Gerry

>
> Jerome
>
>> Regards!
>> Gerry
>>
>>>
>>>> 4) It's always safe for sysfs handler to read 32bit counters.
>>>> 5) It's unsafe for sysfs handler to read 64bit counters on 32bit
>>>> platforms.
>>>
>>> I was unaware of that.
>>>
>>>>
>>>> So it does work with current design, but very hard to understand.
>>>> Suggest to use atomic_t for 32bit counters too for maintainability,
>>>> though may be a little slower.
>>>> Any suggestion?
>>>
>>> If atomic counter aren't necessary, no need to use them, but a comment
>>> in zram_stats definition would be nice. Could you add one in your next
>>> version of this patch?
>> Sure!
>>
>>>
>>> Thanks
>>> Jerome
>>>
>>>> Regards!
>>>> Gerry
>>>>
>>>
>>
>>
>



  reply	other threads:[~2013-06-06 15:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 16:05 [PATCH v2 01/10] zram: kill unused zram_get_num_devices() Jiang Liu
2013-06-04 16:06 ` [PATCH v2 02/10] zram: avoid invalid memory access in zram_exit() Jiang Liu
2013-06-05  6:04   ` Minchan Kim
2013-06-05 15:24     ` Jiang Liu
2013-06-04 16:06 ` [PATCH v2 03/10] zram: use zram->lock to protect zram_free_page() in swap free notify path Jiang Liu
2013-06-05  6:29   ` Minchan Kim
2013-06-05 16:00     ` Jiang Liu
2013-06-05 10:26   ` Jerome Marchand
2013-06-04 16:06 ` [PATCH v2 04/10] zram: destroy all devices on error recovery path in zram_init() Jiang Liu
2013-06-05  6:40   ` Minchan Kim
2013-06-05 10:40   ` Jerome Marchand
2013-06-04 16:06 ` [PATCH v2 05/10] zram: avoid double free in function zram_bvec_write() Jiang Liu
2013-06-05  6:41   ` Minchan Kim
2013-06-07  9:35   ` Jerome Marchand
2013-06-04 16:06 ` [PATCH v2 06/10] zram: avoid access beyond the zram device Jiang Liu
2013-06-05  6:43   ` Minchan Kim
2013-06-04 16:06 ` [PATCH v2 07/10] zram: optimize memory operations with clear_page()/copy_page() Jiang Liu
2013-06-05  6:57   ` Minchan Kim
2013-06-04 16:06 ` [PATCH v2 08/10] zram: protect sysfs handler from invalid memory access Jiang Liu
2013-06-05  7:03   ` Minchan Kim
2013-06-04 16:06 ` [PATCH v2 09/10] zram: minor code cleanup Jiang Liu
2013-06-05  7:13   ` Minchan Kim
2013-06-04 16:06 ` [PATCH v2 10/10] zram: use atomic64_xxx() to replace zram_stat64_xxx() Jiang Liu
2013-06-05 12:02   ` Jerome Marchand
2013-06-05 16:21     ` Jiang Liu
2013-06-06  9:37       ` Jerome Marchand
2013-06-06 14:36         ` Jiang Liu
2013-06-06 15:07           ` Jerome Marchand
2013-06-06 15:56             ` Jiang Liu [this message]
2013-06-05  5:52 ` [PATCH v2 01/10] zram: kill unused zram_get_num_devices() Minchan Kim
2013-06-05 15:09   ` Jiang Liu
2013-06-05  9:06 ` Jerome Marchand

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=51B0B13E.8030305@gmail.com \
    --to=liuj97@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jiang.liu@huawei.com \
    --cc=jmarchan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=wangyijing@huawei.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