Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3292462lfo; Mon, 23 May 2022 00:53:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWa6K/ogom9P5YZ7miQ/H6inVRMdvFlSA1ymA5dfextwMGPLQPGYtxfIuMVVXE4++eo+QX X-Received: by 2002:a05:6a00:23cc:b0:518:9e6c:f8dd with SMTP id g12-20020a056a0023cc00b005189e6cf8ddmr4254150pfc.43.1653292414000; Mon, 23 May 2022 00:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292413; cv=none; d=google.com; s=arc-20160816; b=zls3v4k0t80WSAyu2I2GgGEX4QIbgVuETODtQPAzbLD4dMJdYtF8Z0GdpKmv2LLd6Q Au0nNveCRiODB4sl4lzyVfdn5s/Y816IMD7LBA+2FgEAwa5uCTyjL4em4JsH3FYEjW5f vnwSsCZ8vFZQkSgJJRuIKSfg7lPrbmKPc15Irxm2ZrdeJsIX9zwLEeGUW1p07jlDJvn6 lpK20q8CnLkgDbQfCS9j+GoUAbJcX3OV1hwxtFR8IVtBhmbUzMETsVDssBZpKjEUuy3N KljHqpk92+UfxAqf2+f1B5f7RvinX6uhbwSB4RjH9cuHPXu63BWTdwT7lib07gAzmIhL 2DzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cowFMMuGvgfdaWA366Gk5O1CrrDkR8s9xOd2QVYAJJE=; b=BwiqrwK11iE+SD1R9mgh0fMM61RtahidAhRTvbbtjKKBkYohuN/EhdGOaM2rPLQUuv 0t2bBp/Gb0QxjpooP9Ect38bQU2zYVOjEpdj4SpD2r/wMwoGfbRdx/e6DY/EndqrQaYa +y4gEW0oxF7QSddpbrJp4KIbYWyVKM0oeo8dysB89RWnAZCDQl7v8zT5SF7Jb93euNJV Rsga28HQqgZJmg2OcmRdDKPHrB21JsrHeTlqft+S2OQcr7NLwMfHKcjf984xR7kcF6AM w3sPFHsH9bE4GcYOwOyaml7EG1fX1HErx8VHR/vs4SrvjT9pBxnUX2TDlqRpAJ6RW4mk p81g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j3FpKS+P; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f16-20020aa79690000000b0050d469d0d0esi4176822pfk.204.2022.05.23.00.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:53:33 -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=@gmail.com header.s=20210112 header.b=j3FpKS+P; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C99EE61293; Mon, 23 May 2022 00:00:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237206AbiEVFT3 (ORCPT + 99 others); Sun, 22 May 2022 01:19:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236370AbiEVFTZ (ORCPT ); Sun, 22 May 2022 01:19:25 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F21BE403E1 for ; Sat, 21 May 2022 22:19:23 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id i74so5715694ioa.4 for ; Sat, 21 May 2022 22:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cowFMMuGvgfdaWA366Gk5O1CrrDkR8s9xOd2QVYAJJE=; b=j3FpKS+P0dtEu0+F/fZcVSLU/pzvFjnBBo1ZeVL1E/2ca+bv6K87o1DuFCfqBkbqp1 PVvZnqp4kA2o6CyuX7SA6ug3tdl8wNSeRN7wxVpBUuGBk6YBzQ5K/3hPlubsQIxXylNe cNqxt9aHdWcVulro/uqFDHeAUYXA1gVUipVpaVrf9bMyTfb2byYRQ+fyZXouKnkvC/5P 6x2Ctu6bJn+sS/ow/sZq5Jbjz19aj0/96K/XtzWO1WyTIFAlTkkeIJmqAP9T7h9sH5I/ OiD/UvGbwprOWw0oAuatjiMYUv124rpHiYcSbfcHLSix3xeykMDiehxP0Hc3iyNmQVCZ k/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cowFMMuGvgfdaWA366Gk5O1CrrDkR8s9xOd2QVYAJJE=; b=hBbu7iSdf8QQkNrpN+6jXHcpa8AJJBu24bsguLznwLQe8/lvl7g0/NGyczo9Bs/Smv bJlUqW5HGKpTrSedBXktIaq49+Uqo0GdzJ+e0ZZLlgBuoMWVupipn2NNTR6e9m+RkXWJ OK/8BOh9VB4ELmfsXCoZut5pqDm+231+izJzt1Ob9D/J0DZgNxUYW9iAfRR/q5wZPxPt 4AlNNLCd/eJA92kGjvM1Hn+7ClzVar4o9k+VSp1fYxyYxpYnElYWSJnu8BdMQsalp8xv d5ivHlZJ8AyKF78/QxG4S6qdAg8NHmsNhUdNI7RTrbvrlPZ0nzZNMC2uVZ5+zte9D6Ul xnOA== X-Gm-Message-State: AOAM531LPw12TbGvdKnjeljlHtibJAZ0rGGaBT17LmdAcItSo2Q8kO5w yl/skj9+VYr6I+wHIalNJ8k= X-Received: by 2002:a05:6638:370b:b0:32e:a6ce:edcf with SMTP id k11-20020a056638370b00b0032ea6ceedcfmr4242646jav.267.1653196763270; Sat, 21 May 2022 22:19:23 -0700 (PDT) Received: from n2.us-central1-a.c.spheric-algebra-350919.internal (151.16.70.34.bc.googleusercontent.com. [34.70.16.151]) by smtp.gmail.com with ESMTPSA id q2-20020a056638040200b0032b5316724dsm1889353jap.22.2022.05.21.22.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 May 2022 22:19:22 -0700 (PDT) Date: Sun, 22 May 2022 05:19:20 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vasily Averin Cc: Andrew Morton , kernel@openvz.org, linux-kernel@vger.kernel.org, Steven Rostedt , Ingo Molnar , linux-mm@kvack.org, Shakeel Butt , Roman Gushchin , Vlastimil Babka , Matthew Wilcox , Joonsoo Kim , David Rientjes , Pekka Enberg , Christoph Lameter , Michal Hocko , Muchun Song Subject: Re: [PATCH v4] tracing: add 'accounted' entry into output of allocation tracepoints Message-ID: References: <0c73ce5c-3625-6187-820e-1277e168b3bc@openvz.org> <1621d82a-439d-0657-2b7e-5e90c42c2087@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1621d82a-439d-0657-2b7e-5e90c42c2087@openvz.org> X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,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 On Sun, May 22, 2022 at 07:33:08AM +0300, Vasily Averin wrote: > On 5/22/22 06:51, Hyeonggon Yoo wrote: > > On Sat, May 21, 2022 at 09:36:54PM +0300, Vasily Averin wrote: > >> Slab 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 boolean "accounted" entry into trace output, > >> and set it to 'true' for calls used __GFP_ACCOUNT flag and > >> for allocations from caches marked with SLAB_ACCOUNT. > >> > >> Signed-off-by: Vasily Averin > >> Acked-by: Shakeel Butt > > > > May I ask what information do you want to collect > > using this patch? > > I analyze ftrace output to understand which allocations are accounted. > When some userspace operation consume memory, it's important to account > most part of memory (>2/3 of all) to avoid misuse inside memcg-limited > contianers. Otherwise memcg-limited container can consume significant > portion of host memory, trigger global OOM, wake up OOM-killer and kill > random processes on host. > If memory consumers are accounted, it leads to memcg-OOM only. > > Now kmem tracing output looks like this: > > kmem_cache_alloc: (getname_flags.part.0+0x2c) call_site=getname_flags.part.0+0x2c ptr=0xffff8fff022e9000 bytes_req=4096 bytes_alloc=4096 gfp_flags=GFP_KERNEL accounted=false > kmalloc: (alloc_bprm+0x32) call_site=alloc_bprm+0x32 ptr=0xffff8fff2b408a00 bytes_req=416 bytes_alloc=512 gfp_flags=GFP_KERNEL|__GFP_ZERO accounted=false > kmem_cache_alloc: (mm_alloc+0x16) call_site=mm_alloc+0x16 ptr=0xffff8fff0894d500 bytes_req=1048 bytes_alloc=1088 gfp_flags=GFP_KERNEL accounted=true > mm_page_alloc: page=0xffffffffa4ab8d42 pfn=0x12ad72 order=1 migratetype=0 gfp_flags=GFP_USER|__GFP_ZERO|__GFP_ACCOUNT > kmem_cache_alloc: (vm_area_alloc+0x1a) call_site=vm_area_alloc+0x1a ptr=0xffff8fff2af27000 bytes_req=200 bytes_alloc=200 gfp_flags=GFP_KERNEL accounted=true > > As you can see, without new field it is quite hard to understand, > is last allocation accounted. > > This analyze helps me to identify most important allocations for given scenario > and enable accounting for selected allocations. > > An example of this analyze you can found here: > https://lore.kernel.org/all/d28233ee-bccb-7bc3-c2ec-461fd7f95e6a@openvz.org/ > Thank you for detailed explanation. Makes sense to me. > > If we decide to do that, it would be better to print > > something like: > > slab_flags=SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT|SLAB_STORE_USER > > instead of just printing 'accounted=true/false'. This patch is too > > specific to SLAB_ACCOUNT. > > Any extra output degrades performance. No strong opinion but just a concern that maybe later someone want add something similar like 'reclaimable=true/false', 'dma=true/false', ... and I would prefer more general solution. (especially if we'll not change tracepoints after release because of backward compatibility) > For my task it's not important to know SLAB flags, I just need to understand, > is current allocation accounted or not. SLAB_ACCOUNT, SLAB_RECLAIM_ACCOUNT, SLAB_DMA, ... etc are SLAB flags. 'if current allocation is accounted or not' depends on SLAB_ACCOUNT flag is set or not. Thanks, Hyeonggon > > And if what you want to know is just total slab memory that is accounted, > > what about adding something like SlabAccounted in /proc/meminfo? > > It is not enough for me. I need to have per-process allocation information. > > Thank you, > Vasily Averin