Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp128736iob; Tue, 17 May 2022 21:11:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkOm6+atjQ/ekRZfDzxTfog2ehLPXZY2X1saE95sL92h3jePRBDCU52CxaqjNaGp/vXz6w X-Received: by 2002:a17:902:a9c6:b0:15e:fe5d:cf67 with SMTP id b6-20020a170902a9c600b0015efe5dcf67mr25363332plr.74.1652847089825; Tue, 17 May 2022 21:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652847089; cv=none; d=google.com; s=arc-20160816; b=Wl6QPwMQnRWTupPv0Hy7/wb10tkunDSk7BD0ztYBWdjEWdYxrBfFeyFIF9Ct79RP0o Go/DxURvK6mol2MSKKf2qehQ4dTdIgc6lzHEX2tMrN/vAQW4fgborYv9NFf7q3/IGzyc hz6ShV3yVNWAgMf+iRk6nmI13eVQjB80M5QHixYUrJh5O5kyNhEE8tY+WH88eNlOuXOy sFn3OxH4ewjwnGuOfG3i8+bnKvYU0joK5wO9P3yXZyNlF6b5KmGYsAhGKpd8H6V4ju2e U1eb/7092xQqxuiTpwMWDcB/YhNORvf1cunPmVddGCOqVhbu/DpcKojTzLNeJIHbW3to p6VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:reply-to :content-language:cc:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature; bh=4Y7GTp06m87sjrCjAMpmQ5sQb3h3R2MyluXYoWhziFQ=; b=MUPrLNx+pKKyPyFRuXQrB95xyMcbw+8GtSf5/giZAkhrG6MeiQ8+tA7mkC51ETW6/U f60YrjH7fQ54UKJAiL0k3am40L2xMl7/bBmiTYvLHejUNPO4CKTodRh9gnQAFHn4rOel QxAfXryxYdO7rLYy9k2FyhSBdpjjqeFjFobYAJHu6pLDEPHJFtxBEbCOP3r+9Ude/Lxo l/+Gwi8bWLyfLOzewfR/v1TxLfjb8S42ElTbGaHnU6eOjdYyOTXV96+b0+ZbUw3+XrqU cjwcqIc+Ca48x+O8puMTYM1T1bOqveuSw9Rcc1yofvxiHgupT/+75zC5NXOcgF+UWxSY Mdrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=MghXAnMT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x17-20020a631711000000b003f24d6ac522si1259697pgl.8.2022.05.17.21.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:11:29 -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=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=MghXAnMT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12DC819FB7; Tue, 17 May 2022 20:42:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245446AbiEQJp1 (ORCPT + 99 others); Tue, 17 May 2022 05:45:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245391AbiEQJoh (ORCPT ); Tue, 17 May 2022 05:44:37 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ED0447AF5 for ; Tue, 17 May 2022 02:44:17 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id j4so30297083lfh.8 for ; Tue, 17 May 2022 02:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :content-language:reply-to:content-transfer-encoding; bh=4Y7GTp06m87sjrCjAMpmQ5sQb3h3R2MyluXYoWhziFQ=; b=MghXAnMT6KgtejKHKI+m5S8SyqmUYagS+dMS6d3Siyt9TDQsrCRUjWc6Af1jh3cJbV Tqh+DfBGiOkHXNOEJMxbR7HlMjwq+wlzQD8Tnm6peub57oQqy3FrQM0iz2qatq17+g+G vW64ljpV+gwxahaKaIZQlLdLl1wvofEtn20vw4bQDgnqbyetV3Ry6IsomfwJmeSIscUg pV2pqY0Nzgs/8/xNTdyZtztvcr7anhSOTIrBB8HqZu/AZrudcrUXsNhCaJ8sgvtLRDrc zJYjHz/fXOkFcwwbWB5v3Q5F8Pc88geDcDWRqusZeZ38rnDv5PD+1L+sa1IPyotMGU8n tusA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:content-language:reply-to:content-transfer-encoding; bh=4Y7GTp06m87sjrCjAMpmQ5sQb3h3R2MyluXYoWhziFQ=; b=5grYqm3fIJu7cvRA/swqlKc8Zh/4gpEgzYd6D+YjjBOqno85dPdhhLtTcyGdQOia+5 wAMkzz8WMaa1n8opw7g0WHkCeCJDGdb4M4Jo+mirczlN3tVuN+dKbBWYN72ZMO1H/Xnj XzD76jbBPcDh5lsh/nDzwJ/PXEvxDRnHb0rtF3FwK1n/E6ac/OkXzJXwqJkcjO9wBYdw A417RSiOnNmXB7Pf5JkPi9g8K+N1njKS0tzzmaiR4KIX1KLGXONi/TKSiuFm+KmoImHo 8FZSJ+pwLzq0+tCoY1FCnZGP5QGqvm5L8YDJh18JlZgUQl/V/Sli9mKyft3LCWh3wLKF AFsA== X-Gm-Message-State: AOAM530fBz/bOtI0UEeVAhdNlCmCazOuv7U9okLWVhS5RgIXoHWt5Piv WIoZINuWyVrxo6a+QmX3yZZYgQ== X-Received: by 2002:a05:6512:2350:b0:472:6182:955c with SMTP id p16-20020a056512235000b004726182955cmr16059189lfu.214.1652780656167; Tue, 17 May 2022 02:44:16 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id y16-20020ac24e70000000b0047255d211aasm1536573lfs.217.2022.05.17.02.44.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 May 2022 02:44:15 -0700 (PDT) Message-ID: <8ef9de6a-7497-07f7-852c-befcc3843771@openvz.org> Date: Tue, 17 May 2022 12:44:14 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 From: Vasily Averin Subject: [PATCH v2] tracing: add ACCOUNT flag for allocations from marked slab caches To: Steven Rostedt , Shakeel Butt , Roman Gushchin , Vlastimil Babka , Matthew Wilcox Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, Ingo Molnar , Andrew Morton , linux-mm@kvack.org, Joonsoo Kim , David Rientjes , Pekka Enberg , Christoph Lameter , Michal Hocko Content-Language: en-US Reply-To: YoMccU66auLAPEHa@casper.infradead.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 dSlab caches marked with SLAB_ACCOUNT force accounting for every allocation from this cache even if __GFP_ACCOUNT flag is not passed. Unfortunately, at the moment this flag is not visible in ftrace output, and this makes it difficult to analyze the accounted allocations. This patch adds the __GFP_ACCOUNT flag for allocations from slab caches marked with SLAB_ACCOUNT to the ftrace output --- v2: 1) handle kmem_cache_alloc_node() too, thanks to Shakeel 2) rework kmem_cache_alloc* tracepoints to use cachep instead of current cachep->*size parameters. Now kmalloc[_node] and kmem_cache_alloc[_node] tracepoints do not use common template NB: kmem_cache_alloc_node tracepoint in SLOB cannot be switched to cachep, therefore it was replaced by kmalloc_node tracepoint. --- VvS: is this acceptable? Maybe I should split this patch? Signed-off-by: Vasily Averin --- include/trace/events/kmem.h | 82 +++++++++++++++++++++++++++---------- mm/slab.c | 7 +--- mm/slab_common.c | 7 ++-- mm/slob.c | 10 ++--- mm/slub.c | 6 +-- 5 files changed, 71 insertions(+), 41 deletions(-) diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h index 71c141804222..3b4f96e4a607 100644 --- a/include/trace/events/kmem.h +++ b/include/trace/events/kmem.h @@ -9,7 +9,7 @@ #include #include -DECLARE_EVENT_CLASS(kmem_alloc, +TRACE_EVENT(kmalloc, TP_PROTO(unsigned long call_site, const void *ptr, @@ -43,23 +43,41 @@ DECLARE_EVENT_CLASS(kmem_alloc, show_gfp_flags(__entry->gfp_flags)) ); -DEFINE_EVENT(kmem_alloc, kmalloc, +TRACE_EVENT(kmem_cache_alloc, - TP_PROTO(unsigned long call_site, const void *ptr, - size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags), + TP_PROTO(unsigned long call_site, + const void *ptr, + struct kmem_cache *s, + gfp_t gfp_flags), - TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags) -); + TP_ARGS(call_site, ptr, s, gfp_flags), -DEFINE_EVENT(kmem_alloc, kmem_cache_alloc, + TP_STRUCT__entry( + __field( unsigned long, call_site ) + __field( const void *, ptr ) + __field( size_t, bytes_req ) + __field( size_t, bytes_alloc ) + __field( unsigned long, gfp_flags ) + ), - TP_PROTO(unsigned long call_site, const void *ptr, - size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags), + TP_fast_assign( + __entry->call_site = call_site; + __entry->ptr = ptr; + __entry->bytes_req = s->object_size; + __entry->bytes_alloc = s->size; + __entry->gfp_flags = (__force unsigned long)gfp_flags | + (s->flags & SLAB_ACCOUNT ? __GFP_ACCOUNT : 0); + ), - TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags) + TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s", + (void *)__entry->call_site, + __entry->ptr, + __entry->bytes_req, + __entry->bytes_alloc, + show_gfp_flags(__entry->gfp_flags)) ); -DECLARE_EVENT_CLASS(kmem_alloc_node, +TRACE_EVENT(kmalloc_node, TP_PROTO(unsigned long call_site, const void *ptr, @@ -97,22 +115,42 @@ DECLARE_EVENT_CLASS(kmem_alloc_node, __entry->node) ); -DEFINE_EVENT(kmem_alloc_node, kmalloc_node, +TRACE_EVENT(kmem_cache_alloc_node, - TP_PROTO(unsigned long call_site, const void *ptr, - size_t bytes_req, size_t bytes_alloc, - gfp_t gfp_flags, int node), + TP_PROTO(unsigned long call_site, + const void *ptr, + struct kmem_cache *s, + gfp_t gfp_flags, + int node), - TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node) -); + TP_ARGS(call_site, ptr, s, gfp_flags, node), -DEFINE_EVENT(kmem_alloc_node, kmem_cache_alloc_node, + TP_STRUCT__entry( + __field( unsigned long, call_site ) + __field( const void *, ptr ) + __field( size_t, bytes_req ) + __field( size_t, bytes_alloc ) + __field( unsigned long, gfp_flags ) + __field( int, node ) + ), - TP_PROTO(unsigned long call_site, const void *ptr, - size_t bytes_req, size_t bytes_alloc, - gfp_t gfp_flags, int node), + TP_fast_assign( + __entry->call_site = call_site; + __entry->ptr = ptr; + __entry->bytes_req = s->object_size; + __entry->bytes_alloc = s->size; + __entry->gfp_flags = (__force unsigned long)gfp_flags | + (s->flags & SLAB_ACCOUNT ? __GFP_ACCOUNT : 0); + __entry->node = node; + ), - TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node) + TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d", + (void *)__entry->call_site, + __entry->ptr, + __entry->bytes_req, + __entry->bytes_alloc, + show_gfp_flags(__entry->gfp_flags), + __entry->node) ); TRACE_EVENT(kfree, diff --git a/mm/slab.c b/mm/slab.c index 0edb474edef1..935b1c90d7f0 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3492,8 +3492,7 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru, { void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_); - trace_kmem_cache_alloc(_RET_IP_, ret, - cachep->object_size, cachep->size, flags); + trace_kmem_cache_alloc(_RET_IP_, ret, cachep, flags); return ret; } @@ -3606,9 +3605,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) { void *ret = slab_alloc_node(cachep, flags, nodeid, cachep->object_size, _RET_IP_); - trace_kmem_cache_alloc_node(_RET_IP_, ret, - cachep->object_size, cachep->size, - flags, nodeid); + trace_kmem_cache_alloc_node(_RET_IP_, ret, cachep, flags, nodeid); return ret; } diff --git a/mm/slab_common.c b/mm/slab_common.c index 2b3206a2c3b5..12299cf450fe 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -25,13 +25,12 @@ #include #include -#define CREATE_TRACE_POINTS -#include - #include "internal.h" - #include "slab.h" +#define CREATE_TRACE_POINTS +#include + enum slab_state slab_state; LIST_HEAD(slab_caches); DEFINE_MUTEX(slab_mutex); diff --git a/mm/slob.c b/mm/slob.c index 40ea6e2d4ccd..69875419769c 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -610,14 +610,12 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node) if (c->size < PAGE_SIZE) { b = slob_alloc(c->size, flags, c->align, node, 0); - trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size, - SLOB_UNITS(c->size) * SLOB_UNIT, - flags, node); + trace_kmalloc_node(_RET_IP_, b, c->object_size, + SLOB_UNITS(c->size) * SLOB_UNIT, flags, node); } else { b = slob_new_pages(flags, get_order(c->size), node); - trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size, - PAGE_SIZE << get_order(c->size), - flags, node); + trace_kmalloc_node(_RET_IP_, b, c->object_size, + PAGE_SIZE << get_order(c->size), flags, node); } if (b && c->ctor) { diff --git a/mm/slub.c b/mm/slub.c index ed5c2c03a47a..fc6678269db0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3231,8 +3231,7 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru, { void *ret = slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size); - trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size, - s->size, gfpflags); + trace_kmem_cache_alloc(_RET_IP_, ret, s, gfpflags); return ret; } @@ -3266,8 +3265,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node) { void *ret = slab_alloc_node(s, NULL, gfpflags, node, _RET_IP_, s->object_size); - trace_kmem_cache_alloc_node(_RET_IP_, ret, - s->object_size, s->size, gfpflags, node); + trace_kmem_cache_alloc_node(_RET_IP_, ret, s, gfpflags, node); return ret; } -- 2.31.1