From patchwork Fri Aug 16 21:10:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takaya Saeki X-Patchwork-Id: 13766813 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 94506C3DA4A for ; Fri, 16 Aug 2024 21:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06AB38D00B3; Fri, 16 Aug 2024 17:10:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F36CC8D00A2; Fri, 16 Aug 2024 17:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7A98D00B3; Fri, 16 Aug 2024 17:10:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C054B8D00A2 for ; Fri, 16 Aug 2024 17:10:41 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 65860140343 for ; Fri, 16 Aug 2024 21:10:41 +0000 (UTC) X-FDA: 82459352682.28.7577C6D Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf08.hostedemail.com (Postfix) with ESMTP id 233EA160030 for ; Fri, 16 Aug 2024 21:10:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="cnQyv3u/"; spf=pass (imf08.hostedemail.com: domain of takayas@chromium.org designates 209.85.215.169 as permitted sender) smtp.mailfrom=takayas@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723842564; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=mIVamb0t+ukSevWtGDhnJxmQQeMGvGtS5gLAZtBpwhQ=; b=rjrvyhyiLrouBHubg2egzfcUWFb0KDNYVbiPv0tDpnFf/JXs11AxaaQTkMO8xzh3dUo7dP E12HTvHrCgJhkiaP9BkQ7xsFlpLC+uWltEr0n+TqbogrjMrrJf+qeqL9qst7UX+6yuLoTP oKnN3KMbDo5wRV7EEHhplZeIEH6pvkA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723842564; a=rsa-sha256; cv=none; b=vN/3MYF78gTCcIXT9ncih7UaeYcb0H4nQxWL4ALr0lbnjs6Eyg7FryI2Mm8CU94WXR7Z7A /a6GisbqEiBjnGvvybRltmNzYoOF7vlscPJ17kFr2b2NncDKSE1u7yhCkU8YYUOZHTU3mt qcB0zGLX51yWrGy5BUWYCS1Kw1wZvuk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="cnQyv3u/"; spf=pass (imf08.hostedemail.com: domain of takayas@chromium.org designates 209.85.215.169 as permitted sender) smtp.mailfrom=takayas@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7b0c9bbddb4so1647866a12.3 for ; Fri, 16 Aug 2024 14:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1723842638; x=1724447438; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mIVamb0t+ukSevWtGDhnJxmQQeMGvGtS5gLAZtBpwhQ=; b=cnQyv3u/+M4+rgBHvmaelr1lefbAqOEQTVAoxB+ftAWhxOWP15lj9vbb2yBlE5BTlW DbkLSaHdhyx2iL8VbimBbMGWZbhBZuO+6I7oYkh+x0NckWaIsccTe0GDC+1lqSQYUxd9 Dmu6x5kdZy44fXeCTPIwje0Sk4BnIz7F2O0tc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723842638; x=1724447438; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mIVamb0t+ukSevWtGDhnJxmQQeMGvGtS5gLAZtBpwhQ=; b=m4wKWqJHnSl1NP2nZtxpMcBkmUfoyeybi6CfT/5fcVfzC144OJQDwlfHE1pjMtavbC 85/RCON4shqb2gIUsl1fugaux8AACQX1ZfiYOGptCeTDglIKHPPE5JWymg9aDmu+HFsg ufq49X42V/8PPopiPhjCoByNcV0HrlFucuYrLE2sKnYnTZlVrUu21J4hesnNgoMinUQn ecTf6Y0PZihCAk+kTViak6Z2gfPRQNB/2cAQPrextx6hpczvaViP4+Ue629tbwYC64nM 38tOn0HhZgjAevHy85ey10xTtk8J/uKnXqV5Xl3L8S3wTXXj2/An6+hsZN4ZxZV0+GHX /yHQ== X-Forwarded-Encrypted: i=1; AJvYcCXHmry2kNmyfuxDFAWIXfK7QwKqJLY7LX4bA7UWEH/dCZs9dsm1H3bQTUBnGIWRfJzzI/sAoMNtqQ58R7P14+5xbME= X-Gm-Message-State: AOJu0Yyuu8LCu7iwEGrr/E7UbYpf4p08EV+yclypmDUjzrsIqt2AZI1p fWZsiDWzZxwmlbQJPJ2eRURTnojAa/2Y8Jr7CP+aCEluRQIavmpUf0xL8c3t X-Google-Smtp-Source: AGHT+IEM/jRWr5rAkRLa/IpFUV9K3uejMQWznzf/9GJt778E8nRMTEi2Y3OtuwWQtPn8GLL5M3N1uw== X-Received: by 2002:a17:90a:67c6:b0:2c9:5ecd:e3c5 with SMTP id 98e67ed59e1d1-2d4063e7697mr766956a91.33.1723842637621; Fri, 16 Aug 2024 14:10:37 -0700 (PDT) Received: from localhost (0.223.81.34.bc.googleusercontent.com. [34.81.223.0]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d3f0f1f51bsm1867399a91.32.2024.08.16.14.10.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Aug 2024 14:10:37 -0700 (PDT) From: Takaya Saeki To: Andrew Morton , Matthew Wilcox Cc: 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, Takaya Saeki Subject: [PATCH v4] filemap: add trace events for get_pages, map_pages, and fault Date: Fri, 16 Aug 2024 21:10:29 +0000 Message-ID: <20240816211029.903842-1-takayas@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog MIME-Version: 1.0 X-Stat-Signature: ojz4m7annrq97p8w7no5nimbqgiyh6hx X-Rspamd-Queue-Id: 233EA160030 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723842638-82670 X-HE-Meta: U2FsdGVkX18uFQsrhrcs55RGSbNiZhGOZYFcxzPH5V2gUcEiXaKBJAES8loR8y/Y8UK1S01xlwz1mnNUzMaXD6CdBuiSIMDOYD6sjeW6UaDhnUcGIe5RzL5ZqZhDA7jsx/ClN6A8Zz8b7UvA3tB3Bk/hH4oil+PqkqEAiabXubP6snrER7MPYDICVoINchd1vQTW3iYKC5VwGe3XpkpVXxsNejc5MijDim18nKB78yV3do6Huj/k3Q0ALi1PCPGbkvg22j+IchxFZjQJVqJD8eoPSxpRoupkZlaoqSEIazACFOf77vGooq1bn7Oq5ZFsbPm5wpp19axXiMsfk/qRb4F9BzLoH8iL2/jEdkJvi1qwVcpHmMuGaaR94APmrce5e7wz/EsiqgVQX4EjLfI7wjuCmeTzqGp33sbPq6ekxXZXtOBqcg0/4VAv6cf00dubW4Zt2lh3h+6g4IwW8z+2xvHByuLt3wRgvMDsiSZ1C3GJZKEqbeLRj1vxcMnAN+YtPDt0BRC7zEjUYHrA4mRK5VImYTuh7MMkr+IKYRQ+x+RXcG+eXdeuF7v7h4SLd+hShSym4zNzNHKxqHmV1Yj/j65x4/1yDwIqYbI5tYz3RYNaz9lqbDgHrb5JLyEwbEfLdB1U8MVuw2yFgR0qrRvOhmceZwP2jo9/JzIn/yybrXTWGSJ/sBWPbgdELKUsCmpieBpne3bwMJJ8yRP+lxhLkaiJuMOrxnOsHSeEVUoVkUoANbGAUaGr2hQ49KqoKWZTGmczjwPOl/09cpOIARegEuBNQOXGeBDsyz7QGDiN0GBlcvJGiOCJ708C8e4eTxHBymav3Lx5FbTklWT2NqjJNfUNDG2bgOvqPja9dTS69PjN5GgYAR+1Uq9bcxn8B957tFxqwAJh+LriK6Vh9XFeY+g0aCQwKcx0PQMPsObD4U+iD4Dq2XsbelL//wCJbPl2S4H2gBuL+oEieTSy+1R 6rE156Sg HzPGDx6Se74mXHazm5xn5sx6LqqAmGIJQrDvtpVqoS2kOt6uoHYzE8N6BW4YNRECBxUVCruCLl/PTil1/fcXRrhjldGdTHLQbeBWDBYBZ/yMmSJHMdzGOAfvfBesdjhqDD89bbFQrnoahfQKFrOTFKp3r7q7Ucknxu+1ttCjKVXkz+bTYfTopV0aOONZ+TeGpHcC0vuPs8AbfpGv6vXoPXiSvmck57760Hv3ETKO6ck7vZe1ZIwSQGmmZ6wJuh5HfyASqESE3uByHSSDUBpmdYl0ymfkUJ2gwZ5kQPejj14wL5opSUYNojT6/QuCPtsaa/RCEWdezk7gCwodi6UP7p5NuiOgMKEbrfIP16MzPI7Xk9rxVHPPC31+z1E0zPM1WU2f1X3G9iMlkP+iPXAKSylqUsTuN7KBM1/2HaQQ643LQ0sZPMl1TeYiKug== 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: 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. Signed-off-by: Takaya Saeki Reviewed-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- Changelog between v4 and v3 - fix mm_filemap_get_pages by replacing last_index with last_index-1. it is an open interval while mm_filemap_map_pages's one is inclusive. Changelog between v3 and v2 - Use a range notation in the printf format Changelog between v2 and v1 - Fix a file offset type usage by casting pgoff_t to loff_t - Fix format string of dev and inode include/trace/events/filemap.h | 84 ++++++++++++++++++++++++++++++++++ mm/filemap.c | 4 ++ 2 files changed, 88 insertions(+) diff --git a/include/trace/events/filemap.h b/include/trace/events/filemap.h index 46c89c1e460c..f48fe637bfd2 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-%lld", + MAJOR(__entry->s_dev), + MINOR(__entry->s_dev), __entry->i_ino, + ((loff_t)__entry->index) << PAGE_SHIFT, + ((((loff_t)__entry->last_index + 1) << PAGE_SHIFT) - 1) + ) +); + +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 d62150418b91..e6b20cda9912 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 - 1); return 0; err: if (err < 0) @@ -3287,6 +3288,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? */ @@ -3653,6 +3656,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();