From nobody Wed Dec 31 05:24:07 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C097DC4332F for ; Tue, 7 Nov 2023 08:14:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233677AbjKGIOK (ORCPT ); Tue, 7 Nov 2023 03:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233590AbjKGIOI (ORCPT ); Tue, 7 Nov 2023 03:14:08 -0500 Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8771FE8; Tue, 7 Nov 2023 00:14:03 -0800 (PST) X-QQ-mid: bizesmtp91t1699344838tve14rzx Received: from localhost.localdomain ( [175.11.90.246]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 07 Nov 2023 16:13:52 +0800 (CST) X-QQ-SSF: 00400000000000O0T000000A0000000 X-QQ-FEAT: 3M0okmaRx3gmxPjUV56yDKvB3Uhj8OcIpw7vWvpFGbsFfrB+bfwV7TozelY5e DMI/DxjOU8Tal584vSNyxOx5pZja88QCqwwjIl0o4CnUzPFLiXAU5V+M/gM+ILYnZlGx2fL Jtl2leZXWwQhqffFZSUUQEocdjWH3F4eOS62spWgc7UHKQqsP8msvrB1ZrTyn/0osDH2IbE vLMPurMnhNfp3gYSRyxXgXcSFR8EijFT4Tc5E7FQEEtmDyQ5kGlsh+q0H5Fhu9zhx67geNf LIX4c7sTyfsZqkCglfVxYcWEEYPYE2251UY5+kro/DpLtPKHGkK0BdTXZKmtZBmMBpLtKWV B1POWAVC+ErxfxG5NqfZuSDd+jfAvfTIqZSM81S0nMdu5b7Xn/ktDwb+Q498ZuzIU6ci3Qs X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11280650343400386784 From: Zhou Jifeng To: zhoujifeng@kylinos.com.cn Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, miklos@szeredi.hu Subject: [PATCH v2] fuse: Track process write operations in both direct and writethrough modes Date: Tue, 7 Nov 2023 16:13:50 +0800 Message-Id: <20231107081350.14472-1-zhoujifeng@kylinos.com.cn> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20231028065912.6084-1-zhoujifeng@kylinos.com.cn> References: <20231028065912.6084-1-zhoujifeng@kylinos.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:kylinos.com.cn:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Due to the fact that fuse does not count the write IO of processes in the direct and writethrough write modes, user processes cannot track write_bytes through the =E2=80=9C/proc/[pid]/io=E2=80=9D path. For example,= the system tool iotop cannot count the write operations of the corresponding process. Signed-off-by: Zhou Jifeng --- v1 -> v2: Fix "Miss error code" issue fs/fuse/file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 1cdb6327511e..4846ab8c01cf 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, unsigned int open_flags, int opcode, @@ -1305,6 +1306,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *io= cb, struct iov_iter *from) ssize_t written =3D 0; struct inode *inode =3D mapping->host; ssize_t err; + ssize_t count; struct fuse_conn *fc =3D get_fuse_conn(inode); =20 if (fc->writeback_cache) { @@ -1330,6 +1332,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *io= cb, struct iov_iter *from) if (err <=3D 0) goto out; =20 + count =3D err; + task_io_account_write(count); + err =3D file_remove_privs(file); if (err) goto out; @@ -1600,6 +1605,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *i= ocb, struct iov_iter *from) =20 res =3D generic_write_checks(iocb, from); if (res > 0) { + task_io_account_write(res); if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { res =3D fuse_direct_IO(iocb, from); } else { --=20 2.18.1