Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8552301ybi; Tue, 9 Jul 2019 18:27:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeQmXDekAFU1OmzxAVvIfh2Noel0YXV+GM9f6eEDldS4zb2lAhRiQCQagwHhc5i/qtTiSI X-Received: by 2002:a63:6b46:: with SMTP id g67mr34046802pgc.45.1562722061527; Tue, 09 Jul 2019 18:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562722061; cv=none; d=google.com; s=arc-20160816; b=CwFT5+0OP8v1nSvOvpBt7ZBnkN4icwvL8oRljD+ozVqvXfThvHTwt6GFi3XJpSys3V XxEtg78hdvTVVptzXstXXBwxcesBRHDKmdAZH+UKsB2Cf9l1jru2/wnrMHxReQlqwHUR wlaO6XAxhvxjFueilECnZnsz2ZS5TvCdm1dJHVHRrgwUF/86888pwo344DyNNmHEszA3 YxOwrEBgLc49J/lff7s5ngpuqvgVY1RqHuNTImfBR5PEAAnL03A+qC/MKSwxxwfNqDuk 9Dbohqpx5S74EmF+95dWrM62AvxnRKT7wUDooTa8vSuJZ2wBwvj9y6a2lQ2X64AhJc9p fiOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Cu9Ev7USkO+Ferj7wq9cXxOfsXPdqxH7nA9dSx/5Zw8=; b=m4wVdsyYKNxTz0CEN4rqVU9b1chYVmaiVeQkRx4/B2mR72Q8qIl4RP2rw4sWWMRmjO +bYDruFlH8tjmRa2vevh13ci9i+iXJjB5KnPA+aVzdUKbkY93sZFlDWqd5DwksAOA3E1 p7coeBDPrD37VwQOyncXywVdCQ32MoiqSpajHb+CgSdw/frBItrTagQ9rumgK0fS85tJ c+Se6R8f2WK3uz2HQQJjra7c3kQsUW+xXE/qSDw2HlFVI5UJ+nTIAtdZO8+p0bjmjDzO Z0MWKdT/qEetotDwhiF444x9DvWyVRl2lLMQZNXRsAqi6nAds/C/BuG7NKwVwWP7unDh eCHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m17si589702pgg.539.2019.07.09.18.27.25; Tue, 09 Jul 2019 18:27:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbfGJBZp (ORCPT + 99 others); Tue, 9 Jul 2019 21:25:45 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2247 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726324AbfGJBZo (ORCPT ); Tue, 9 Jul 2019 21:25:44 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D74B0BD00961EB2F6ECA; Wed, 10 Jul 2019 09:25:35 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.212) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Jul 2019 09:25:26 +0800 Subject: Re: [PATCH] f2fs: allocate memory in batch in build_sit_info() To: Jaegeuk Kim , Chao Yu CC: , , Chen Gong References: <20190704081730.46414-1-yuchao0@huawei.com> <20190708234633.GB21769@jaegeuk-macbookpro.roam.corp.google.com> <86fb078c-0f9e-8d08-7e3b-29a2b6c8b107@kernel.org> <20190709172347.GA53646@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: <6a110d61-3dac-2142-d4e5-cda928aa4938@huawei.com> Date: Wed, 10 Jul 2019 09:25:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190709172347.GA53646@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/10 1:23, Jaegeuk Kim wrote: > On 07/09, Chao Yu wrote: >> On 2019-7-9 7:46, Jaegeuk Kim wrote: >>> On 07/04, Chao Yu wrote: >>>> build_sit_info() allocate all bitmaps for each segment one by one, >>>> it's quite low efficiency, this pach changes to allocate large >>>> continuous memory at a time, and divide it and assign for each bitmaps >>> >>> It may give more failure rate? >> >> For android, I think there should be no problem, since while startup, memory >> should be sufficient for f2fs mount. >> For server or desktop, if there is any failure on memory allocation, >> f2fs_kzalloc will fallback to vmalloc, so that would not be worse than before, >> right? >> >> Or if you worry about this really, could we add a fast path: > > How much time can we really get with this big alloc? Total build_sit_info()'s elapsed time reduces from 20ms to 10ms on 128gb device. Thanks, > >> >> build_sit_info() >> - try allocate sit_i->bitmap >> - success: divide memory >> - fail: fallback to old method >> >> Thanks, >> >>> >>>> of segment. For large size image, it can expect improving its mount >>>> speed. >>>> >>>> Signed-off-by: Chen Gong >>>> Signed-off-by: Chao Yu >>>> --- >>>> fs/f2fs/segment.c | 51 +++++++++++++++++++++-------------------------- >>>> fs/f2fs/segment.h | 1 + >>>> 2 files changed, 24 insertions(+), 28 deletions(-) >>>> >>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c >>>> index 402fbbbb2d7c..73c803af1f31 100644 >>>> --- a/fs/f2fs/segment.c >>>> +++ b/fs/f2fs/segment.c >>>> @@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) >>>> struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); >>>> struct sit_info *sit_i; >>>> unsigned int sit_segs, start; >>>> - char *src_bitmap; >>>> + char *src_bitmap, *bitmap; >>>> unsigned int bitmap_size; >>>> >>>> /* allocate memory for SIT information */ >>>> @@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi) >>>> if (!sit_i->dirty_sentries_bitmap) >>>> return -ENOMEM; >>>> >>>> +#ifdef CONFIG_F2FS_CHECK_FS >>>> + bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4; >>>> +#else >>>> + bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3; >>>> +#endif >>>> + sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL); >>>> + if (!sit_i->bitmap) >>>> + return -ENOMEM; >>>> + >>>> + bitmap = sit_i->bitmap; >>>> + >>>> for (start = 0; start < MAIN_SEGS(sbi); start++) { >>>> - sit_i->sentries[start].cur_valid_map >>>> - = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); >>>> - sit_i->sentries[start].ckpt_valid_map >>>> - = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); >>>> - if (!sit_i->sentries[start].cur_valid_map || >>>> - !sit_i->sentries[start].ckpt_valid_map) >>>> - return -ENOMEM; >>>> + sit_i->sentries[start].cur_valid_map = bitmap; >>>> + bitmap += SIT_VBLOCK_MAP_SIZE; >>>> + >>>> + sit_i->sentries[start].ckpt_valid_map = bitmap; >>>> + bitmap += SIT_VBLOCK_MAP_SIZE; >>>> >>>> #ifdef CONFIG_F2FS_CHECK_FS >>>> - sit_i->sentries[start].cur_valid_map_mir >>>> - = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); >>>> - if (!sit_i->sentries[start].cur_valid_map_mir) >>>> - return -ENOMEM; >>>> + sit_i->sentries[start].cur_valid_map_mir = bitmap; >>>> + bitmap += SIT_VBLOCK_MAP_SIZE; >>>> #endif >>>> >>>> - sit_i->sentries[start].discard_map >>>> - = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, >>>> - GFP_KERNEL); >>>> - if (!sit_i->sentries[start].discard_map) >>>> - return -ENOMEM; >>>> + sit_i->sentries[start].discard_map = bitmap; >>>> + bitmap += SIT_VBLOCK_MAP_SIZE; >>>> } >>>> >>>> sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); >>>> @@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi) >>>> static void destroy_sit_info(struct f2fs_sb_info *sbi) >>>> { >>>> struct sit_info *sit_i = SIT_I(sbi); >>>> - unsigned int start; >>>> >>>> if (!sit_i) >>>> return; >>>> >>>> - if (sit_i->sentries) { >>>> - for (start = 0; start < MAIN_SEGS(sbi); start++) { >>>> - kvfree(sit_i->sentries[start].cur_valid_map); >>>> -#ifdef CONFIG_F2FS_CHECK_FS >>>> - kvfree(sit_i->sentries[start].cur_valid_map_mir); >>>> -#endif >>>> - kvfree(sit_i->sentries[start].ckpt_valid_map); >>>> - kvfree(sit_i->sentries[start].discard_map); >>>> - } >>>> - } >>>> + if (sit_i->sentries) >>>> + kvfree(sit_i->bitmap); >>>> kvfree(sit_i->tmp_map); >>>> >>>> kvfree(sit_i->sentries); >>>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h >>>> index 2fd53462fa27..4d171b489130 100644 >>>> --- a/fs/f2fs/segment.h >>>> +++ b/fs/f2fs/segment.h >>>> @@ -226,6 +226,7 @@ struct sit_info { >>>> block_t sit_base_addr; /* start block address of SIT area */ >>>> block_t sit_blocks; /* # of blocks used by SIT area */ >>>> block_t written_valid_blocks; /* # of valid blocks in main area */ >>>> + char *bitmap; /* all bitmaps pointer */ >>>> char *sit_bitmap; /* SIT bitmap pointer */ >>>> #ifdef CONFIG_F2FS_CHECK_FS >>>> char *sit_bitmap_mir; /* SIT bitmap mirror */ >>>> -- >>>> 2.18.0.rc1 > . >