From patchwork Wed Dec 11 00:14:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: LongPing Wei X-Patchwork-Id: 13902628 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB21EE7717F for ; Wed, 11 Dec 2024 00:14:54 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tLANT-0004mX-1t; Wed, 11 Dec 2024 00:14:54 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tLANR-0004mQ-Jo for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2024 00:14:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JY/egANZ1IlZmwOkWBtDSUQisRRSOI7ZL/UXKhOuitQ=; b=E1oG+7mkYf9PFDC8T576iiYcuy h2ALRTk7FqpqfbGId7hNeMBIiVG/hpEXtsg6lpJt+ZJvr7zKAfkJpJV+TrukFL5Nsssb8JWpomezL ehTHB5XCEazrMHwU2hKybkeaC4gFgghGAP6lrF4PwygErEISTaoWpd1v3prtsRtgisOA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=JY/egANZ1IlZmwOkWBtDSUQisRRSOI7ZL/UXKhOuitQ=; b=Q 9d9Mmo6oixEao9jvGEjAH/ClM1afC5gmvQUA6yvn/EirvPKFWCi/XjL4yWR5AaVhf3kUys7m7+Tob 95XrnDU7JswTswSTvdl6uDxFarlfRbkhfg4I7lLj/MuZMJNIlG4jj6ei/mz3WvOVRP2TtnWNaTeLW 8kok3Ipibd3efXI8=; Received: from mail-eastasiaazon11010044.outbound.protection.outlook.com ([52.101.128.44] helo=HK2PR02CU002.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tLANQ-0002RU-4I for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2024 00:14:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sa06drDxSjS9QzvrbGaodh5Qnl7tHz4I2Hg4ILyBjro238lGsKoTlk7sIOs64kcwmQ1VTZoMNYSaIiPInlmsWWv+APZVsZc4Lk0mjVCsNWcCn/HLUnnINzfyZSqB1uFJnu4GQY+f31MwMLxlyEnnvAPHK7Rr0NuTbMAf+97+S9WOjh15T8sDfxuII52DcwlKdfusauvggkWMWeEqQWByK/7puGcwjTpqJnIqKJNXnz1e+f/om/NFzYaAN+FiK+dqFgkIQ8dltATOZsfkJTIOS3RP76Z0DhytutIBUZ62MguCavL8cmPrj1zpNpY4i+pr+sUhHiuJwRs4xNUOjjkFXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=JY/egANZ1IlZmwOkWBtDSUQisRRSOI7ZL/UXKhOuitQ=; b=iSH2ZbQsvgUV+hm+6iqZqVZ08gnoK7H9AK6UcMK3cQQiCxZotxZgZ8RBkykP+jbLOn7w6EHyMFBMhcxp1smq52efUoVK9fH3lO9+SMuroFxCGBzjBtXYPWuOaQjrJvJXKui85pc4AMUheiy57v77OZ/o6gTRmAGz0z/JBeXskuMuy+Cta5lZaUtaDKIw37M7Y5XMezOfj5eSTu0iMmDHz/CgA24Uzy0riH7LObntLgDU7cFNd8k+7apNaLNev0hJGITiELWxAeP29NzyFVSkMv7P9Hrb1ypSJGaudrPZHdLt+bu43XUh8welBMw2/4yAxetygLP2gewcbbBsEF7TSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JY/egANZ1IlZmwOkWBtDSUQisRRSOI7ZL/UXKhOuitQ=; b=u/EjtYexEg8uN231MT91zivkDnYzQpwaNIsZUf63HA/s/C2TxzJlJtsSW6vgz7lK0GxMl2Ce/Lc+dn9766yRaKA2BuxTuYvi0dGIRFGkUcNbxGcXw/mXS923p7Fpi6mL/IcrcXcSPi1neodbAGg4WMmpihT6iYXHNPcJ/QFaE4w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEZPR02MB7967.apcprd02.prod.outlook.com (2603:1096:101:22a::14) by SEZPR02MB5591.apcprd02.prod.outlook.com (2603:1096:101:38::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 00:14:35 +0000 Received: from SEZPR02MB7967.apcprd02.prod.outlook.com ([fe80::5723:5b88:ed4c:d49b]) by SEZPR02MB7967.apcprd02.prod.outlook.com ([fe80::5723:5b88:ed4c:d49b%3]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 00:14:35 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 11 Dec 2024 08:14:04 +0800 Message-Id: <20241211001404.4120186-1-weilongping@oppo.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0028.apcprd02.prod.outlook.com (2603:1096:4:1f4::6) To SEZPR02MB7967.apcprd02.prod.outlook.com (2603:1096:101:22a::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR02MB7967:EE_|SEZPR02MB5591:EE_ X-MS-Office365-Filtering-Correlation-Id: a16f061e-ed67-4977-f8e7-08dd1978cb18 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: c1JKsxJt4xyIHIiheV8FiZK0tF3CLLZsSjSv3RiJAMduRAuCb9l8ivT2l0n7egW1pgl5182tAXWbme5Zm+9vWFbWBMH9QP8lGRVbTrAfIjZ117fF/yEg5VwI8MxrJD57Vqp9x5XKPe8fHxDGT69AWa2l2Sd7BoXXwrOOt5T3Jgq9H/tky+KgsXG5JOQIlmt4xt2FufnjzI81gmJ50lci8ClgbqjfE6yTcbdTcxEzll++I6wpOWO2sLLkCUfEEMMdo7eHG8cYMcA09xxaMlZRmH+nfL1AToNYHvHyujgCOl2NxLFSdYE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33HUFBE8OIdu4iJfPVIKaa8Cw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR02MB7967.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(52116014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FxtamBhPmf+kfNN4KbxTOlZ3lxFeR2GATnQ9N1UhKQkw/w4P1bpG5mv2hiWi07YYl1f1dGMCUm0qXODBUwdy8z2NMyldclInnfSkV0eprgVeblQJ3Kj61jKwpXnEjhZ94Lifb29SCGHjKIwWviZNTdf6HqYAYaddH8eXX8wuicoc67u70tbeGk0F6ZrTMbaRRenXt4ByEzGE11DGosoXER/ye8zDQABuyrJd9GX9Jpfv2R7xpY5ymzfMQPnNA2nK1hVwfKWEk80anK5M8lBNtAkRcSBd5oVIM5u+XsgftlMVZo7ItMI5tI6O5AYDo107EiDRGU4jjpPoVAVlDuETtnWMAYDjhhtp333tWXkjUBXFtYFsctnRovZfuIVDP8ylrD8QI2Tr+nin2vRN7clJ1GBDn7dLAaIvnjmEYRYo6aYEqPnUwvtFfO48VWtJUFlsluSeEohOPMRBmbyWTs1wPKEAOiolpP9WjqqUN6mwtwVRn/nw8VH1F8ND7Esp/5nJqTyIYNgpN0FEaC3gQYpaBeJFujjmmJ466s5PAmBuHQC9nZuee21l7QbLY9VpJuhMEvpxaRFsXIAwRejFXy3EKtEZbaF3oTR5shCuRcSN4+RABAji0S0qgBkgMy0Cl2+I0PszVmrrPMU9fFqMK6jNMc+wwN+1cTqt2yyZbNrhyh/0bCXemr037redsbKt7i9w2NFSVuXyK3OzKFJATs4S9d6xirAO6T//U0uQyTQPJkjKXIPKz46n/MXjTF91RhlnwDtwrptPZQRttQPcO7ESbpZbAiolyX6Pu8bDoG9ubcWJ5cVLIMwfdDaS0wYJjOVziP3jpBCv0Ep3t8JXwvIDpg4nyrJUlFFitYlz9P3L3GeV41if2aM5V1utc4Gg3RdtQE+HC/17CeHE/v4R79MDLm5r5xis6e/jZmoH71OcYy8F2cE2N9IjTR6xEffSyOGcBYnXdcvg1DwEzOM380ilaCeAanvtHXMxYJ+9TvQydJCa5QZnhg9NPglFsGpbX2T56ZwKPb7l+YoA7xlOD5sfPGJafncF40AojpOkujuT/Gq7kWajokRi1AbVDy/7XG6zet/bilMnzAxIDr7dNx9/vrPsCaUWqiN7SiSv9d+4fArUX9BvYD3DlISzJRLGAS4X/L3Y/IgC9puywwZ67diQ9EdloccxDkoFKQ3K6sisLgAmWUPdb9ENwpxbSGFIsQr+1VnfpWpj4lR4y/BzO/j5yMN0dF0fZ1ryMvMgTAGHycr3ovPOD4h7DVsW3CkqbkkzgzOSDcVdWr/JyFblp/+/UGlyHV1P8ixKsliPCfjFoZ/OB0vc7H+38tCTLxQ9f5OFLY/JZEBvbMC8Bqe3Only/HnRJBszuY9RZTF+RAr0Od1MlodQvPotyiMdBCN0pB53ksSfMnY4b5e/BvQGhEQ8MW5p45MRNz56rjW4r2Xs+Ku8zagNb22ZzVKwYuGYf3dPCm8xDk9VRj76Uzj7WuTXGQ+kyibPDJUIwpZxcl0/RpBumFFb2CTtCNAiT+lK/oWQ+UquKRSp4i9EG2+dCDHvEnF+cQvc3sMnJaeVaC1mUpWq8A6n4jwEXmM++HUzm4/RshLnIPDIADtLDsEFbbh4pg== X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a16f061e-ed67-4977-f8e7-08dd1978cb18 X-MS-Exchange-CrossTenant-AuthSource: SEZPR02MB7967.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 00:14:35.2946 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bKUJ9nvXFNVXJftQ5I/dYNbS8cVsIJ7ciwWiifNtY4N2RQTH+IJDPWggrpMGuAhC+37FhabUpOtXRbrkNzuL8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB5591 X-Headers-End: 1tLANQ-0002RU-4I Subject: [f2fs-dev] [PATCH v2 1/2] f2fs-tools: use pread and pwrite when they are available. X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: LongPing Wei via Linux-f2fs-devel From: LongPing Wei Reply-To: LongPing Wei Cc: panglu2022@gmail.com, LongPing Wei , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch wants to reduce the number of system calls to improve performance. pread and pwrite will only be used when the target platform support them. Signed-off-by: LongPing Wei Reviewed-by: Sheng Yong Reviewed-by: Chao Yu --- configure.ac | 4 +++- lib/libf2fs_io.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 2053a65..ddfc3b0 100644 --- a/configure.ac +++ b/configure.ac @@ -182,6 +182,7 @@ AC_TYPE_SIZE_T AC_FUNC_GETMNTENT AC_CHECK_FUNCS_ONCE([ add_key + clock_gettime fallocate fsetxattr fstat @@ -192,8 +193,9 @@ AC_CHECK_FUNCS_ONCE([ getuid keyctl memset + pread + pwrite setmntent - clock_gettime ]) AS_IF([test "$ac_cv_header_byteswap_h" = "yes"], diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c index 520ae03..2030440 100644 --- a/lib/libf2fs_io.c +++ b/lib/libf2fs_io.c @@ -279,6 +279,12 @@ static int dcache_io_read(long entry, __u64 offset, off_t blk) if (fd < 0) return fd; +#ifdef HAVE_PREAD + if (pread(fd, dcache_buf + entry * F2FS_BLKSIZE, F2FS_BLKSIZE, offset) < 0) { + MSG(0, "\n pread() fail.\n"); + return -1; + } +#else if (lseek(fd, offset, SEEK_SET) < 0) { MSG(0, "\n lseek fail.\n"); return -1; @@ -287,6 +293,7 @@ static int dcache_io_read(long entry, __u64 offset, off_t blk) MSG(0, "\n read() fail.\n"); return -1; } +#endif dcache_lastused[entry] = ++dcache_usetick; dcache_valid[entry] = true; dcache_blk[entry] = blk; @@ -393,10 +400,15 @@ int dev_read_version(void *buf, __u64 offset, size_t len) { if (c.sparse_mode) return 0; +#ifdef HAVE_RPEAD + if (pread(c.kd, buf, len, (off_t)offset) < 0) + return -1; +#else if (lseek(c.kd, (off_t)offset, SEEK_SET) < 0) return -1; if (read(c.kd, buf, len) < 0) return -1; +#endif return 0; } @@ -535,10 +547,15 @@ int dev_read(void *buf, __u64 offset, size_t len) fd = __get_device_fd(&offset); if (fd < 0) return fd; +#ifdef HAVE_PREAD + if (pread(fd, buf, len, (off_t)offset) < 0) + return -1; +#else if (lseek(fd, (off_t)offset, SEEK_SET) < 0) return -1; if (read(fd, buf, len) < 0) return -1; +#endif return 0; } @@ -615,9 +632,6 @@ static int __dev_write(void *buf, __u64 offset, size_t len, enum rw_hint whint) if (fd < 0) return fd; - if (lseek(fd, (off_t)offset, SEEK_SET) < 0) - return -1; - #if ! defined(__MINGW32__) if (c.need_whint && (c.whint != whint)) { u64 hint = whint; @@ -629,8 +643,15 @@ static int __dev_write(void *buf, __u64 offset, size_t len, enum rw_hint whint) } #endif +#ifdef HAVE_PWRITE + if (pwrite(fd, buf, len, (off_t)offset) < 0) + return -1; +#else + if (lseek(fd, (off_t)offset, SEEK_SET) < 0) + return -1; if (write(fd, buf, len) < 0) return -1; +#endif c.need_fsync = true; @@ -663,10 +684,15 @@ int dev_write_block(void *buf, __u64 blk_addr, enum rw_hint whint) int dev_write_dump(void *buf, __u64 offset, size_t len) { +#ifdef HAVE_PWRITE + if (pwrite(c.dump_fd, buf, len, (off_t)offset) < 0) + return -1; +#else if (lseek(c.dump_fd, (off_t)offset, SEEK_SET) < 0) return -1; if (write(c.dump_fd, buf, len) < 0) return -1; +#endif return 0; }