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=-11.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 C54E0C3F2C6 for ; Tue, 3 Mar 2020 23:54:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A10B20866 for ; Tue, 3 Mar 2020 23:54:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BuPLToiB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A10B20866 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3209C6B0070; Tue, 3 Mar 2020 18:54:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D16E6B0071; Tue, 3 Mar 2020 18:54:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C0DD6B0072; Tue, 3 Mar 2020 18:54:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 016B26B0070 for ; Tue, 3 Mar 2020 18:54:36 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9D93BB287 for ; Tue, 3 Mar 2020 23:54:36 +0000 (UTC) X-FDA: 76555708152.03.house45_626e671a1c71c X-HE-Tag: house45_626e671a1c71c X-Filterd-Recvd-Size: 4559 Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Mar 2020 23:54:36 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id q65so243298oif.4 for ; Tue, 03 Mar 2020 15:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=U/AZ7U0KHmcr9QXvwZlQmeLdBD0j8SEt/BJmgUku3Ig=; b=BuPLToiByk/bx7Wu2BMsoB3elyNG+L/DRg5LKFbkWa6X6b0EwIvfkdejfsQ5zJmGk7 aI0NT/6ojh5joNirrWv/cYnjAZKUHbUxjodu3BQBfXaOlnxsaDgcZmgz33RuCyOl41N6 ApY08xTTc5Pp82cNM848Bd1K7V/F2GoBZFsDbxeHv5jv2aKG5bxfNwFCTKn+zdj/baC1 lEQ6mtT1ul2femrlG0iGDgfCwSQAkTMRDzBCTCEE5dAOJtPCPZYvK8pQ/mu7/OhBNNsz aIcphStoDNK76S5JPz/wdMl7GkLFrbrruHkrHPsu1/oT8QYdMs4VimVxtYIn5KsKOclI 2Gaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=U/AZ7U0KHmcr9QXvwZlQmeLdBD0j8SEt/BJmgUku3Ig=; b=Ura/SfNyL3HdLgI8brp8Ua8G8UAZc2qgP+O0ofP1mX1JcYvHmEBHaMdVSdL8wumb/I BDh+LsyPHZDUpoOXbnDqy1NsQOjKWGfeWm6a6uEkAoydj/gJeLqYT+pIri2rV+mDkPFs /UKNYgz7GePAGpiN/6YsPHWms8dXwZWGFF2/ejqNsHaFaJ3vdYAtEiU440GpStRa+KKP ypv/he2KCIwYFpAy7p6UvEftiSREZBH0TVpvrQ4v+sEI1V2msbok+gYt0N1JHy8y1+m0 NvtgTMPYqutzy3fEHncDSTWgmtK780PsQHnLzBWIvn58cN1cxhI7kbsY9tfKMG9DKBfM Wnuw== X-Gm-Message-State: ANhLgQ2zSNt8MKLbCZR2eHfSxNN2Wnt7pJVJQX0TcCjshdVRaSw2AnBO lnLItbdOSACkwa0ZJqLaUGAorMlb/CE6m46ZbkWA7lSqEoU= X-Google-Smtp-Source: ADFU+vvMae7IcKXiyLTUwR+cYqi/whefWdi0hnRgoORjgCw4UX0cLXu/XpZOSZnamdQslkSPH1Io7MPYVuJLg92ghas= X-Received: by 2002:aca:3bc6:: with SMTP id i189mr6540oia.142.1583279675263; Tue, 03 Mar 2020 15:54:35 -0800 (PST) MIME-Version: 1.0 References: <20200303233550.251375-1-guro@fb.com> In-Reply-To: <20200303233550.251375-1-guro@fb.com> From: Shakeel Butt Date: Tue, 3 Mar 2020 15:54:24 -0800 Message-ID: Subject: Re: [PATCH] mm: fork: fix kernel_stack memcg stats for various stack implementations To: Roman Gushchin Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Linux MM , Kernel Team , LKML , Bharata B Rao , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 3, 2020 at 3:36 PM 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 Reviewed-by: Shakeel Butt