Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5162717iob; Mon, 9 May 2022 09:55:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxphWUEFPNvaCnXx1/iagh13S/Q5HIPfvxHQ4d7ibkBSQ7jhNOst/k5vCPXkUxqeJH8IiaJ X-Received: by 2002:a05:6214:cac:b0:45a:88b7:9530 with SMTP id s12-20020a0562140cac00b0045a88b79530mr14277918qvs.58.1652115355192; Mon, 09 May 2022 09:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652115355; cv=none; d=google.com; s=arc-20160816; b=nvYh+jagY61MkC5f2XsesyDXZfFh+YqT70XaIqnIkBOjyxyCx1qmcqZtZs/zBQxysS Tem1GM28i13VYyCZRYeHo4ErxXTXrGHAtaSjA0fiCbiAJ9Wv4rsBxD5dxiUuxGxH9Blr m8hRrg3QgRG5Nx0e1RlBP9jCiFcgw/yCGzqCuJ4EO5VNKFU0rY5MLXEOgtBss4jsNPWs XYDm3aIF7N/M0PXqZHzdHb5ZCQYHelBRsyKzGzQg+FJEEaPyFEVn1ariy2vD2sb3chJd K9OTTqWe4ASL+lV6HfhkRl1uYi06pFfuOL6t7+mdv4CJhbaqinI+QlOItRRlx8GPxxHV v3hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=yP76u3REy6mirl+riO5eO4fLZcEDVLtTL+BRbXCAU3M=; b=GfLfc2tHjpOnbP6C5WMb2nN3krDenIUTJJ4oTivzqp6ZaMkzgT9tPKC6C7tQLtAKhP lLbvYFRPbdlufo5sU8Ax5h+2h7V3E4t0We9QAa8dU+NOWCTx8W5nPu70mzX5is8H9zvf UWZmEZOffQbTJu3dlB2uKyBUz7r7AQ34DjMvIIlOTH6wi8e20FMCaIs8tupc0l4ZaRbj br9vtkN+SxWY2tzyO69gsNY0zUxAd0dVzUkj2R8CjUfImna8ZOq159JEkWwlRtcExz/7 TQlVqG2FpK0EQ3szzJ8tamKvOM3vPDT6arqF6mUQBH+hRlCGzE9A02N+wIWaMZBU/bgj avjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RhBcsZyr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c1-20020ac87dc1000000b002f3c679eefcsi7304985qte.257.2022.05.09.09.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 09:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RhBcsZyr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1D5F229206; Mon, 9 May 2022 09:47:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239358AbiEIQvL (ORCPT + 99 others); Mon, 9 May 2022 12:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239323AbiEIQvE (ORCPT ); Mon, 9 May 2022 12:51:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC156205442 for ; Mon, 9 May 2022 09:47:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B076612F5 for ; Mon, 9 May 2022 16:47:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D373FC385B1; Mon, 9 May 2022 16:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652114828; bh=BdChrK3ppYQZEGDKoOx4mUw4ng4JEF0GRnsXWCcaH9U=; h=Date:From:To:Subject:References:In-Reply-To:From; b=RhBcsZyrUo69ayeHbh6UUpIzZK0SRM2Pa/o0ikv/Mu6t0RJAHCZkiLzmTFu8WFyth +3qq5Itee+OyEPuUElKF022bYmlS5honPCsHzCf8zPoXLjKeHFWhS0pXh9qTh8/WZP MnwMIk9moCkUXKd+bL3AhsushNB15LS1jTWNtPqBpMAQUjIsXI+EEHEMutQyorGTsD taondY4o0zJqwjnNGoMsdD8SK5dUr/NcI5rV6gdpcFAQYx0krjX5V9XMhn7+up16iJ v5Ik9+FPF6EmvhiYA/hP1rcAwsTsf7NQCuWLs4uHepLIBEBqudRrJE+mQuHL8j1PaY C5ihNIiRXFwxg== Date: Mon, 9 May 2022 09:47:07 -0700 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH 2/5 v2] f2fs: introduce f2fs_gc_control to consolidate f2fs_gc parameters Message-ID: References: <20220506232032.1264078-1-jaegeuk@kernel.org> <20220506232032.1264078-2-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220506232032.1264078-2-jaegeuk@kernel.org> X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org This was used in Android for a long time. Let's upstream it. Signed-off-by: Jaegeuk Kim --- Change log from v1: - fix tracepoint for the "don't care" entry fs/f2fs/file.c | 58 ++++++++++++++++++++--- include/trace/events/f2fs.h | 94 +++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 68ddf4c7ca64..51df34f95984 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4329,17 +4329,39 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct inode *inode = file_inode(iocb->ki_filp); + const loff_t pos = iocb->ki_pos; ssize_t ret; if (!f2fs_is_compress_backend_ready(inode)) return -EOPNOTSUPP; - if (f2fs_should_use_dio(inode, iocb, to)) - return f2fs_dio_read_iter(iocb, to); + if (trace_f2fs_dataread_start_enabled()) { + char *p = f2fs_kmalloc(F2FS_I_SB(inode), PATH_MAX, GFP_KERNEL); + char *path; + + if (!p) + goto skip_read_trace; + + path = dentry_path_raw(file_dentry(iocb->ki_filp), p, PATH_MAX); + if (IS_ERR(path)) { + kfree(p); + goto skip_read_trace; + } - ret = filemap_read(iocb, to, 0); - if (ret > 0) - f2fs_update_iostat(F2FS_I_SB(inode), APP_BUFFERED_READ_IO, ret); + trace_f2fs_dataread_start(inode, pos, iov_iter_count(to), + current->pid, path, current->comm); + kfree(p); + } +skip_read_trace: + if (f2fs_should_use_dio(inode, iocb, to)) { + ret = f2fs_dio_read_iter(iocb, to); + } else { + ret = filemap_read(iocb, to, 0); + if (ret > 0) + f2fs_update_iostat(F2FS_I_SB(inode), APP_BUFFERED_READ_IO, ret); + } + if (trace_f2fs_dataread_end_enabled()) + trace_f2fs_dataread_end(inode, pos, ret); return ret; } @@ -4637,14 +4659,36 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) /* Possibly preallocate the blocks for the write. */ target_size = iocb->ki_pos + iov_iter_count(from); preallocated = f2fs_preallocate_blocks(iocb, from, dio); - if (preallocated < 0) + if (preallocated < 0) { ret = preallocated; - else + } else { + if (trace_f2fs_datawrite_start_enabled()) { + char *p = f2fs_kmalloc(F2FS_I_SB(inode), + PATH_MAX, GFP_KERNEL); + char *path; + + if (!p) + goto skip_write_trace; + path = dentry_path_raw(file_dentry(iocb->ki_filp), + p, PATH_MAX); + if (IS_ERR(path)) { + kfree(p); + goto skip_write_trace; + } + trace_f2fs_datawrite_start(inode, orig_pos, orig_count, + current->pid, path, current->comm); + kfree(p); + } +skip_write_trace: /* Do the actual write. */ ret = dio ? f2fs_dio_write_iter(iocb, from, &may_need_sync): f2fs_buffered_write_iter(iocb, from); + if (trace_f2fs_datawrite_end_enabled()) + trace_f2fs_datawrite_end(inode, orig_pos, ret); + } + /* Don't leave any preallocated blocks around past i_size. */ if (preallocated && i_size_read(inode) < target_size) { f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index f701bb23f83c..11f6b7147be2 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -2068,6 +2068,100 @@ TRACE_EVENT(f2fs_fiemap, __entry->ret) ); +DECLARE_EVENT_CLASS(f2fs__rw_start, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes, + pid_t pid, char *pathname, char *command), + + TP_ARGS(inode, offset, bytes, pid, pathname, command), + + TP_STRUCT__entry( + __string(pathbuf, pathname) + __field(loff_t, offset) + __field(int, bytes) + __field(loff_t, i_size) + __string(cmdline, command) + __field(pid_t, pid) + __field(ino_t, ino) + ), + + TP_fast_assign( + /* + * Replace the spaces in filenames and cmdlines + * because this screws up the tooling that parses + * the traces. + */ + __assign_str(pathbuf, pathname); + (void)strreplace(__get_str(pathbuf), ' ', '_'); + __entry->offset = offset; + __entry->bytes = bytes; + __entry->i_size = i_size_read(inode); + __assign_str(cmdline, command); + (void)strreplace(__get_str(cmdline), ' ', '_'); + __entry->pid = pid; + __entry->ino = inode->i_ino; + ), + + TP_printk("entry_name %s, offset %llu, bytes %d, cmdline %s," + " pid %d, i_size %llu, ino %lu", + __get_str(pathbuf), __entry->offset, __entry->bytes, + __get_str(cmdline), __entry->pid, __entry->i_size, + (unsigned long) __entry->ino) +); + +DECLARE_EVENT_CLASS(f2fs__rw_end, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes), + + TP_ARGS(inode, offset, bytes), + + TP_STRUCT__entry( + __field(ino_t, ino) + __field(loff_t, offset) + __field(int, bytes) + ), + + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->bytes = bytes; + ), + + TP_printk("ino %lu, offset %llu, bytes %d", + (unsigned long) __entry->ino, + __entry->offset, __entry->bytes) +); + +DEFINE_EVENT(f2fs__rw_start, f2fs_dataread_start, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes, + pid_t pid, char *pathname, char *command), + + TP_ARGS(inode, offset, bytes, pid, pathname, command) +); + +DEFINE_EVENT(f2fs__rw_end, f2fs_dataread_end, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes), + + TP_ARGS(inode, offset, bytes) +); + +DEFINE_EVENT(f2fs__rw_start, f2fs_datawrite_start, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes, + pid_t pid, char *pathname, char *command), + + TP_ARGS(inode, offset, bytes, pid, pathname, command) +); + +DEFINE_EVENT(f2fs__rw_end, f2fs_datawrite_end, + + TP_PROTO(struct inode *inode, loff_t offset, int bytes), + + TP_ARGS(inode, offset, bytes) +); + #endif /* _TRACE_F2FS_H */ /* This part must be outside protection */ -- 2.35.1.1021.g381101b075-goog