Message ID | 20230609131555.56651-1-frank.li@vivo.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp958155vqr; Fri, 9 Jun 2023 06:45:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6L6B+HZWggip6Qw4Q4uCMexyWp5g/Ip8RPe9uTiVEjLKmq+Yyf1wil3xZ5vEuHdUVjbwA1 X-Received: by 2002:a05:6a00:cc3:b0:654:9d3a:f96f with SMTP id b3-20020a056a000cc300b006549d3af96fmr1522635pfv.4.1686318307855; Fri, 09 Jun 2023 06:45:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686318307; cv=pass; d=google.com; s=arc-20160816; b=EMld75kobVteaJRyXZ4FTRmvFGR7zOn68UuFhZSS8ZNb6r2YrnkvHdRsDn0pyeGIvU BRFn7APUYonUck9Fl3dKGEKvE35zUpfBUvD/gm0QHZY0yf7lLw39B8A3LHYU/8XqQVsU iub0cvy5pPuXs+I9x+wf+UF8fzDdDo94g+Y+XvmsvPAYKfvOtYXsYJHZC3ZolvhmheZH dOCZFV7f+V03AF2DXfAFZbj99ytvXC4mtdK0orztDalI0weHDjb8EEkX/1KOTi9FRuk4 xHVo2SjFD8TEoyKdA7nbBMoBhCW8zqKf1zDjZhHswGAIxIfgsSH/VzI6B0DV/FgWQY7f hRgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=umCehp1ddvPRZ1k35Zb8VMKOFF6IlmsBoeOINWWsH5Q=; b=KZdGH8uNkCyU5XlBU7a6hz+yHtkxEWyrzyOvDR9TKJFGRYnxtjLr/fP9/nXvbGB0w3 Hqq7iE4jDT/4qe2xllohlunxXChYbaVjL0JponEQ3VM/JtenL++EvTNIcTKx4/HGkKhN 3Kq368vyLq6ZmZK70lIGPtm3OgKQduhmJ09NZtZJFGb9iU6cB/s4b0DlVHLVNNfnCkyY sRghH5cHQoyi6cKthxOs8U0uTLCF+QTkkJycKZrY5CfIT7P2lyINtBdluH4MwWmZL1TB 8HTZMB1oGcgkDawisX5hPkRQIaigaVVggW5hUMDYaZrizGDFIpTLdTvI+JVmeALcDfha k8Uw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=e5nyZFZR; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u197-20020a6379ce000000b00535bf852410si2602255pgc.313.2023.06.09.06.44.50; Fri, 09 Jun 2023 06:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=e5nyZFZR; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241367AbjFINQV (ORCPT <rfc822;liningstudo@gmail.com> + 99 others); Fri, 9 Jun 2023 09:16:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241298AbjFINQQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 9 Jun 2023 09:16:16 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2124.outbound.protection.outlook.com [40.107.255.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD4DE30CD for <linux-kernel@vger.kernel.org>; Fri, 9 Jun 2023 06:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tu7QYnoxXQ3MuLl+OyCcxNmjVebhnd9ZPT+n19LbWq1w3BFR4Iwcd8ij4kKSl4mNZ3TszX6oVY5v22nVmEqzdXzR4YsyReJ9MpRdiWwwVujfoLG5kYf89SszzjN4RRZlWKcN0DVQuAEV4FR32p90D1wjvNZpVG03SE/kYUu3F638U+viY2msc5REjk2Iv5vo+ps5lcKsj61399Bhua65vEKnpL009S+JnG1+njW+VNOr9bcRAsET7JvxAatU7QDlsbuLIifog+XQ4S2GpP3KgVilCUgRAnYETW42JT7sFSYrkQ53IFbARjaKWs89CqMyUYiRnsf+BHcvyeSsf0GCig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=umCehp1ddvPRZ1k35Zb8VMKOFF6IlmsBoeOINWWsH5Q=; b=H/rqX8XRRR+L2ra7jAG/kHbzHmTZNSOgyPEJ+2ehl4Yt2iqWK+eHF4awngPLIUoFaguficyH3KrXFxs11XQrQtBGnJCicIHjMFNqM8iNUxfUeyT95g+Fwb0K0x674WdtcptcfgBYIGfPzMyFhXNwtFj9f2fxoHfDb2BovRU8ihRd8aFPnNPtP4pQkztxrMsKmw8/ziqd3iMQye2uSJLXfke/cyC8+vGruthW4I9PLTCzuf1RcBQk6edfAUCokN2mr3CF3bace+g3DbFio4byi5RN7sUyKxgfRvfYt43sdKllFfaWd0H2mIg+n6A0rO6WPuVSutQ3uFEa3MXVdVPwog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=umCehp1ddvPRZ1k35Zb8VMKOFF6IlmsBoeOINWWsH5Q=; b=e5nyZFZRyWXEQGOXEXuHrcsz9VIRhCphDYsfihU9rm/dHIci9M0+k2Jm6V8gdEqlX8Lbx2uzLWKEYw8+TnYDWY61PfxL8RJhixU3DF4lRFSwy/UZzsPI5eHstxMXGzgo30jd/Xnpoz+0rliv5oopXNKpYrwlaVHLlpN+jNFN2PmZ2ubKEkRmlFCy9dbMm24ZfXXJxmxBjn2H3oNlmN2S39GKT4X/anNqzO3cBBJaeV0CjXquVP7anBn38jMzzDplEn4hEQGdV+5Zo5YMTmGEeRmUhzBKZ6r/vAzouqLqJXP+Moc0GaoVikAJWtskjcKWRC0LqCnla/w8kBq7IpT34A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TYZPR06MB4029.apcprd06.prod.outlook.com (2603:1096:400:23::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.32; Fri, 9 Jun 2023 13:16:09 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965%3]) with mapi id 15.20.6455.039; Fri, 9 Jun 2023 13:16:09 +0000 From: Yangtao Li <frank.li@vivo.com> To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org> Cc: Yangtao Li <frank.li@vivo.com>, Qi Han <hanqi@vivo.com>, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: compress: don't force buffered io when in COMPR_MODE_USER mode Date: Fri, 9 Jun 2023 21:15:55 +0800 Message-Id: <20230609131555.56651-1-frank.li@vivo.com> X-Mailer: git-send-email 2.39.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TYZPR06MB4029:EE_ X-MS-Office365-Filtering-Correlation-Id: e577d4d9-47ea-46df-0481-08db68ebafe2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gg5xYU57LgSLRAac+HIJ6osrjScqTFNILLIUVsjID6bFSygcCKxnv2WMM7Dh0nSBcfY7Ak8GEmDNs5QsfLLg8Gun85E24q611Q3M9IRYUgJQ1NAu65lgmPJVnmY+kUQy/o1921BH1z1sBO3QwFaSIgrh+6xYRI+DWTt8y5BZsGL8Ffk6cvYkWc4PmEuE+qTGvQPXtafeedCzfr17CyDR2hbuNjnhwbo0CzEsG+ftJVN1to/drXvQOxY743NkUS9SQlTprO5tHVgpIA+bBd+EWCVmHoYZdpzypLlOSXyqV45R7+4JLpO83vIgQ2LCb5QmiUg5IUmMqZ4T1O+M6Ff4filRuu4kynLQrJ4UK9O6NpcTd6H3fpVnsw0bqcurQTxYaRTtVv1CuzTuRRf7+1mv3ldoLBgVA3dA0w6fu8gM1mBOM6bcaWxfhKuxZ1UtKQoQ9XJi0IAj2tqDkSkiT4j0EWO6S1wPmlmbHy9DeC8exojy6uBs/RV5UUDUGRAbDu8gL9HvNRf1Pncse7cDavutF7RoSiDoQoY+LSXTzYWKVRbCZ1FmMCD4IQNooWzMjRp3wuU1NsK4t7BVj3eAFir/8Wetg3CeVlJTrk2LgFgNOkS+r8U72l5Du1OlkCfez44Q X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(136003)(39850400004)(396003)(451199021)(6512007)(1076003)(38100700002)(6506007)(2616005)(41300700001)(38350700002)(6666004)(6486002)(52116002)(186003)(26005)(83380400001)(478600001)(54906003)(110136005)(66556008)(66476007)(66946007)(316002)(5660300002)(4326008)(2906002)(8676002)(40140700001)(86362001)(8936002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QFFhz9WzN5PP9OLEU6kaZ8stx7GFFNOEQZNP8J9+GuR1Pnj6EMz0sjCh2vJzV9u0bQltj2O3lP2AUpCywcuVuHJ8icwDoWAZD03asWZPcXjZy5LY9mkTdnazzL3HH3rFiCEPGN2u0ead8dGfEUWDb4xBPueB6n0Rl6lOrLxlInUSaZTDnm+Of1B1/JWiPelzEH9pHxMi2nJy4JmRygtq53MT/pUhe1EDNkyzzI20nd/O9yd9qlJY/hi60XZpkOMIeo42ZnCKClauLOxYqfi+7BSR9ERmtjn/37fMQay2HVlA0befMbylFNisGhjQ/cJDW7UqsnD4GrXaJTRacllhOH7gyFSSQd/t6iEhzvFCfrHzdTm5d3IRhLjiaoZuoYxZbT41scLJPBsl1nIhz2FifKfTaCJFeGtX+a9N0u5U3bYwui5TcIDryVy1ggsCTQEQU8+gAvkf8A0oN9L3yZSnuMWwxoAeh9HHYSuKDvYyMD7nn0+0ikRtybJTtZCUgjksJ1Ptyt4I4khzWNITnrw09TYSrlJGs5y2am/kdWicAdQ0jHwPWOtuFfxMwKNubj/U33WXPxXJZuulI/Yp6F9ag+vA41msmFEtd7a5i2b/evoINHgxnejRyeQu2XMPAntoZDe0eRa7hRS+eJwVr6CXWJ+dZZxeMdevhoyr7FWHqEvGP9hYh1wpPaXJ/nXko0jwNQUK6RUJtEKQrk11htpB+a4jq7oYILrBxPQwmflg9kx+3kFzx7V/C1dE++HB66OpT5FqHSQ+/ZzQPwf/tFA7IrjPYagIJvxBqSpXzBsGXFpo3hnkoFnGGIqItZ/kdS4ZRLkrn6bAC3UNu2RLopzA9uqHhhhl0TPPk/7IYg6oHrplabpChVgPIw5Mn1Iz2jJd55Sm7xrNDt/VwMFJPrLgzXLVe9FuQp3Oaz06fZFch41Oh+aLb5C1LnYvGoZXEShxJq7XCJRQLQhhReIB0BVa9/B90zVUVQFwOk4CY9Ax6l3BNLRu4v0aZK+egw5vsPLFRfMfu9oWBeghXdTwB8BGSPf50vFIrziWvlfzFW0jniyFZ76YSBbs3uSmEvlUn9mzPqfWEDefisWsISp69NY2/sSltPDnNv6ZuSmwJzqOf+ZJoZcAQ1pVGsEArxPYG29+OArG2Ql45E9JkQidQ08rzb/V74VNquAHoxK6dEFdV5LicTvXnKy8rguaJzhSEl6F0gFJfv4X1G91CpnK38vLHfgQIWHF57GVOQ/y2KyivK9toi4sb9f3mFgYzAY8gH9+UnKLKpW2wrCg1xA6yqGBGLAZRTVi5JKzkdikdiC35Sjrh4mm40cMuAjRc0261J7A1Ug9yEi56Q7bqLFyi+tt5mW9QO/kGbsUyg7lM6D5O5mSuL0V33QvP7SzYETiLpWX0g7Jax3HRPBVmGDoS6LNhfZpQgiKqnUOS8ConJE/7Bc+z3ujibNFrUKhfgJXpaJii1bK/qccu9t+eC1X/vvZNh7Cp+bbxiahul0whB2diM/c6nEOKC4u5ahp0Og0+4/hl7ioUuLe+tdTV7k5gwTtQJW9B1Vu34MeqJLZo+fCjws4be6AMw2n0P1f8VafIgmD X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e577d4d9-47ea-46df-0481-08db68ebafe2 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2023 13:16:08.3521 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: azduNq+TZL/jYh00dSniVpAwrqS3qpsLVjXOSx08fl+7M629adGlxsY/1lv5+XjTmuV/P3DLP6TI1hVMCHlo7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB4029 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768232905868793850?= X-GMAIL-MSGID: =?utf-8?q?1768232905868793850?= |
Series |
f2fs: compress: don't force buffered io when in COMPR_MODE_USER mode
|
|
Commit Message
李扬韬
June 9, 2023, 1:15 p.m. UTC
It is observed that when in user compression mode (compress_extension=*), even though the file is not compressed, the file is still forced to use buffer io, which makes the AndroBench sequential read and write drop significantly. In fact, when the file is not compressed, we don't need to force it to buffer io. | w/o patch | w/ patch | seq read (MB/s) | 1320.068 | 3696.154 | seq write (MB/s) | 617.996 | 2978.478 | Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Qi Han <hanqi@vivo.com> Signed-off-by: Yangtao Li <frank.li@vivo.com> --- fs/f2fs/f2fs.h | 14 ++++++++++++++ fs/f2fs/file.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-)
Comments
On 2023/6/9 21:15, Yangtao Li wrote: > It is observed that when in user compression mode (compress_extension=*), > even though the file is not compressed, the file is still forced to use > buffer io, which makes the AndroBench sequential read and write drop > significantly. In fact, when the file is not compressed, we don't need > to force it to buffer io. > > | w/o patch | w/ patch | > seq read (MB/s) | 1320.068 | 3696.154 | > seq write (MB/s) | 617.996 | 2978.478 | > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Qi Han <hanqi@vivo.com> > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > fs/f2fs/f2fs.h | 14 ++++++++++++++ > fs/f2fs/file.c | 2 +- > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 1efcfd9e5a99..7f5472525310 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct inode *inode) > is_inode_flag_set(inode, FI_COMPRESSED_FILE); > } > > +static inline bool f2fs_is_compressed_file(struct inode *inode) > +{ > + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; > + > + if (compress_mode == COMPR_MODE_FS) > + return f2fs_compressed_file(inode); > + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || Should check dirty page as well? i_compr_blocks may increase after data writeback. Thanks, > + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || > + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) > + return true; > + > + return false; > +} > + > static inline bool f2fs_need_compress_data(struct inode *inode) > { > int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 74ecc9e20619..0698129b2165 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode *inode, int rw) > return true; > if (fsverity_active(inode)) > return true; > - if (f2fs_compressed_file(inode)) > + if (f2fs_is_compressed_file(inode)) > return true; > > /* disallow direct IO if any of devices has unaligned blksize */
On 2023/6/12 22:38, Chao Yu wrote: > On 2023/6/9 21:15, Yangtao Li wrote: >> It is observed that when in user compression mode >> (compress_extension=*), >> even though the file is not compressed, the file is still forced to use >> buffer io, which makes the AndroBench sequential read and write drop >> significantly. In fact, when the file is not compressed, we don't need >> to force it to buffer io. >> >> | w/o patch | w/ patch | >> seq read (MB/s) | 1320.068 | 3696.154 | >> seq write (MB/s) | 617.996 | 2978.478 | >> >> Fixes: 4c8ff7095bef ("f2fs: support data compression") >> Signed-off-by: Qi Han <hanqi@vivo.com> >> Signed-off-by: Yangtao Li <frank.li@vivo.com> >> --- >> fs/f2fs/f2fs.h | 14 ++++++++++++++ >> fs/f2fs/file.c | 2 +- >> 2 files changed, 15 insertions(+), 1 deletion(-) >> >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >> index 1efcfd9e5a99..7f5472525310 100644 >> --- a/fs/f2fs/f2fs.h >> +++ b/fs/f2fs/f2fs.h >> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >> inode *inode) >> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >> } >> +static inline bool f2fs_is_compressed_file(struct inode *inode) >> +{ >> + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >> + >> + if (compress_mode == COMPR_MODE_FS) >> + return f2fs_compressed_file(inode); >> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || > > Should check dirty page as well? i_compr_blocks may increase after > data writeback. > IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated when FI_ENABLE_COMPRESS is enabled. If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be updated after data writeback. So there is no need to additionally judge whether there is a dirty page? Thanks, > Thanks, > >> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >> + return true; >> + >> + return false; >> +} >> + >> static inline bool f2fs_need_compress_data(struct inode *inode) >> { >> int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index 74ecc9e20619..0698129b2165 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >> *inode, int rw) >> return true; >> if (fsverity_active(inode)) >> return true; >> - if (f2fs_compressed_file(inode)) >> + if (f2fs_is_compressed_file(inode)) >> return true; >> /* disallow direct IO if any of devices has unaligned blksize */
On 2023/6/13 12:14, Yangtao Li wrote: > > On 2023/6/12 22:38, Chao Yu wrote: >> On 2023/6/9 21:15, Yangtao Li wrote: >>> It is observed that when in user compression mode >>> (compress_extension=*), >>> even though the file is not compressed, the file is still forced to use >>> buffer io, which makes the AndroBench sequential read and write drop >>> significantly. In fact, when the file is not compressed, we don't need >>> to force it to buffer io. >>> >>> | w/o patch | w/ patch | >>> seq read (MB/s) | 1320.068 | 3696.154 | >>> seq write (MB/s) | 617.996 | 2978.478 | >>> >>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>> Signed-off-by: Qi Han <hanqi@vivo.com> >>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>> --- >>> fs/f2fs/f2fs.h | 14 ++++++++++++++ >>> fs/f2fs/file.c | 2 +- >>> 2 files changed, 15 insertions(+), 1 deletion(-) >>> >>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>> index 1efcfd9e5a99..7f5472525310 100644 >>> --- a/fs/f2fs/f2fs.h >>> +++ b/fs/f2fs/f2fs.h >>> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >>> inode *inode) >>> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >>> } >>> +static inline bool f2fs_is_compressed_file(struct inode *inode) >>> +{ >>> + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>> + >>> + if (compress_mode == COMPR_MODE_FS) >>> + return f2fs_compressed_file(inode); >>> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || >> >> Should check dirty page as well? i_compr_blocks may increase after >> data writeback. >> > IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated when > FI_ENABLE_COMPRESS is enabled. > > If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be > updated after data writeback. > > So there is no need to additionally judge whether there is a dirty page? Oh, user mode, that's correct. If we allow dio/aio on compress file, it needs to consider race case in between aio and ioc_compress_file. Thanks, > > > Thanks, > >> Thanks, >> >>> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >>> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >>> + return true; >>> + >>> + return false; >>> +} >>> + >>> static inline bool f2fs_need_compress_data(struct inode *inode) >>> { >>> int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>> index 74ecc9e20619..0698129b2165 100644 >>> --- a/fs/f2fs/file.c >>> +++ b/fs/f2fs/file.c >>> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >>> *inode, int rw) >>> return true; >>> if (fsverity_active(inode)) >>> return true; >>> - if (f2fs_compressed_file(inode)) >>> + if (f2fs_is_compressed_file(inode)) >>> return true; >>> /* disallow direct IO if any of devices has unaligned blksize */
On 2023/6/19 8:54, Chao Yu wrote: > On 2023/6/13 12:14, Yangtao Li wrote: >> >> On 2023/6/12 22:38, Chao Yu wrote: >>> On 2023/6/9 21:15, Yangtao Li wrote: >>>> It is observed that when in user compression mode >>>> (compress_extension=*), >>>> even though the file is not compressed, the file is still forced to >>>> use >>>> buffer io, which makes the AndroBench sequential read and write drop >>>> significantly. In fact, when the file is not compressed, we don't need >>>> to force it to buffer io. >>>> >>>> | w/o patch | w/ patch | >>>> seq read (MB/s) | 1320.068 | 3696.154 | >>>> seq write (MB/s) | 617.996 | 2978.478 | >>>> >>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>> Signed-off-by: Qi Han <hanqi@vivo.com> >>>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>>> --- >>>> fs/f2fs/f2fs.h | 14 ++++++++++++++ >>>> fs/f2fs/file.c | 2 +- >>>> 2 files changed, 15 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>>> index 1efcfd9e5a99..7f5472525310 100644 >>>> --- a/fs/f2fs/f2fs.h >>>> +++ b/fs/f2fs/f2fs.h >>>> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >>>> inode *inode) >>>> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >>>> } >>>> +static inline bool f2fs_is_compressed_file(struct inode *inode) >>>> +{ >>>> + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>> + >>>> + if (compress_mode == COMPR_MODE_FS) >>>> + return f2fs_compressed_file(inode); >>>> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || >>> >>> Should check dirty page as well? i_compr_blocks may increase after >>> data writeback. >>> >> IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated when >> FI_ENABLE_COMPRESS is enabled. >> >> If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be >> updated after data writeback. >> >> So there is no need to additionally judge whether there is a dirty page? > > Oh, user mode, that's correct. > > If we allow dio/aio on compress file, it needs to consider race case in > between aio and ioc_compress_file. The inode_lock is already held in f2fs_file_write_iter and f2fs_ioc_compress_file, I guess this is enough? What else? 4691 static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 4692 { 4693 struct inode *inode = file_inode(iocb->ki_filp); 4694 const loff_t orig_pos = iocb->ki_pos; 4695 const size_t orig_count = iov_iter_count(from); 4696 loff_t target_size; 4697 bool dio; 4698 bool may_need_sync = true; 4699 int preallocated; 4700 ssize_t ret; 4701 4702 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { 4703 ret = -EIO; 4704 goto out; 4705 } 4706 4707 if (!f2fs_is_compress_backend_ready(inode)) { 4708 ret = -EOPNOTSUPP; 4709 goto out; 4710 } 4711 4712 if (iocb->ki_flags & IOCB_NOWAIT) { 4713 if (!inode_trylock(inode)) { 4714 ret = -EAGAIN; 4715 goto out; 4716 } 4717 } else { 4718 inode_lock(inode); 4719 } 4115 static int f2fs_ioc_compress_file(struct file *filp) 4116 { 4117 struct inode *inode = file_inode(filp); 4118 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4119 pgoff_t page_idx = 0, last_idx; 4120 unsigned int blk_per_seg = sbi->blocks_per_seg; 4121 int cluster_size = F2FS_I(inode)->i_cluster_size; 4122 int count, ret; 4123 4124 if (!f2fs_sb_has_compression(sbi) || 4125 F2FS_OPTION(sbi).compress_mode != COMPR_MODE_USER) 4126 return -EOPNOTSUPP; 4127 4128 if (!(filp->f_mode & FMODE_WRITE)) 4129 return -EBADF; 4130 4131 if (!f2fs_compressed_file(inode)) 4132 return -EINVAL; 4133 4134 f2fs_balance_fs(sbi, true); 4135 4136 file_start_write(filp); 4137 inode_lock(inode); Thanks, > > Thanks, > >> >> >> Thanks, >> >>> Thanks, >>> >>>> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >>>> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >>>> + return true; >>>> + >>>> + return false; >>>> +} >>>> + >>>> static inline bool f2fs_need_compress_data(struct inode *inode) >>>> { >>>> int compress_mode = >>>> F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>> index 74ecc9e20619..0698129b2165 100644 >>>> --- a/fs/f2fs/file.c >>>> +++ b/fs/f2fs/file.c >>>> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >>>> *inode, int rw) >>>> return true; >>>> if (fsverity_active(inode)) >>>> return true; >>>> - if (f2fs_compressed_file(inode)) >>>> + if (f2fs_is_compressed_file(inode)) >>>> return true; >>>> /* disallow direct IO if any of devices has unaligned >>>> blksize */
On 2023/6/19 11:11, Yangtao Li wrote: > On 2023/6/19 8:54, Chao Yu wrote: > >> On 2023/6/13 12:14, Yangtao Li wrote: >>> >>> On 2023/6/12 22:38, Chao Yu wrote: >>>> On 2023/6/9 21:15, Yangtao Li wrote: >>>>> It is observed that when in user compression mode >>>>> (compress_extension=*), >>>>> even though the file is not compressed, the file is still forced to use >>>>> buffer io, which makes the AndroBench sequential read and write drop >>>>> significantly. In fact, when the file is not compressed, we don't need >>>>> to force it to buffer io. >>>>> >>>>> | w/o patch | w/ patch | >>>>> seq read (MB/s) | 1320.068 | 3696.154 | >>>>> seq write (MB/s) | 617.996 | 2978.478 | >>>>> >>>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>>> Signed-off-by: Qi Han <hanqi@vivo.com> >>>>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>>>> --- >>>>> fs/f2fs/f2fs.h | 14 ++++++++++++++ >>>>> fs/f2fs/file.c | 2 +- >>>>> 2 files changed, 15 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>>>> index 1efcfd9e5a99..7f5472525310 100644 >>>>> --- a/fs/f2fs/f2fs.h >>>>> +++ b/fs/f2fs/f2fs.h >>>>> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >>>>> inode *inode) >>>>> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >>>>> } >>>>> +static inline bool f2fs_is_compressed_file(struct inode *inode) >>>>> +{ >>>>> + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>> + >>>>> + if (compress_mode == COMPR_MODE_FS) >>>>> + return f2fs_compressed_file(inode); >>>>> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || >>>> >>>> Should check dirty page as well? i_compr_blocks may increase after >>>> data writeback. >>>> >>> IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated when >>> FI_ENABLE_COMPRESS is enabled. >>> >>> If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be >>> updated after data writeback. >>> >>> So there is no need to additionally judge whether there is a dirty page? >> >> Oh, user mode, that's correct. >> >> If we allow dio/aio on compress file, it needs to consider race case in >> between aio and ioc_compress_file. > > > The inode_lock is already held in f2fs_file_write_iter and f2fs_ioc_compress_file, I guess this is enough? > > What else? aio may complete outside inode lock, so it needs to call inode_dio_wait() in f2fs_ioc_compress_file() to avoid the race case? Thanks, > > > 4691 static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) > 4692 { > 4693 struct inode *inode = file_inode(iocb->ki_filp); > 4694 const loff_t orig_pos = iocb->ki_pos; > 4695 const size_t orig_count = iov_iter_count(from); > 4696 loff_t target_size; > 4697 bool dio; > 4698 bool may_need_sync = true; > 4699 int preallocated; > 4700 ssize_t ret; > 4701 > 4702 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { > 4703 ret = -EIO; > 4704 goto out; > 4705 } > 4706 > 4707 if (!f2fs_is_compress_backend_ready(inode)) { > 4708 ret = -EOPNOTSUPP; > 4709 goto out; > 4710 } > 4711 > 4712 if (iocb->ki_flags & IOCB_NOWAIT) { > 4713 if (!inode_trylock(inode)) { > 4714 ret = -EAGAIN; > 4715 goto out; > 4716 } > 4717 } else { > 4718 inode_lock(inode); > 4719 } > > > 4115 static int f2fs_ioc_compress_file(struct file *filp) > 4116 { > 4117 struct inode *inode = file_inode(filp); > 4118 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > 4119 pgoff_t page_idx = 0, last_idx; > 4120 unsigned int blk_per_seg = sbi->blocks_per_seg; > 4121 int cluster_size = F2FS_I(inode)->i_cluster_size; > 4122 int count, ret; > 4123 > 4124 if (!f2fs_sb_has_compression(sbi) || > 4125 F2FS_OPTION(sbi).compress_mode != COMPR_MODE_USER) > 4126 return -EOPNOTSUPP; > 4127 > 4128 if (!(filp->f_mode & FMODE_WRITE)) > 4129 return -EBADF; > 4130 > 4131 if (!f2fs_compressed_file(inode)) > 4132 return -EINVAL; > 4133 > 4134 f2fs_balance_fs(sbi, true); > 4135 > 4136 file_start_write(filp); > 4137 inode_lock(inode); > > > Thanks, > >> >> Thanks, >> >>> >>> >>> Thanks, >>> >>>> Thanks, >>>> >>>>> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >>>>> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >>>>> + return true; >>>>> + >>>>> + return false; >>>>> +} >>>>> + >>>>> static inline bool f2fs_need_compress_data(struct inode *inode) >>>>> { >>>>> int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>>> index 74ecc9e20619..0698129b2165 100644 >>>>> --- a/fs/f2fs/file.c >>>>> +++ b/fs/f2fs/file.c >>>>> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >>>>> *inode, int rw) >>>>> return true; >>>>> if (fsverity_active(inode)) >>>>> return true; >>>>> - if (f2fs_compressed_file(inode)) >>>>> + if (f2fs_is_compressed_file(inode)) >>>>> return true; >>>>> /* disallow direct IO if any of devices has unaligned blksize */
On 2023/6/19 12:04, Chao Yu wrote: > On 2023/6/19 11:11, Yangtao Li wrote: >> On 2023/6/19 8:54, Chao Yu wrote: >> >>> On 2023/6/13 12:14, Yangtao Li wrote: >>>> >>>> On 2023/6/12 22:38, Chao Yu wrote: >>>>> On 2023/6/9 21:15, Yangtao Li wrote: >>>>>> It is observed that when in user compression mode >>>>>> (compress_extension=*), >>>>>> even though the file is not compressed, the file is still forced >>>>>> to use >>>>>> buffer io, which makes the AndroBench sequential read and write drop >>>>>> significantly. In fact, when the file is not compressed, we don't >>>>>> need >>>>>> to force it to buffer io. >>>>>> >>>>>> | w/o patch | w/ patch | >>>>>> seq read (MB/s) | 1320.068 | 3696.154 | >>>>>> seq write (MB/s) | 617.996 | 2978.478 | >>>>>> >>>>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>>>> Signed-off-by: Qi Han <hanqi@vivo.com> >>>>>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>>>>> --- >>>>>> fs/f2fs/f2fs.h | 14 ++++++++++++++ >>>>>> fs/f2fs/file.c | 2 +- >>>>>> 2 files changed, 15 insertions(+), 1 deletion(-) >>>>>> >>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>>>>> index 1efcfd9e5a99..7f5472525310 100644 >>>>>> --- a/fs/f2fs/f2fs.h >>>>>> +++ b/fs/f2fs/f2fs.h >>>>>> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >>>>>> inode *inode) >>>>>> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >>>>>> } >>>>>> +static inline bool f2fs_is_compressed_file(struct inode *inode) >>>>>> +{ >>>>>> + int compress_mode = >>>>>> F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>>> + >>>>>> + if (compress_mode == COMPR_MODE_FS) >>>>>> + return f2fs_compressed_file(inode); >>>>>> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || >>>>> >>>>> Should check dirty page as well? i_compr_blocks may increase after >>>>> data writeback. >>>>> >>>> IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated >>>> when >>>> FI_ENABLE_COMPRESS is enabled. >>>> >>>> If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be >>>> updated after data writeback. >>>> >>>> So there is no need to additionally judge whether there is a dirty >>>> page? >>> >>> Oh, user mode, that's correct. >>> >>> If we allow dio/aio on compress file, it needs to consider race case in >>> between aio and ioc_compress_file. >> >> >> The inode_lock is already held in f2fs_file_write_iter and >> f2fs_ioc_compress_file, I guess this is enough? >> >> What else? > > aio may complete outside inode lock, so it needs to call inode_dio_wait() > in f2fs_ioc_compress_file() to avoid the race case? How about adding this below? diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f45d05c13ae5..5021d13e788b 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4146,6 +4146,10 @@ static int f2fs_ioc_compress_file(struct file *filp) goto out; } + /* avoid race case between aio and ioc_compress_file */ + if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) + inode_dio_wait(inode); + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (ret) goto out; Thanks, > > Thanks, > >> >> >> 4691 static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct >> iov_iter *from) >> 4692 { >> 4693 struct inode *inode = file_inode(iocb->ki_filp); >> 4694 const loff_t orig_pos = iocb->ki_pos; >> 4695 const size_t orig_count = iov_iter_count(from); >> 4696 loff_t target_size; >> 4697 bool dio; >> 4698 bool may_need_sync = true; >> 4699 int preallocated; >> 4700 ssize_t ret; >> 4701 >> 4702 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { >> 4703 ret = -EIO; >> 4704 goto out; >> 4705 } >> 4706 >> 4707 if (!f2fs_is_compress_backend_ready(inode)) { >> 4708 ret = -EOPNOTSUPP; >> 4709 goto out; >> 4710 } >> 4711 >> 4712 if (iocb->ki_flags & IOCB_NOWAIT) { >> 4713 if (!inode_trylock(inode)) { >> 4714 ret = -EAGAIN; >> 4715 goto out; >> 4716 } >> 4717 } else { >> 4718 inode_lock(inode); >> 4719 } >> >> >> 4115 static int f2fs_ioc_compress_file(struct file *filp) >> 4116 { >> 4117 struct inode *inode = file_inode(filp); >> 4118 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); >> 4119 pgoff_t page_idx = 0, last_idx; >> 4120 unsigned int blk_per_seg = sbi->blocks_per_seg; >> 4121 int cluster_size = F2FS_I(inode)->i_cluster_size; >> 4122 int count, ret; >> 4123 >> 4124 if (!f2fs_sb_has_compression(sbi) || >> 4125 F2FS_OPTION(sbi).compress_mode != >> COMPR_MODE_USER) >> 4126 return -EOPNOTSUPP; >> 4127 >> 4128 if (!(filp->f_mode & FMODE_WRITE)) >> 4129 return -EBADF; >> 4130 >> 4131 if (!f2fs_compressed_file(inode)) >> 4132 return -EINVAL; >> 4133 >> 4134 f2fs_balance_fs(sbi, true); >> 4135 >> 4136 file_start_write(filp); >> 4137 inode_lock(inode); >> >> >> Thanks, >> >>> >>> Thanks, >>> >>>> >>>> >>>> Thanks, >>>> >>>>> Thanks, >>>>> >>>>>> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >>>>>> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >>>>>> + return true; >>>>>> + >>>>>> + return false; >>>>>> +} >>>>>> + >>>>>> static inline bool f2fs_need_compress_data(struct inode *inode) >>>>>> { >>>>>> int compress_mode = >>>>>> F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>>>> index 74ecc9e20619..0698129b2165 100644 >>>>>> --- a/fs/f2fs/file.c >>>>>> +++ b/fs/f2fs/file.c >>>>>> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >>>>>> *inode, int rw) >>>>>> return true; >>>>>> if (fsverity_active(inode)) >>>>>> return true; >>>>>> - if (f2fs_compressed_file(inode)) >>>>>> + if (f2fs_is_compressed_file(inode)) >>>>>> return true; >>>>>> /* disallow direct IO if any of devices has unaligned >>>>>> blksize */
On 2023/6/19 17:31, Yangtao Li wrote: > On 2023/6/19 12:04, Chao Yu wrote: > >> On 2023/6/19 11:11, Yangtao Li wrote: >>> On 2023/6/19 8:54, Chao Yu wrote: >>> >>>> On 2023/6/13 12:14, Yangtao Li wrote: >>>>> >>>>> On 2023/6/12 22:38, Chao Yu wrote: >>>>>> On 2023/6/9 21:15, Yangtao Li wrote: >>>>>>> It is observed that when in user compression mode >>>>>>> (compress_extension=*), >>>>>>> even though the file is not compressed, the file is still forced >>>>>>> to use >>>>>>> buffer io, which makes the AndroBench sequential read and write drop >>>>>>> significantly. In fact, when the file is not compressed, we don't >>>>>>> need >>>>>>> to force it to buffer io. >>>>>>> >>>>>>> | w/o patch | w/ patch | >>>>>>> seq read (MB/s) | 1320.068 | 3696.154 | >>>>>>> seq write (MB/s) | 617.996 | 2978.478 | >>>>>>> >>>>>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>>>>> Signed-off-by: Qi Han <hanqi@vivo.com> >>>>>>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>>>>>> --- >>>>>>> fs/f2fs/f2fs.h | 14 ++++++++++++++ >>>>>>> fs/f2fs/file.c | 2 +- >>>>>>> 2 files changed, 15 insertions(+), 1 deletion(-) >>>>>>> >>>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>>>>>> index 1efcfd9e5a99..7f5472525310 100644 >>>>>>> --- a/fs/f2fs/f2fs.h >>>>>>> +++ b/fs/f2fs/f2fs.h >>>>>>> @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct >>>>>>> inode *inode) >>>>>>> is_inode_flag_set(inode, FI_COMPRESSED_FILE); >>>>>>> } >>>>>>> +static inline bool f2fs_is_compressed_file(struct inode *inode) >>>>>>> +{ >>>>>>> + int compress_mode = >>>>>>> F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>>>> + >>>>>>> + if (compress_mode == COMPR_MODE_FS) >>>>>>> + return f2fs_compressed_file(inode); >>>>>>> + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || >>>>>> >>>>>> Should check dirty page as well? i_compr_blocks may increase after >>>>>> data writeback. >>>>>> >>>>> IIUC, in COMPR_MODE_USER mode, i_compr_blocks will only be updated >>>>> when >>>>> FI_ENABLE_COMPRESS is enabled. >>>>> >>>>> If FI_ENABLE_COMPRESS is not enabled, i_compr_blocks will never be >>>>> updated after data writeback. >>>>> >>>>> So there is no need to additionally judge whether there is a dirty >>>>> page? >>>> >>>> Oh, user mode, that's correct. >>>> >>>> If we allow dio/aio on compress file, it needs to consider race case in >>>> between aio and ioc_compress_file. >>> >>> >>> The inode_lock is already held in f2fs_file_write_iter and >>> f2fs_ioc_compress_file, I guess this is enough? >>> >>> What else? >> >> aio may complete outside inode lock, so it needs to call inode_dio_wait() >> in f2fs_ioc_compress_file() to avoid the race case? > > > How about adding this below? > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index f45d05c13ae5..5021d13e788b 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -4146,6 +4146,10 @@ static int f2fs_ioc_compress_file(struct file *filp) > goto out; > } > > + /* avoid race case between aio and ioc_compress_file */ > + if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) f2fs_ioc_compress_file() has already checked the mode? Thanks, > + inode_dio_wait(inode); > + > ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); > if (ret) > goto out; > > > Thanks, > > >> >> Thanks, >> >>> >>> >>> 4691 static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct >>> iov_iter *from) >>> 4692 { >>> 4693 struct inode *inode = file_inode(iocb->ki_filp); >>> 4694 const loff_t orig_pos = iocb->ki_pos; >>> 4695 const size_t orig_count = iov_iter_count(from); >>> 4696 loff_t target_size; >>> 4697 bool dio; >>> 4698 bool may_need_sync = true; >>> 4699 int preallocated; >>> 4700 ssize_t ret; >>> 4701 >>> 4702 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { >>> 4703 ret = -EIO; >>> 4704 goto out; >>> 4705 } >>> 4706 >>> 4707 if (!f2fs_is_compress_backend_ready(inode)) { >>> 4708 ret = -EOPNOTSUPP; >>> 4709 goto out; >>> 4710 } >>> 4711 >>> 4712 if (iocb->ki_flags & IOCB_NOWAIT) { >>> 4713 if (!inode_trylock(inode)) { >>> 4714 ret = -EAGAIN; >>> 4715 goto out; >>> 4716 } >>> 4717 } else { >>> 4718 inode_lock(inode); >>> 4719 } >>> >>> >>> 4115 static int f2fs_ioc_compress_file(struct file *filp) >>> 4116 { >>> 4117 struct inode *inode = file_inode(filp); >>> 4118 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); >>> 4119 pgoff_t page_idx = 0, last_idx; >>> 4120 unsigned int blk_per_seg = sbi->blocks_per_seg; >>> 4121 int cluster_size = F2FS_I(inode)->i_cluster_size; >>> 4122 int count, ret; >>> 4123 >>> 4124 if (!f2fs_sb_has_compression(sbi) || >>> 4125 F2FS_OPTION(sbi).compress_mode != >>> COMPR_MODE_USER) >>> 4126 return -EOPNOTSUPP; >>> 4127 >>> 4128 if (!(filp->f_mode & FMODE_WRITE)) >>> 4129 return -EBADF; >>> 4130 >>> 4131 if (!f2fs_compressed_file(inode)) >>> 4132 return -EINVAL; >>> 4133 >>> 4134 f2fs_balance_fs(sbi, true); >>> 4135 >>> 4136 file_start_write(filp); >>> 4137 inode_lock(inode); >>> >>> >>> Thanks, >>> >>>> >>>> Thanks, >>>> >>>>> >>>>> >>>>> Thanks, >>>>> >>>>>> Thanks, >>>>>> >>>>>>> + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || >>>>>>> + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) >>>>>>> + return true; >>>>>>> + >>>>>>> + return false; >>>>>>> +} >>>>>>> + >>>>>>> static inline bool f2fs_need_compress_data(struct inode *inode) >>>>>>> { >>>>>>> int compress_mode = >>>>>>> F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; >>>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>>>>> index 74ecc9e20619..0698129b2165 100644 >>>>>>> --- a/fs/f2fs/file.c >>>>>>> +++ b/fs/f2fs/file.c >>>>>>> @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode >>>>>>> *inode, int rw) >>>>>>> return true; >>>>>>> if (fsverity_active(inode)) >>>>>>> return true; >>>>>>> - if (f2fs_compressed_file(inode)) >>>>>>> + if (f2fs_is_compressed_file(inode)) >>>>>>> return true; >>>>>>> /* disallow direct IO if any of devices has unaligned >>>>>>> blksize */
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 1efcfd9e5a99..7f5472525310 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3168,6 +3168,20 @@ static inline int f2fs_compressed_file(struct inode *inode) is_inode_flag_set(inode, FI_COMPRESSED_FILE); } +static inline bool f2fs_is_compressed_file(struct inode *inode) +{ + int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; + + if (compress_mode == COMPR_MODE_FS) + return f2fs_compressed_file(inode); + else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) || + is_inode_flag_set(inode, FI_COMPRESS_RELEASED) || + is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) + return true; + + return false; +} + static inline bool f2fs_need_compress_data(struct inode *inode) { int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 74ecc9e20619..0698129b2165 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -821,7 +821,7 @@ static bool f2fs_force_buffered_io(struct inode *inode, int rw) return true; if (fsverity_active(inode)) return true; - if (f2fs_compressed_file(inode)) + if (f2fs_is_compressed_file(inode)) return true; /* disallow direct IO if any of devices has unaligned blksize */