From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05113C3F2C6 for ; Wed, 4 Mar 2020 00:43:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 99C3F206D5 for ; Wed, 4 Mar 2020 00:43:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="L24u5zqD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99C3F206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 174E46B0003; Tue, 3 Mar 2020 19:43:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 126846B0005; Tue, 3 Mar 2020 19:43:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 061D16B0006; Tue, 3 Mar 2020 19:43:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id E20E06B0003 for ; Tue, 3 Mar 2020 19:43:05 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A9E70180AD802 for ; Wed, 4 Mar 2020 00:43:05 +0000 (UTC) X-FDA: 76555830330.27.girls58_551e77392e53a X-HE-Tag: girls58_551e77392e53a X-Filterd-Recvd-Size: 4920 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Mar 2020 00:43:04 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id f198so5385704qke.11 for ; Tue, 03 Mar 2020 16:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wOjgETEggr7acXmXSIGKLYA84kpLrcA+aOyLjNXDSaw=; b=L24u5zqDkHCBPaOj1oSrn6IQPgzZGnryJZeVmIyRZITl1GRSlm2vWmgiDWPb6UlNCa hZZmmHLySwl37+ZRqpogB1VkAKXaTlIi7WqTlPaVS+b7YIhQa0b/wqwTo5IeAFn1Jtgl uCi+r0RahZAfqaPh+2nq/7T0OIQhkrwiCM+yTj3N8PxqLD6gz4GOCkDRl6++fYML/rQv jhm5o1hID6OaRxNCKMgayYNz62i7oEE7rc3Ms3nriNevMaotorpYTSYkKGBherhb5R9i nUVUhJccEJGYcjKXw/h5IZ5qOGnqlkEfdx8atzZtYl0pR/uAZs/zqfk6GYx4PFlrf2Jk A6AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wOjgETEggr7acXmXSIGKLYA84kpLrcA+aOyLjNXDSaw=; b=dsnrc3+bbEdB8KVx9sOcFGFMJZJWi5fZ4PfYh95NcsniRTNK3GmIMbh5ErnhkjNWFt sJXK1T56Ixhyg93EZ/MF07C9BUogV9CK9td/A5KKgR1oFamw8Wg707RE5v8t2ljyRQNq k5PQlJV7uL3JsaOU44XPbAimvR7H+z6/cO2k/woC+seadc3GfSGk/BCDJjLH5uAaG1qe hVA+BVMXfZRLk30x2G4I3DEUuyqbomuy+r+UczmHJftAQXZrcpoTEYyqGUNbDgc3dar5 thVIS1FhAVSpbQUlFv6XZz5zZuchw8PG/1tIyrupCPXV9RbZ5cI3flJl9ktUmayJnXP1 iElw== X-Gm-Message-State: ANhLgQ2SELTEH0OzVER8Fx4+VcbKqRurDJOcCPAtWfWnddN5DUhPNcAv 7p6SfkDrLmySlWn8ZaA8RLr7Tg== X-Google-Smtp-Source: ADFU+vtT815ZqojFX5Xd5JyTcZYq1D4yYzc3QBiv54PBkSjODKMU8WjxMws4JqGmk+Jx1vFpgBEn7g== X-Received: by 2002:a37:7746:: with SMTP id s67mr634304qkc.127.1583282583953; Tue, 03 Mar 2020 16:43:03 -0800 (PST) Received: from localhost (pool-96-232-200-60.nycmny.fios.verizon.net. [96.232.200.60]) by smtp.gmail.com with ESMTPSA id 8sm44239qke.80.2020.03.03.16.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 16:43:03 -0800 (PST) Date: Tue, 3 Mar 2020 19:43:02 -0500 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Michal Hocko , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org, Bharata B Rao , stable@vger.kernel.org Subject: Re: [PATCH] mm: fork: fix kernel_stack memcg stats for various stack implementations Message-ID: <20200304004302.GB76149@cmpxchg.org> References: <20200303233550.251375-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200303233550.251375-1-guro@fb.com> 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: On Tue, Mar 03, 2020 at 03:35:50PM -0800, Roman Gushchin wrote: > Depending on CONFIG_VMAP_STACK and the THREAD_SIZE / PAGE_SIZE ratio > the space for task stacks can be allocated using __vmalloc_node_range(), > alloc_pages_node() and kmem_cache_alloc_node(). In the first and the > second cases page->mem_cgroup pointer is set, but in the third it's > not: memcg membership of a slab page should be determined using the > memcg_from_slab_page() function, which looks at > page->slab_cache->memcg_params.memcg . In this case, using > mod_memcg_page_state() (as in account_kernel_stack()) is incorrect: > page->mem_cgroup pointer is NULL even for pages charged to a non-root > memory cgroup. > > It can lead to kernel_stack per-memcg counters permanently showing 0 > on some architectures (depending on the configuration). > > In order to fix it, let's introduce a mod_memcg_obj_state() helper, > which takes a pointer to a kernel object as a first argument, uses > mem_cgroup_from_obj() to get a RCU-protected memcg pointer and > calls mod_memcg_state(). It allows to handle all possible > configurations (CONFIG_VMAP_STACK and various THREAD_SIZE/PAGE_SIZE > values) without spilling any memcg/kmem specifics into fork.c . > > Note: this patch has been first posted as a part of the new slab > controller patchset. This is a slightly updated version: the fixes > tag has been added and the commit log was extended by the advice > of Johannes Weiner. Because it's a fix that makes sense by itself, > I'm re-posting it as a standalone patch. > > Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages") > Signed-off-by: Roman Gushchin > Cc: stable@vger.kernel.org Acked-by: Johannes Weiner Thanks for pointing out the user impact.