From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752630AbdBGDZa (ORCPT ); Mon, 6 Feb 2017 22:25:30 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:4819 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbdBGDZ3 (ORCPT ); Mon, 6 Feb 2017 22:25:29 -0500 Subject: Re: [PATCH] mm: extend zero pages to same element pages for zram To: Minchan Kim References: <1483692145-75357-1-git-send-email-zhouxianrong@huawei.com> <1486111347-112972-1-git-send-email-zhouxianrong@huawei.com> <20170205142100.GA9611@bbox> <2f6e188c-5358-eeab-44ab-7634014af651@huawei.com> <20170206234805.GA12188@bbox> <20170207025426.GA1528@bbox> CC: , , , , , , , , , , , From: zhouxianrong Message-ID: Date: Tue, 7 Feb 2017 11:24:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <20170207025426.GA1528@bbox> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.142.145.228] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.58993E20.0079,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 6d1dbc91f349e8f6a0cceb04a1028a2c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/2/7 10:54, Minchan Kim wrote: > On Tue, Feb 07, 2017 at 10:20:57AM +0800, zhouxianrong wrote: > > < snip > > >>>> 3. the below should be modified. >>>> >>>> static inline bool zram_meta_get(struct zram *zram) >>>> @@ -495,11 +553,17 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize) >>>> >>>> /* Free all pages that are still in this zram device */ >>>> for (index = 0; index < num_pages; index++) { >>>> - unsigned long handle = meta->table[index].handle; >>>> + unsigned long handle; >>>> + >>>> + bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value); >>>> + handle = meta->table[index].handle; >>>> >>>> - if (!handle) >>>> + if (!handle || zram_test_flag(meta, index, ZRAM_SAME)) { >>>> + bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value); >>>> continue; >>>> + } >>>> >>>> + bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value); >>>> zs_free(meta->mem_pool, handle); >>> >>> Could you explain why we need this modification? >>> >>>> } >>>> >>>> @@ -511,7 +575,7 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize) >>>> static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize) >>>> { >>>> size_t num_pages; >>>> - struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL); >>>> + struct zram_meta *meta = kzalloc(sizeof(*meta), GFP_KERNEL); >>> >>> Ditto >>> >>>> >>>> >>> >>> . >>> >> >> because of union of handle and element, i think a non-zero element (other than handle) is prevented from freeing. >> if zram_meta_get was modified, zram_meta_alloc did so. > > Right. Thanks but I don't see why we need the locking in there and modification of > zram_meta_alloc. > > Isn't it enough with this? i am afraid someone do reset_store, so did lock. yes, i am wrong, zram_meta_alloc should not be modified here. because meta->table has already cleared meta->table = vzalloc(num_pages * sizeof(*meta->table)); > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index c20b05a84f21..a25d34a8af19 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -425,8 +425,11 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize) > /* Free all pages that are still in this zram device */ > for (index = 0; index < num_pages; index++) { > unsigned long handle = meta->table[index].handle; > - > - if (!handle) > + /* > + * No memory is allocated for same element filled pages. > + * Simply clear same page flag. > + */ > + if (!handle || zram_test_flag(meta, index, ZRAM_SAME)) > continue; > > zs_free(meta->mem_pool, handle); > > . >