From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7396C27C4F for ; Wed, 26 Jun 2024 12:32:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43A886B0088; Wed, 26 Jun 2024 08:32:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E9AF6B0093; Wed, 26 Jun 2024 08:32:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B1496B0095; Wed, 26 Jun 2024 08:32:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 101BA6B0088 for ; Wed, 26 Jun 2024 08:32:07 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B213A120CC2 for ; Wed, 26 Jun 2024 12:32:06 +0000 (UTC) X-FDA: 82272977052.27.2F915D2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 00D7412000F for ; Wed, 26 Jun 2024 12:32:03 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PpD6ZpKM; spf=pass (imf29.hostedemail.com: domain of mhiramat@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719405108; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KGj9WwILAZxKElON1eT8SBIMBUWPhdFrAzouuEUIUiQ=; b=piPOy+bzTRt8mfzGx3/rOP+PXZsSMkqpAAN+INFbQgO3289rXginUFmN85vidBpEGGmej2 Xym5TgmeuBkR2TUstEb9dirItfqxToleuPzm77b2bl6Rfo4G2hXX9+ALv/EGE1B1OeJcrh lfnYVje2YnaBDcGugrOpo0LNXXm1ePE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719405108; a=rsa-sha256; cv=none; b=MY5IJTRlprfG/NOFgJKQUAru863Lbmpy2cn0nO0a4zeY1HqV5KPkmxPCevwRyQ3Bt3VdMh DU+FRYDapRvdy8uFXI2Xu3XaxXezjTko/3BCmmGCy3oosIdeEW+keEquuAXuYHSa8n+DSC ioYvwGlZSbY/lbVfJYvajSLpQe9bjRg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PpD6ZpKM; spf=pass (imf29.hostedemail.com: domain of mhiramat@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EF620619E5; Wed, 26 Jun 2024 12:32:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1C21C2BD10; Wed, 26 Jun 2024 12:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719405122; bh=mc/ZYbx1LwXPN/DM65SBf0NUloG3DhGylqQgVaBcn9g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PpD6ZpKMa22oJXnc5CzpHrMIdkiw7/YZz1clqYsll/D6PeVQU3wuvM38FF9MxpJ/E PGtfU7hGckDZxUSsxPakXzyhUdY3+U7vCMl6JUroMbpkZ+0Sk9BvPBKzXH28yXtdva wCcVFDD0JFOrjflRvW6XyODgg0Dl+rHC1z7ROKEPYe3nQAJft3lUoUBmrL9Bndska8 FQ1897/y+TWw0308uQVzjiM6xIqGvL0dyDJAyOEpFbqPsBHTgutljd5GakEH/ZK1Uq CMjKA27CKH4LRXjHcTcfBIKrgXvhC+9F6OHUb+zgcf5aHeZEx28wVfmXLJ8OOl4V2p fFpd4rsrceshw== Date: Wed, 26 Jun 2024 21:31:57 +0900 From: Masami Hiramatsu (Google) To: Takaya Saeki Cc: Matthew Wilcox , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Junichi Uekawa , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] filemap: add trace events for get_pages, map_pages, and fault Message-Id: <20240626213157.e2d1b916bcb28d97620043d1@kernel.org> In-Reply-To: <20240620161903.3176859-1-takayas@chromium.org> References: <20240620161903.3176859-1-takayas@chromium.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 00D7412000F X-Stat-Signature: whhcrttf4w45dzn3kxr3yr6xfaa6ka5q X-HE-Tag: 1719405123-509779 X-HE-Meta: U2FsdGVkX1/EcMUOex5oEIG+XhSHv7IALYXOs9I2zyff4MdlnP8qVfZ0oFRsfsUHw9xaicA0Jxrx1Joh0GR353k1Ue/m4CN/lPNpVs8gmLJ7ldCnZpD+uZ9HErwK9OfO0A7fwLV7Yurp8Cxq5+juTisHVOuZwmmKEuoIuwcyFw9vLkJvqz66rr9TdEVPO5fiy0nckOaTVKm1/QS4EH3KuiaO2+VG7ODkRYRQROzR+5bw0pwXPgoZSG6N6V7AgqvqnAmJeo6pcb4l1BY/3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NlZkxpDc5r3QI X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, 20 Jun 2024 16:19:03 +0000 Takaya Saeki wrote: > To allow precise tracking of page caches accessed, add new tracepoints > that trigger when a process actually accesses them. > > The ureadahead program used by ChromeOS traces the disk access of > programs as they start up at boot up. It uses mincore(2) or the > 'mm_filemap_add_to_page_cache' trace event to accomplish this. It stores > this information in a "pack" file and on subsequent boots, it will read > the pack file and call readahead(2) on the information so that disk > storage can be loaded into RAM before the applications actually need it. > > A problem we see is that due to the kernel's readahead algorithm that > can aggressively pull in more data than needed (to try and accomplish > the same goal) and this data is also recorded. The end result is that > the pack file contains a lot of pages on disk that are never actually > used. Calling readahead(2) on these unused pages can slow down the > system boot up times. > > To solve this, add 3 new trace events, get_pages, map_pages, and fault. > These will be used to trace the pages are not only pulled in from disk, > but are actually used by the application. Only those pages will be > stored in the pack file, and this helps out the performance of boot up. > > With the combination of these 3 new trace events and > mm_filemap_add_to_page_cache, we observed a reduction in the pack file > by 7.3% - 20% on ChromeOS varying by device. > This looks good to me from the trace-event point of view. Reviewed-by: Masami Hiramatsu (Google) Thanks! > Signed-off-by: Takaya Saeki > --- > Changelog between v2 and v1 > - Fix a file offset type usage by casting pgoff_t to loff_t > - Fixed format string of dev and inode > > include/trace/events/filemap.h | 84 ++++++++++++++++++++++++++++++++++ > mm/filemap.c | 4 ++ > 2 files changed, 88 insertions(+) > > V1:https://lore.kernel.org/all/20240618093656.1944210-1-takayas@chromium.org/ > > diff --git a/include/trace/events/filemap.h b/include/trace/events/filemap.h > index 46c89c1e460c..3a94bd633bf0 100644 > --- a/include/trace/events/filemap.h > +++ b/include/trace/events/filemap.h > @@ -56,6 +56,90 @@ DEFINE_EVENT(mm_filemap_op_page_cache, mm_filemap_add_to_page_cache, > TP_ARGS(folio) > ); > > +DECLARE_EVENT_CLASS(mm_filemap_op_page_cache_range, > + > + TP_PROTO( > + struct address_space *mapping, > + pgoff_t index, > + pgoff_t last_index > + ), > + > + TP_ARGS(mapping, index, last_index), > + > + TP_STRUCT__entry( > + __field(unsigned long, i_ino) > + __field(dev_t, s_dev) > + __field(unsigned long, index) > + __field(unsigned long, last_index) > + ), > + > + TP_fast_assign( > + __entry->i_ino = mapping->host->i_ino; > + if (mapping->host->i_sb) > + __entry->s_dev = > + mapping->host->i_sb->s_dev; > + else > + __entry->s_dev = mapping->host->i_rdev; > + __entry->index = index; > + __entry->last_index = last_index; > + ), > + > + TP_printk( > + "dev=%d:%d ino=%lx ofs=%lld max_ofs=%lld", > + MAJOR(__entry->s_dev), > + MINOR(__entry->s_dev), __entry->i_ino, > + ((loff_t)__entry->index) << PAGE_SHIFT, > + ((loff_t)__entry->last_index) << PAGE_SHIFT > + ) > +); > + > +DEFINE_EVENT(mm_filemap_op_page_cache_range, mm_filemap_get_pages, > + TP_PROTO( > + struct address_space *mapping, > + pgoff_t index, > + pgoff_t last_index > + ), > + TP_ARGS(mapping, index, last_index) > +); > + > +DEFINE_EVENT(mm_filemap_op_page_cache_range, mm_filemap_map_pages, > + TP_PROTO( > + struct address_space *mapping, > + pgoff_t index, > + pgoff_t last_index > + ), > + TP_ARGS(mapping, index, last_index) > +); > + > +TRACE_EVENT(mm_filemap_fault, > + TP_PROTO(struct address_space *mapping, pgoff_t index), > + > + TP_ARGS(mapping, index), > + > + TP_STRUCT__entry( > + __field(unsigned long, i_ino) > + __field(dev_t, s_dev) > + __field(unsigned long, index) > + ), > + > + TP_fast_assign( > + __entry->i_ino = mapping->host->i_ino; > + if (mapping->host->i_sb) > + __entry->s_dev = > + mapping->host->i_sb->s_dev; > + else > + __entry->s_dev = mapping->host->i_rdev; > + __entry->index = index; > + ), > + > + TP_printk( > + "dev=%d:%d ino=%lx ofs=%lld", > + MAJOR(__entry->s_dev), > + MINOR(__entry->s_dev), __entry->i_ino, > + ((loff_t)__entry->index) << PAGE_SHIFT > + ) > +); > + > TRACE_EVENT(filemap_set_wb_err, > TP_PROTO(struct address_space *mapping, errseq_t eseq), > > diff --git a/mm/filemap.c b/mm/filemap.c > index 876cc64aadd7..39f9d7fb3d2c 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2556,6 +2556,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, > goto err; > } > > + trace_mm_filemap_get_pages(mapping, index, last_index); > return 0; > err: > if (err < 0) > @@ -3286,6 +3287,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > if (unlikely(index >= max_idx)) > return VM_FAULT_SIGBUS; > > + trace_mm_filemap_fault(mapping, index); > + > /* > * Do we have something in the page cache already? > */ > @@ -3652,6 +3655,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, > } while ((folio = next_uptodate_folio(&xas, mapping, end_pgoff)) != NULL); > add_mm_counter(vma->vm_mm, folio_type, rss); > pte_unmap_unlock(vmf->pte, vmf->ptl); > + trace_mm_filemap_map_pages(mapping, start_pgoff, end_pgoff); > out: > rcu_read_unlock(); > > -- > 2.45.2.627.g7a2c4fd464-goog > -- Masami Hiramatsu (Google)