From patchwork Tue Jun 18 09:36:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takaya Saeki X-Patchwork-Id: 13702012 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 E9686C2BA15 for ; Tue, 18 Jun 2024 09:37:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 790BD6B0337; Tue, 18 Jun 2024 05:37:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 770886B0338; Tue, 18 Jun 2024 05:37:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62F406B0339; Tue, 18 Jun 2024 05:37: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 446226B0337 for ; Tue, 18 Jun 2024 05:37:07 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E60481C1306 for ; Tue, 18 Jun 2024 09:37:06 +0000 (UTC) X-FDA: 82243505652.27.23DE850 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) by imf14.hostedemail.com (Postfix) with ESMTP id 2846D100008 for ; Tue, 18 Jun 2024 09:37:03 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iS0n4HlS; spf=pass (imf14.hostedemail.com: domain of takayas@chromium.org designates 209.85.160.42 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=1718703418; 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=yO5Ag6TkgQi37C9WOmZH4DbdT66+5TaN0dgl3GOdIjM=; b=QlFpksi8CvA2GT6St4rPJkgjDIbXzCUP5wNUuVRkTG7ih0D4W2HUFBd0f/UBAXvO0sTiF7 F/FVfUMu50qOFQ57B3kh/RDpb6qQOvfJYvqHee5nA+JLRvj8kDkk96Rd7G7/qKECgXmhho 6K9tioRw4afT0SQ8Hg5fYZrp59c8Dtg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718703418; a=rsa-sha256; cv=none; b=SYJcwRB15IlYvHELsR/DTsciF0XON2M77aw5JpHejjU7yzQcLki98uvT6hrhSyFUxDnukG c0MzKPZUT9ZEDIX82KKI+ypn+tx6thQlCfT2aLHX+duY9fA8WmGpjMx2qeY8G/GdjzTEmY oJ6FsXWRm34nIEguee1FR3FI04ygH2w= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iS0n4HlS; spf=pass (imf14.hostedemail.com: domain of takayas@chromium.org designates 209.85.160.42 as permitted sender) smtp.mailfrom=takayas@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-24c0dbd2866so2732768fac.0 for ; Tue, 18 Jun 2024 02:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718703423; x=1719308223; 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=yO5Ag6TkgQi37C9WOmZH4DbdT66+5TaN0dgl3GOdIjM=; b=iS0n4HlSq7qOh8OoZGdanDnZp3tRedbYX+MI5BD6MscZci+NVBFAc1L2aj4IKAE7lP AJ3uqf2xJSbztASf8Q5kvxIimIOovu3k/ztppPunghbbg1ZafXV0h+FwlDaWciOAnYSg nKmU5vUmDZLFECffYGtKryrVr+cVWJ0qDMKzQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718703423; x=1719308223; 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=yO5Ag6TkgQi37C9WOmZH4DbdT66+5TaN0dgl3GOdIjM=; b=HwMikvHX3CfZX9HvP7WtL4Z6o0gzcrzF79Iv6cm3b4cqT980uGbClBcTPA6K/8rNUP NfBG1ztZvOhz/WST/+k1SdnfcaD/Tk9ZaPLNT7g2D9779eCY4/z8Hshj1k/pJRI6ggBL tNNvdG+tmZsdPhhxYbQkYcTnDffnumVrzAQR43m1yZKtYz1Y/fHArAjj654nNa4WwjA1 +Liby+KGVb3zNu2QGNQJQBLtIYHiT0zz3AcktMD5gzw+dVuhYxp/Y3gHVcGVwZyIA5fd J2qFlyx+/dhaQWn2beGya2QTrcyASRBHsMpm1E0rOQBT9DCzFYyXupEPzZXjnc5RlcMO QGdA== X-Forwarded-Encrypted: i=1; AJvYcCX8Rl/iMPVEYCoVk8tllITnKXGYqlzvIz3BHY8lSj584eGes/zHj2LSnUUMnUqR6NYvbO9tRaPl2IqM1DXuHlar/gY= X-Gm-Message-State: AOJu0YzMPJmo/2ac4DoTerb6PvdoW+lvESzRLLzLqNJLhGzoVGPE2abU TYveVe8mKOb/OjmNO6iIpL+vZlsvO5d9lM3PGoL4QjyE4DEyESS4U/IzeSAZ X-Google-Smtp-Source: AGHT+IFjGk/o+lwl7K/bIc/tHdxoPP+pTmgqlmCZ6lEWgXKCgTfp4wm0qZkGTYoC1vTxxK5H8+Ha1w== X-Received: by 2002:a05:6870:c1d4:b0:24f:dd11:4486 with SMTP id 586e51a60fabf-25842ba209bmr14156507fac.36.1718703423087; Tue, 18 Jun 2024 02:37:03 -0700 (PDT) Received: from localhost (148.175.199.104.bc.googleusercontent.com. [104.199.175.148]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-705d8fc3dbdsm6995546b3a.1.2024.06.18.02.36.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jun 2024 02:37:02 -0700 (PDT) From: Takaya Saeki To: Matthew Wilcox , Andrew Morton 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] filemap: add trace events for get_pages, map_pages, and fault Date: Tue, 18 Jun 2024 09:36:56 +0000 Message-ID: <20240618093656.1944210-1-takayas@chromium.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog MIME-Version: 1.0 X-Rspamd-Queue-Id: 2846D100008 X-Stat-Signature: aqtuyiau4ixkb6rz78k574mehene38hr X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718703423-169794 X-HE-Meta: U2FsdGVkX1+f5W9UpQ2d1OldpMkJkCAf9Rjsv7M0bfs8beGzg8TqVXFM6/MDMOxuGMDsYyxMl0XR9rYYwVBLLt4uh8WXvVLRqdnFGEbCIU2ZDyi6iqeGo8EGLkWCCVL0C6Y5pMAL33A3byfKJdCJ0zUsVrUTFn2Xkf4ZGsyEWlKOGHgZyuy2IpxQXVPK85xf90Opllw9g6Ycns28Pwk3DXJNNK8ID1DyAmREOsFRJIn3EDStj+EpMW8ptDF9VS7OAVMOur8MRy8VnIL1S7gmUApfyRuENocUr2KqgiJPHwsLTW5PLoLEoE9xQle4c5abmM5buve5K5C3e4kDKaW9gXhj4OTMg3vurK8E4Qs54uzOkHEwKPE8S74VHug4DNFv6IQRootEBU5LqWRXpst48bNSDedsbNYDuWzGKjZEsVWGtOge/K00BmKj6+VXyxhkCHvwjFlSjgEZn0fc0YOan0URFWspVoWjoYIW3gXeBQhvrE0ymrKdtfgEJhL1JWx6SLlb0lsuRwYBCIAMH0l6EV8jjsB+vSLBCpPYF2CMfVNv5XZeUqx7CZj4kgLNlsiS1yR6BGu8FZtZHvIjSpw9knHX8noThEqnLef3er3j2eu9CAu6WOs3oZMezIInX19/re0jeWDId1rNhyHI3xKF/fUmB2MMsBKmENK3ZW17XG5X5L6GvM6qfDKsswNL5cT6V64zHtodmiM4cC+gqcRO/O5lAnLbCHw5dp9RGiYLRtYG5Jb0dGYEPODU6L5zb1NsKSVxxaLgA7uTv2wpYPsXypkm5vp61Gi4N01oj8ONylxLTnxJkZYsF/8zElqZs2H5MKtfNHy2jaAPZcEs3jI4ifM45l9WHVT+gRGdHZ6ao695hNxL4ia7Kx7/94LkemnMy1XrhyMFwcktyEllBnANElFv15jLm5SkydWHNnH8Da92VoQmP7nO/LG48TePVa8ZtaHAO/nK6srjasCG49A vM/hoZYu AzWpLc+UP79apaJ3zDe6yFxmnwIYIAHICV/UzMKXjoIwaZb0xmGKTBhEVUQrEObYAvZOlfBVv5FnzrXCLcbzkUUYaDoNm2o7WEvRz84KnheoyEEcXhnppCFzJfjzA4aaoN+tE2YbneixfCIS2O9R4xhPoYlNdpLzIP4WAt+FxGNRIpuAlRtO1BaqD4uvTHOtS1NS+rH4nZGMIMx6cMxD73broPlzx8VGEBeMPHswhQPgVXaJTvwIkPPvqn3GeAbdPAKs2v/x75y+T7eX6ldGNTBzi05W36tt7kee1uetYOw24LijZ2YxssOoINicq+RC7arB1 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: Steven Rostedt (Google) --- 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..68c705572c4f 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=%lu max_ofs=%lu", + MAJOR(__entry->s_dev), + MINOR(__entry->s_dev), __entry->i_ino, + __entry->index << PAGE_SHIFT, + __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=%lu", + MAJOR(__entry->s_dev), + MINOR(__entry->s_dev), __entry->i_ino, + __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();