From nobody Mon Nov 25 02:29:12 2024 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBFFD1E2848 for ; Wed, 30 Oct 2024 10:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284346; cv=none; b=BbU9/j4saAcMrMoNfYv4rkWcqIVr6XYxSB4YVSzOWogNN7i0vFFZNgpk75PQTATOV1Bu7LwWFoLekUFord8oadVm3zNHufYZUcnGihIK0UafNyQyGfHFoCaEylrRj78XnK/c2++z89CSiie2K8zAk1eyFCTDVyhilP+gD5xdIss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284346; c=relaxed/simple; bh=JZ286Romoe06+GRgPc3jaV6GDufMbsUVU9Tunn0/Avc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wsuvkjp1kaKVdPXqfnNespTO18ZPgDWz+JA4BemICTZuiPk+hh2d7x8ufEkWkQH/RaRkSBXv0/JFde4eYZsh0ZUNTZTC618Cob8sJRYGTu6gOl8KaSpkARLkuK5Njh9WuacZzTyQeXHWnVNHQRJBkitaxawKdYcz3s/UgcoXOXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 49UAVfg6026716; Wed, 30 Oct 2024 18:31:41 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Xdk1M63kyz2KSK4X; Wed, 30 Oct 2024 18:31:03 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 30 Oct 2024 18:31:39 +0800 From: Yi Sun To: , CC: , , , , , , Subject: [PATCH v2 1/5] f2fs: blocks need to belong to the same segment when using update_sit_entry() Date: Wed, 30 Oct 2024 18:31:32 +0800 Message-ID: <20241030103136.2874140-2-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241030103136.2874140-1-yi.sun@unisoc.com> References: <20241030103136.2874140-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 49UAVfg6026716 Content-Type: text/plain; charset="utf-8" When using update_sit_entry() to release consecutive blocks, ensure that the consecutive blocks belong to the same segment. Because after update_sit_entry_for_realese(), @segno is still in use in update_sit_entry(). Signed-off-by: Yi Sun --- fs/f2fs/segment.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index bb2fd98331cd..a5bd101c63a1 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2424,6 +2424,10 @@ static void update_segment_mtime(struct f2fs_sb_info= *sbi, block_t blkaddr, SIT_I(sbi)->max_mtime =3D ctime; } =20 +/* + * NOTE: when updating multiple blocks at the same time, please ensure + * that the consecutive input blocks belong to the same segment. + */ static int update_sit_entry_for_release(struct f2fs_sb_info *sbi, struct s= eg_entry *se, block_t blkaddr, unsigned int offset, int del) { @@ -2434,6 +2438,8 @@ static int update_sit_entry_for_release(struct f2fs_s= b_info *sbi, struct seg_ent int i; int del_count =3D -del; =20 + f2fs_bug_on(sbi, GET_SEGNO(sbi, blkaddr) !=3D GET_SEGNO(sbi, blkaddr + de= l_count - 1)); + for (i =3D 0; i < del_count; i++) { exist =3D f2fs_test_and_clear_bit(offset + i, se->cur_valid_map); #ifdef CONFIG_F2FS_CHECK_FS @@ -2476,6 +2482,11 @@ static int update_sit_entry_for_release(struct f2fs_= sb_info *sbi, struct seg_ent return del; } =20 +/* + * If releasing blocks, this function supports updating multiple consecuti= ve blocks + * at one time, but please note that these consecutive blocks need to belo= ng to the + * same segment. + */ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, in= t del) { struct seg_entry *se; --=20 2.25.1 From nobody Mon Nov 25 02:29:12 2024 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82C921E377A for ; Wed, 30 Oct 2024 10:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284348; cv=none; b=koQGwua3S2xrSTWxQSCDTfbdn47Rm4khUOop508Eq6XFM1AbTQeX7ItFBtVJEAiXLPFjD8Na1qoXb49fCH8EF80WM3TOheGISY8OA2x9H9FynsUuOGK31JYG9hsKKFFaB8LgP056XgqhwJ/tV0+9hlvx8mI0NdF9SBHeGgHB3h4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284348; c=relaxed/simple; bh=PUBc5a3SONvppUw3w94dSdkO4p3xhINmzL1ECdhrVnQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qUFps/h3rc572J6PmNKyYnbLwpaI6ebsbcGCedEsXvDobt5LWjl8xqvGn6/LquNFeln/vcQNTdiLTRfVT3ptyFyFvWyEh81gqQztK3nZUn9VcrHPcOMLRaeGdSSd6q1CMcInHMULPGNDLHoOekX7HXz0EHLH4jb1SBU6QACtwmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 49UAVgrR026815; Wed, 30 Oct 2024 18:31:42 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Xdk1N5Y5dz2K4lHM; Wed, 30 Oct 2024 18:31:04 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 30 Oct 2024 18:31:40 +0800 From: Yi Sun To: , CC: , , , , , , Subject: [PATCH v2 2/5] f2fs: expand f2fs_invalidate_compress_page() to f2fs_invalidate_compress_pages_range() Date: Wed, 30 Oct 2024 18:31:33 +0800 Message-ID: <20241030103136.2874140-3-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241030103136.2874140-1-yi.sun@unisoc.com> References: <20241030103136.2874140-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 49UAVgrR026815 Content-Type: text/plain; charset="utf-8" New function f2fs_invalidate_compress_pages_range() adds the @len parameter. So it can process some consecutive blocks at a time. Signed-off-by: Yi Sun --- fs/f2fs/compress.c | 7 ++++--- fs/f2fs/f2fs.h | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 7f26440e8595..e607a7885b57 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1903,11 +1903,12 @@ struct address_space *COMPRESS_MAPPING(struct f2fs_= sb_info *sbi) return sbi->compress_inode->i_mapping; } =20 -void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkad= dr) +void f2fs_invalidate_compress_pages_range(struct f2fs_sb_info *sbi, + block_t blkaddr, unsigned int len) { - if (!sbi->compress_inode) + if (!sbi->compress_inode || len =3D=3D 0) return; - invalidate_mapping_pages(COMPRESS_MAPPING(sbi), blkaddr, blkaddr); + invalidate_mapping_pages(COMPRESS_MAPPING(sbi), blkaddr, blkaddr + len - = 1); } =20 void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *pag= e, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 3c6f3cce5779..d3fe66a93a56 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4384,7 +4384,8 @@ void f2fs_destroy_page_array_cache(struct f2fs_sb_inf= o *sbi); int __init f2fs_init_compress_cache(void); void f2fs_destroy_compress_cache(void); struct address_space *COMPRESS_MAPPING(struct f2fs_sb_info *sbi); -void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkad= dr); +void f2fs_invalidate_compress_pages_range(struct f2fs_sb_info *sbi, + block_t blkaddr, unsigned int len); void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *pag= e, nid_t ino, block_t blkaddr); bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page, @@ -4439,8 +4440,8 @@ static inline int f2fs_init_page_array_cache(struct f= 2fs_sb_info *sbi) { return static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi)= { } static inline int __init f2fs_init_compress_cache(void) { return 0; } static inline void f2fs_destroy_compress_cache(void) { } -static inline void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, - block_t blkaddr) { } +static inline void f2fs_invalidate_compress_pages_range(struct f2fs_sb_inf= o *sbi, + block_t blkaddr, unsigned int len) { } static inline void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, nid_t ino, block_t blkaddr) { } static inline bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, @@ -4759,7 +4760,7 @@ static inline void f2fs_invalidate_internal_cache(str= uct f2fs_sb_info *sbi, block_t blkaddr) { f2fs_truncate_meta_inode_pages(sbi, blkaddr, 1); - f2fs_invalidate_compress_page(sbi, blkaddr); + f2fs_invalidate_compress_pages_range(sbi, blkaddr, 1); } =20 #define EFSBADCRC EBADMSG /* Bad CRC detected */ --=20 2.25.1 From nobody Mon Nov 25 02:29:12 2024 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8E7D1D278D for ; Wed, 30 Oct 2024 10:32:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284345; cv=none; b=lviKuCiGto5J0t/B+0XvTP1PIkjEliT19O2lq2Nhl4DyLlKxFHNT39ctH1eex4SlWuWn0WlsX2w1Hj6jeSov38bKT9rB022xqe+W37rWla2tHarHeH25AEgHKFKEEmKNj+DpVhgvLs+jOwJ068FOMaDokKDppBlkTNIVa4bPje0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284345; c=relaxed/simple; bh=3GVtOXyyD93rLRf/4WDDUmXb6p+JsYf2GMu2Iy6RY3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JFAxLRNNUszKyjrQk+5aTbiJwlTZrtM9cBz4vR/DGxZpiVs1kdw4GgTeTBTnypwoza0iCcoEimavG4aXA95OYbJuvAQugAXabho5v3RWpSJ0GDNfBeNzCfwuzGPETQtCZIFe4S8YcfT+Jint0hpjyva9QxC00bW4EIlSrx0lqz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 49UAVhEW026848; Wed, 30 Oct 2024 18:31:43 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Xdk1P5JHRz2KSK4X; Wed, 30 Oct 2024 18:31:05 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 30 Oct 2024 18:31:41 +0800 From: Yi Sun To: , CC: , , , , , , Subject: [PATCH v2 3/5] f2fs: add parameter @len to f2fs_invalidate_internal_cache() Date: Wed, 30 Oct 2024 18:31:34 +0800 Message-ID: <20241030103136.2874140-4-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241030103136.2874140-1-yi.sun@unisoc.com> References: <20241030103136.2874140-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 49UAVhEW026848 Content-Type: text/plain; charset="utf-8" New function can process some consecutive blocks at a time. Signed-off-by: Yi Sun Reviewed-by: Chao Yu --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 6 +++--- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 90fa8ab85194..37bc747aac89 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1420,7 +1420,7 @@ static int __allocate_data_block(struct dnode_of_data= *dn, int seg_type) return err; =20 if (GET_SEGNO(sbi, old_blkaddr) !=3D NULL_SEGNO) - f2fs_invalidate_internal_cache(sbi, old_blkaddr); + f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1); =20 f2fs_update_data_blkaddr(dn, dn->data_blkaddr); return 0; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d3fe66a93a56..addd49af57ec 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4757,10 +4757,10 @@ static inline void f2fs_truncate_meta_inode_pages(s= truct f2fs_sb_info *sbi, } =20 static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi, - block_t blkaddr) + block_t blkaddr, unsigned int len) { - f2fs_truncate_meta_inode_pages(sbi, blkaddr, 1); - f2fs_invalidate_compress_pages_range(sbi, blkaddr, 1); + f2fs_truncate_meta_inode_pages(sbi, blkaddr, len); + f2fs_invalidate_compress_pages_range(sbi, blkaddr, len); } =20 #define EFSBADCRC EBADMSG /* Bad CRC detected */ diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index e40bdd12e36d..155c1a4a0d74 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1410,7 +1410,7 @@ static int move_data_block(struct inode *inode, block= _t bidx, page_address(mpage), PAGE_SIZE); f2fs_put_page(mpage, 1); =20 - f2fs_invalidate_internal_cache(fio.sbi, fio.old_blkaddr); + f2fs_invalidate_internal_cache(fio.sbi, fio.old_blkaddr, 1); =20 set_page_dirty(fio.encrypted_page); if (clear_page_dirty_for_io(fio.encrypted_page)) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index a5bd101c63a1..92ddff285a65 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2567,7 +2567,7 @@ void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi,= block_t addr) if (addr =3D=3D NEW_ADDR || addr =3D=3D COMPRESS_ADDR) return; =20 - f2fs_invalidate_internal_cache(sbi, addr); + f2fs_invalidate_internal_cache(sbi, addr, 1); =20 /* add it into sit main buffer */ down_write(&sit_i->sentry_lock); @@ -3845,7 +3845,7 @@ static void do_write_page(struct f2fs_summary *sum, s= truct f2fs_io_info *fio) goto out; } if (GET_SEGNO(fio->sbi, fio->old_blkaddr) !=3D NULL_SEGNO) - f2fs_invalidate_internal_cache(fio->sbi, fio->old_blkaddr); + f2fs_invalidate_internal_cache(fio->sbi, fio->old_blkaddr, 1); =20 /* writeout dirty page into bdev */ f2fs_submit_page_write(fio); @@ -4037,7 +4037,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, = struct f2fs_summary *sum, update_sit_entry(sbi, new_blkaddr, 1); } if (GET_SEGNO(sbi, old_blkaddr) !=3D NULL_SEGNO) { - f2fs_invalidate_internal_cache(sbi, old_blkaddr); + f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1); if (!from_gc) update_segment_mtime(sbi, old_blkaddr, 0); update_sit_entry(sbi, old_blkaddr, -1); --=20 2.25.1 From nobody Mon Nov 25 02:29:12 2024 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D1A61E3DDB for ; Wed, 30 Oct 2024 10:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284356; cv=none; b=trgpx3DE/aRX9PzxRR8IjdGetrXo67jwcCFDN6DfLRdWNfM583d090Pq0MXt219dlUVDBDRIKGXvkk4ax8EowqWbH5VcHhnlQrkpdp/DQrC6EXGEhdyXc4F7ED87bQ2miEj1DIQjQIw0nlBslVmMeT+tr7WOYSx5xJ0EW2YVYpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284356; c=relaxed/simple; bh=w1mWqRHB0QJil4HOZUPCcylnsuCXHH58MP1R2qHBdzM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b+u5lCGoOTOyqZNOKqsUtbUQtq85b58eSIETJ1kyn/0FxFVQxP2lazOnVLTy06sRkDddnRZVxvSseQ7vVxhYAZaogwBWVXCMP8WY9Z2mnoZhbg7aIwAL8ZQWrcCKPnQsO8WeU8xc9aLsq2NpQzvyr6XvVpG4lzcSMGg4H+pvO4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 49UAVixk026962; Wed, 30 Oct 2024 18:31:44 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Xdk1Q5J9Rz2K4lHM; Wed, 30 Oct 2024 18:31:06 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 30 Oct 2024 18:31:42 +0800 From: Yi Sun To: , CC: , , , , , , Subject: [PATCH v2 4/5] f2fs: add parameter @len to f2fs_invalidate_blocks() Date: Wed, 30 Oct 2024 18:31:35 +0800 Message-ID: <20241030103136.2874140-5-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241030103136.2874140-1-yi.sun@unisoc.com> References: <20241030103136.2874140-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 49UAVixk026962 Content-Type: text/plain; charset="utf-8" New function can process some consecutive blocks at a time. Function f2fs_invalidate_blocks()->down_write() and up_write() are very time-consuming, so if f2fs_invalidate_blocks() can process consecutive blocks at one time, it will save a lot of time. Signed-off-by: Yi Sun --- fs/f2fs/compress.c | 4 +-- fs/f2fs/f2fs.h | 3 +- fs/f2fs/file.c | 8 +++--- fs/f2fs/node.c | 4 +-- fs/f2fs/segment.c | 69 ++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 68 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index e607a7885b57..02ad0ff29cf2 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1374,7 +1374,7 @@ static int f2fs_write_compressed_pages(struct compres= s_ctx *cc, if (blkaddr =3D=3D COMPRESS_ADDR) fio.compr_blocks++; if (__is_valid_data_blkaddr(blkaddr)) - f2fs_invalidate_blocks(sbi, blkaddr); + f2fs_invalidate_blocks(sbi, blkaddr, 1); f2fs_update_data_blkaddr(&dn, COMPRESS_ADDR); goto unlock_continue; } @@ -1384,7 +1384,7 @@ static int f2fs_write_compressed_pages(struct compres= s_ctx *cc, =20 if (i > cc->valid_nr_cpages) { if (__is_valid_data_blkaddr(blkaddr)) { - f2fs_invalidate_blocks(sbi, blkaddr); + f2fs_invalidate_blocks(sbi, blkaddr, 1); f2fs_update_data_blkaddr(&dn, NEW_ADDR); } goto unlock_continue; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index addd49af57ec..4bb459157adf 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3716,7 +3716,8 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t = ino); int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); -void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); +void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr, + unsigned int len); bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); int f2fs_start_discard_thread(struct f2fs_sb_info *sbi); void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 75a8b22da664..13594bb502d1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -652,7 +652,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_da= ta *dn, int count) valid_blocks++; } =20 - f2fs_invalidate_blocks(sbi, blkaddr); + f2fs_invalidate_blocks(sbi, blkaddr, 1); =20 if (!released || blkaddr !=3D COMPRESS_ADDR) nr_free++; @@ -750,7 +750,7 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 fr= om, bool lock) unsigned int i; =20 for (i =3D 0; i < ei.len; i++) - f2fs_invalidate_blocks(sbi, ei.blk + i); + f2fs_invalidate_blocks(sbi, ei.blk + i, 1); =20 dec_valid_block_count(sbi, inode, ei.len); f2fs_update_time(sbi, REQ_TIME); @@ -1319,7 +1319,7 @@ static int __roll_back_blkaddrs(struct inode *inode, = block_t *blkaddr, ret =3D f2fs_get_dnode_of_data(&dn, off + i, LOOKUP_NODE_RA); if (ret) { dec_valid_block_count(sbi, inode, 1); - f2fs_invalidate_blocks(sbi, *blkaddr); + f2fs_invalidate_blocks(sbi, *blkaddr, 1); } else { f2fs_update_data_blkaddr(&dn, *blkaddr); } @@ -1571,7 +1571,7 @@ static int f2fs_do_zero_range(struct dnode_of_data *d= n, pgoff_t start, break; } =20 - f2fs_invalidate_blocks(sbi, dn->data_blkaddr); + f2fs_invalidate_blocks(sbi, dn->data_blkaddr, 1); f2fs_set_data_blkaddr(dn, NEW_ADDR); } =20 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index af36c6d6542b..db15d6a90f67 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -916,7 +916,7 @@ static int truncate_node(struct dnode_of_data *dn) } =20 /* Deallocate node address */ - f2fs_invalidate_blocks(sbi, ni.blk_addr); + f2fs_invalidate_blocks(sbi, ni.blk_addr, 1); dec_valid_node_count(sbi, dn->inode, dn->nid =3D=3D dn->inode->i_ino); set_node_addr(sbi, &ni, NULL_ADDR, false); =20 @@ -2761,7 +2761,7 @@ int f2fs_recover_xattr_data(struct inode *inode, stru= ct page *page) if (err) return err; =20 - f2fs_invalidate_blocks(sbi, ni.blk_addr); + f2fs_invalidate_blocks(sbi, ni.blk_addr, 1); dec_valid_node_count(sbi, inode, false); set_node_addr(sbi, &ni, NULL_ADDR, false); =20 diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 92ddff285a65..67f2bfdeb6ec 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -245,7 +245,7 @@ static int __replace_atomic_write_block(struct inode *i= node, pgoff_t index, if (!__is_valid_data_blkaddr(new_addr)) { if (new_addr =3D=3D NULL_ADDR) dec_valid_block_count(sbi, inode, 1); - f2fs_invalidate_blocks(sbi, dn.data_blkaddr); + f2fs_invalidate_blocks(sbi, dn.data_blkaddr, 1); f2fs_update_data_blkaddr(&dn, new_addr); } else { f2fs_replace_block(sbi, &dn, dn.data_blkaddr, @@ -2558,29 +2558,76 @@ static void update_sit_entry(struct f2fs_sb_info *s= bi, block_t blkaddr, int del) get_sec_entry(sbi, segno)->valid_blocks +=3D del; } =20 -void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr) +static void __f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, + block_t addr, block_t end) { unsigned int segno =3D GET_SEGNO(sbi, addr); struct sit_info *sit_i =3D SIT_I(sbi); + unsigned int seg_num =3D GET_SEGNO(sbi, end) - segno + 1; + unsigned int i =3D 1, max_blocks =3D sbi->blocks_per_seg, len; + block_t addr_start =3D addr; =20 - f2fs_bug_on(sbi, addr =3D=3D NULL_ADDR); - if (addr =3D=3D NEW_ADDR || addr =3D=3D COMPRESS_ADDR) - return; - - f2fs_invalidate_internal_cache(sbi, addr, 1); + f2fs_invalidate_internal_cache(sbi, addr, end - addr + 1); =20 /* add it into sit main buffer */ down_write(&sit_i->sentry_lock); =20 - update_segment_mtime(sbi, addr, 0); - update_sit_entry(sbi, addr, -1); + if (seg_num =3D=3D 1) + len =3D end - addr + 1; + else + len =3D max_blocks - GET_BLKOFF_FROM_SEG0(sbi, addr); =20 - /* add it into dirty seglist */ - locate_dirty_segment(sbi, segno); + do { + update_segment_mtime(sbi, addr_start, 0); + update_sit_entry(sbi, addr_start, -len); + + /* add it into dirty seglist */ + locate_dirty_segment(sbi, segno); + + /* update @addr_start and @len and @segno */ + addr_start =3D START_BLOCK(sbi, ++segno); + if (++i =3D=3D seg_num) + len =3D GET_BLKOFF_FROM_SEG0(sbi, end) + 1; + else + len =3D max_blocks; + } while (i <=3D seg_num); =20 up_write(&sit_i->sentry_lock); } =20 +void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, + block_t addr, unsigned int len) +{ + unsigned int i; + /* Temporary record location */ + block_t addr_start =3D addr, addr_end; + + if (len =3D=3D 0) + return; + + for (i =3D 0; i < len; i++) { + addr_end =3D addr + i; + + f2fs_bug_on(sbi, addr_end =3D=3D NULL_ADDR); + + if (addr_end =3D=3D NEW_ADDR || addr_end =3D=3D COMPRESS_ADDR) { + if (addr_start =3D=3D addr_end) { + addr_end =3D addr_start =3D addr_end + 1; + continue; + } + + __f2fs_invalidate_blocks(sbi, addr_start, addr_end - 1); + addr_end =3D addr_start =3D addr_end + 1; + } + } + + if (addr_end >=3D (addr + len)) + return; + + __f2fs_invalidate_blocks(sbi, addr_start, addr_end); + +} + bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr) { struct sit_info *sit_i =3D SIT_I(sbi); --=20 2.25.1 From nobody Mon Nov 25 02:29:12 2024 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB77F1E32D8 for ; Wed, 30 Oct 2024 10:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284347; cv=none; b=S5W6d3K/1gnHkmTop7MX4QWuMQ5lrdThnvQdxqiHe8yIRFy5kpIJjLb+TNTof++XxB5++uvae+Dr4/g35gTu/8GNFC5ZK3YhlxAo/i/dyzzSXDlfgx6jsd8eyaO4NUcd3uuQXt72VKE8pdB1Kic0Q+G7JUs7ON3m7d2HpzvZKKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730284347; c=relaxed/simple; bh=ByIW6xN2k1vSc+IxsAB9AEtTFIFXUpVw+1AjsVkisBc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ubl9XTH04T8NRUpaMlUGrreudIlYtAX0AJ+p8eKw69M76t95wa1BcH8734KYDwMj63i5CqDsmUgQeD11HAdpaGWWi8sJreWwdh98mqDsN004/Fzwe7waTCSHhuOf03QnUOP1uPOcnRS/li+Zw4EJBsuS3Gncbh1cWiw+XmyJGc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 49UAViG8026981; Wed, 30 Oct 2024 18:31:44 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Xdk1R4B4cz2KSK4X; Wed, 30 Oct 2024 18:31:07 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 30 Oct 2024 18:31:43 +0800 From: Yi Sun To: , CC: , , , , , , Subject: [PATCH v2 5/5] f2fs: Optimize f2fs_truncate_data_blocks_range() Date: Wed, 30 Oct 2024 18:31:36 +0800 Message-ID: <20241030103136.2874140-6-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241030103136.2874140-1-yi.sun@unisoc.com> References: <20241030103136.2874140-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 49UAViG8026981 Content-Type: text/plain; charset="utf-8" Function f2fs_invalidate_blocks() can process continuous blocks at a time, so f2fs_truncate_data_blocks_range() is optimized to use the new functionality of f2fs_invalidate_blocks(). Signed-off-by: Yi Sun --- fs/f2fs/file.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 13594bb502d1..3dbabe6be8e6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -612,6 +612,15 @@ static int f2fs_file_open(struct inode *inode, struct = file *filp) return finish_preallocate_blocks(inode); } =20 +static bool check_curr_block_is_consecutive(struct f2fs_sb_info *sbi, + block_t curr, block_t end) +{ + if (curr - end =3D=3D 1 || curr =3D=3D end) + return true; + else + return false; +} + void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) { struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); @@ -621,8 +630,27 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_d= ata *dn, int count) int cluster_index =3D 0, valid_blocks =3D 0; int cluster_size =3D F2FS_I(dn->inode)->i_cluster_size; bool released =3D !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks); + /* + * Temporary record location. + * When the current block and @blkaddr_end can be processed + * together, update the value of @blkaddr_end. + * When it is detected that current block is not continues with + * @blkaddr_end, it is necessary to process continues blocks + * range [blkaddr_start, blkaddr_end]. + */ + block_t blkaddr_start, blkaddr_end; + /*. + * To avoid processing various invalid data blocks. + * Because @blkaddr_start and @blkaddr_end may be assigned + * NULL_ADDR or invalid data blocks, @last_valid is used to + * record this situation. + */ + bool last_valid =3D false; + /* Process the last block separately? */ + bool last_one =3D true; =20 addr =3D get_dnode_addr(dn->inode, dn->node_page) + ofs; + blkaddr_start =3D blkaddr_end =3D le32_to_cpu(*addr); =20 /* Assumption: truncation starts with cluster */ for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) { @@ -638,24 +666,60 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_= data *dn, int count) } =20 if (blkaddr =3D=3D NULL_ADDR) - continue; + goto next; =20 f2fs_set_data_blkaddr(dn, NULL_ADDR); =20 if (__is_valid_data_blkaddr(blkaddr)) { if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE)) - continue; + goto next; if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr, DATA_GENERIC_ENHANCE)) - continue; + goto next; if (compressed_cluster) valid_blocks++; } =20 - f2fs_invalidate_blocks(sbi, blkaddr, 1); + + if (check_curr_block_is_consecutive(sbi, blkaddr, blkaddr_end)) { + /* + * The current block @blkaddr is continuous with + * @blkaddr_end, so @blkaddr_end is updated. + * And the f2fs_invalidate_blocks() is skipped + * until @blkaddr that cannot be processed + * together is encountered. + */ + blkaddr_end =3D blkaddr; + if (count =3D=3D 1) + last_one =3D false; + else + goto skip_invalid; + } + + f2fs_invalidate_blocks(sbi, blkaddr_start, + blkaddr_end - blkaddr_start + 1); + blkaddr_start =3D blkaddr_end =3D blkaddr; + + if (count =3D=3D 1 && last_one) + f2fs_invalidate_blocks(sbi, blkaddr, 1); + +skip_invalid: + last_valid =3D true; =20 if (!released || blkaddr !=3D COMPRESS_ADDR) nr_free++; + + continue; + +next: + /* If consecutive blocks have been recorded, we need to process them. */ + if (last_valid =3D=3D true) + f2fs_invalidate_blocks(sbi, blkaddr_start, + blkaddr_end - blkaddr_start + 1); + + blkaddr_start =3D blkaddr_end =3D le32_to_cpu(*(addr + 1)); + last_valid =3D false; + } =20 if (compressed_cluster) --=20 2.25.1