Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4694578iob; Sun, 8 May 2022 22:16:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQvcv5FmgJOKIfY3SecRYyCA31u41IqN2ubZsYh9h5k0ugUqLlmPrdkWDLC/lZo2YiXA4K X-Received: by 2002:a17:902:d487:b0:15e:a0a4:69e3 with SMTP id c7-20020a170902d48700b0015ea0a469e3mr14938624plg.155.1652073415260; Sun, 08 May 2022 22:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652073415; cv=none; d=google.com; s=arc-20160816; b=YoW51wmf1oSQ3I8ZkRHTR2Yg4V8nh5+fhApqWGpcpzm7khX3Z+TMIRO0U38uHWO3gB N9pD5aU/toNP0t7DKBWbR2FuODgJGtqJJBZAbr9lLnSri5FhBhX+/H08sKSK/FDmhm13 vqZyDAFZH9oU1eiEJt46+C4l6o5I/LB+nSFh+mtXjiELiqMGDqG8+k6qwkFXmrKVSq9T uVpBwsA554sQiKLhqAi4982Lqivgf2pCzd0EMFhz5cmN4HlzMi0Diep9CAOwRCgzv+I4 UZoc4Co/Bbfb5DBZmsWoF8qwNb7cTC/+DeoyQdhB1HpeEqqFCpn+8+jX3aWhWaIaToyw Vqng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=KWAb658hWnEyrNgr/yyrfE4nucb98F+3qRmQt1CMXNA=; b=guFOknmp8n7WON689ySjJPVl9GM7/ldQp0ArezmABjoB9mckFDhVSXaj7XkgG0UuJy bs9avmMh+p1a6Wz1WALsblRw8gbMHoBhz8/NFRFOntTnPu4j5F9cvMaKc0/88ziUAz+j TLkvg1wyxS6Xs6bxhKJpFeP9M9/narVK8/9eq2ElQu25IRfcQnMaHMHTaw4dyFOtlsou 1oePbVsVk1cP8FqTIIKj3WjAm7qEfiEVqcMvRFjBn3sOK/bktVu3O8qCH30aewZALerl QjiiqS1r1WjhwMubXFb9L6Cdhjf+7mO9/uk4tGPhnI40pPAXwKiT25KAHTnywiNKbt9b s8Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="G/TjzTQM"; 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 d123-20020a623681000000b004fa3e2a9b13si12447280pfa.378.2022.05.08.22.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:16: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=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="G/TjzTQM"; 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 45A8AFE211; Sun, 8 May 2022 22:12:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390781AbiEFTdP (ORCPT + 99 others); Fri, 6 May 2022 15:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236285AbiEFTdN (ORCPT ); Fri, 6 May 2022 15:33:13 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF57F6D868 for ; Fri, 6 May 2022 12:29:28 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id m23so10387642ljb.8 for ; Fri, 06 May 2022 12:29:28 -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 :references:content-language:in-reply-to:content-transfer-encoding; bh=KWAb658hWnEyrNgr/yyrfE4nucb98F+3qRmQt1CMXNA=; b=G/TjzTQMF1GsQTZOCwfujliBF5HfJ5GxX8JkT7vDeyvg5KUQUOMV7XEtC6MmaPQGPx vhCqL1NN0ajISS2f5/HLS0G4JOZ6J0ehLRpNWgpeo3/byghb7omWCXJKirrgPdRi4h+G elmvcOwiVB0KrZMyC6FV+JiyRVKQY667j3Vl70wZnt6RZJwD7IIHdFX0mrzOo/FuDgz5 /ViZkoq02gVCwy3ERveiYb6XZe0GEe1DdKy2aiPGKGAUo38kAuG+rBL50vxkpDyaMyos G9bVpgU0U8+7maS6R2RLUVPa1mK/ghZnh2yhqf+bP6IvFBrl9Ll2C1tJYNMQDzvMvr82 tMrg== 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:references:content-language:in-reply-to :content-transfer-encoding; bh=KWAb658hWnEyrNgr/yyrfE4nucb98F+3qRmQt1CMXNA=; b=NTTsTdmSl79WcN5XkXDeAvl+mz+ckwPQxzp7m66+zenaiDYUkRCCfRf29cJ2tsAece yWKErHvKmIWY1tSGgzNgJc41uisYEMUcpS6/tloI33sqfwod4k+VG90wGMJ/QcWdsXcg 6DfjQkwRUgyef5h/+eaCXf3/bNke/s9xafmuOMr7jA03HiervOkFF6RL173knwAE+6PV bMvE4HFPetPpWMztFZN65pouVKDfWzZ2VPwXgrqFnnlEBgxc4pAL8EKNXhXVDEmsXoJk 41EdNVKEQQS1UDrH0X9hAVU0o2ACqZVZcpqCQa0mF4n7VLNow6pQrPoNDlyoVPS/wplI FTXw== X-Gm-Message-State: AOAM533p3X3rnZTOpgduw6qjj43W6699wNGSzikLA8YTwNDcGTNfprnJ rAS7BFbUuqbTL3ANINrDPEAH4PFf+JUBc8Dz X-Received: by 2002:a2e:a794:0:b0:250:5de1:1ec5 with SMTP id c20-20020a2ea794000000b002505de11ec5mr2859520ljf.270.1651865367120; Fri, 06 May 2022 12:29:27 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id u24-20020a196a18000000b0047255d21180sm791507lfu.175.2022.05.06.12.29.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 May 2022 12:29:26 -0700 (PDT) Message-ID: Date: Fri, 6 May 2022 22:29:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 From: Vasily Averin Subject: [PATCH v2] percpu: improve percpu_alloc_percpu event trace To: Shakeel Butt , Steven Rostedt , Ingo Molnar Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, Roman Gushchin , Vlastimil Babka , Michal Hocko , cgroups@vger.kernel.org, Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , linux-mm@kvack.org References: <2b388d09-940e-990f-1f8a-2fdaa9210fa0@openvz.org> Content-Language: en-US In-Reply-To: <2b388d09-940e-990f-1f8a-2fdaa9210fa0@openvz.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 Added call_site, bytes_alloc and gfp_flags fields to the output of the percpu_alloc_percpu ftrace event: mkdir-4393 [001] 169.334788: percpu_alloc_percpu: call_site=mem_cgroup_css_alloc+0xa6 reserved=0 is_atomic=0 size=2408 align=8 base_addr=0xffffc7117fc00000 off=402176 ptr=0x3dc867a62300 bytes_alloc=14448 gfp_flags=GFP_KERNEL_ACCOUNT This is required to track memcg-accounted percpu allocations. Signed-off-by: Vasily Averin --- v2: added call_site, improved patch description --- include/trace/events/percpu.h | 23 +++++++++++++++++------ mm/percpu-internal.h | 8 ++++---- mm/percpu.c | 5 +++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/include/trace/events/percpu.h b/include/trace/events/percpu.h index df112a64f6c9..e989cefc0def 100644 --- a/include/trace/events/percpu.h +++ b/include/trace/events/percpu.h @@ -6,15 +6,20 @@ #define _TRACE_PERCPU_H #include +#include TRACE_EVENT(percpu_alloc_percpu, - TP_PROTO(bool reserved, bool is_atomic, size_t size, - size_t align, void *base_addr, int off, void __percpu *ptr), + TP_PROTO(unsigned long call_site, + bool reserved, bool is_atomic, size_t size, + size_t align, void *base_addr, int off, + void __percpu *ptr, size_t bytes_alloc, gfp_t gfp_flags), - TP_ARGS(reserved, is_atomic, size, align, base_addr, off, ptr), + TP_ARGS(call_site, reserved, is_atomic, size, align, base_addr, off, + ptr, bytes_alloc, gfp_flags), TP_STRUCT__entry( + __field( unsigned long, call_site ) __field( bool, reserved ) __field( bool, is_atomic ) __field( size_t, size ) @@ -22,9 +27,11 @@ TRACE_EVENT(percpu_alloc_percpu, __field( void *, base_addr ) __field( int, off ) __field( void __percpu *, ptr ) + __field( size_t, bytes_alloc ) + __field( gfp_t, gfp_flags ) ), - TP_fast_assign( + __entry->call_site = call_site; __entry->reserved = reserved; __entry->is_atomic = is_atomic; __entry->size = size; @@ -32,12 +39,16 @@ TRACE_EVENT(percpu_alloc_percpu, __entry->base_addr = base_addr; __entry->off = off; __entry->ptr = ptr; + __entry->bytes_alloc = bytes_alloc; + __entry->gfp_flags = gfp_flags; ), - TP_printk("reserved=%d is_atomic=%d size=%zu align=%zu base_addr=%p off=%d ptr=%p", + TP_printk("call_site=%pS reserved=%d is_atomic=%d size=%zu align=%zu base_addr=%p off=%d ptr=%p bytes_alloc=%zu gfp_flags=%s", + (void *)__entry->call_site, __entry->reserved, __entry->is_atomic, __entry->size, __entry->align, - __entry->base_addr, __entry->off, __entry->ptr) + __entry->base_addr, __entry->off, __entry->ptr, + __entry->bytes_alloc, show_gfp_flags(__entry->gfp_flags)) ); TRACE_EVENT(percpu_free_percpu, diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index 411d1593ef23..70b1ea23f4d2 100644 --- a/mm/percpu-internal.h +++ b/mm/percpu-internal.h @@ -113,7 +113,6 @@ static inline int pcpu_chunk_map_bits(struct pcpu_chunk *chunk) return pcpu_nr_pages_to_map_bits(chunk->nr_pages); } -#ifdef CONFIG_MEMCG_KMEM /** * pcpu_obj_full_size - helper to calculate size of each accounted object * @size: size of area to allocate in bytes @@ -123,13 +122,14 @@ static inline int pcpu_chunk_map_bits(struct pcpu_chunk *chunk) */ static inline size_t pcpu_obj_full_size(size_t size) { - size_t extra_size; + size_t extra_size = 0; - extra_size = size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *); +#ifdef CONFIG_MEMCG_KMEM + extra_size += size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *); +#endif return size * num_possible_cpus() + extra_size; } -#endif /* CONFIG_MEMCG_KMEM */ #ifdef CONFIG_PERCPU_STATS diff --git a/mm/percpu.c b/mm/percpu.c index ea28db283044..3633eeefaa0d 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1884,8 +1884,9 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, ptr = __addr_to_pcpu_ptr(chunk->base_addr + off); kmemleak_alloc_percpu(ptr, size, gfp); - trace_percpu_alloc_percpu(reserved, is_atomic, size, align, - chunk->base_addr, off, ptr); + trace_percpu_alloc_percpu(_RET_IP_, reserved, is_atomic, size, align, + chunk->base_addr, off, ptr, + pcpu_obj_full_size(size), gfp); pcpu_memcg_post_alloc_hook(objcg, chunk, off, size); -- 2.31.1