Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3959245ybf; Tue, 3 Mar 2020 16:44:34 -0800 (PST) X-Google-Smtp-Source: ADFU+vv6gps3C7zh15PYClKXBwDkEz9O0I0tHfr9OkmEBLpuazFpOtZxpg4jZ347hGLsEUd+qVsS X-Received: by 2002:a9d:6a06:: with SMTP id g6mr389201otn.305.1583282674819; Tue, 03 Mar 2020 16:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583282674; cv=none; d=google.com; s=arc-20160816; b=Dw8FBJ/cmMKdU3NkoajwwrQeRAPgaf2cJigQMGzbehixzzozivb03vUl5YKRBJQTNp MgsPsNWFyJVp1EVKanXy9R2fJ1tmo2dnBksJN79OCUycGgPCSf29LqrnlQhDpJR//FDP lnxZYF8kn5QUDZ/SO6cTLjskCjEGgY4VclXKokquiIlq0lBckUohCkH4irgN/cy0NXsE uOQge5LCeVuZsMtdWo3xBQ4568jbMGtg+LbjPlIJcET5CfCUpUb2gvI7RGHTpXumFHc3 sG2tHolYd0KmV4c0RtqZq/deO9JqTdK7VfA/7iqejnOIzcw5fVEWxkA1nwLjTZ+oHsJ8 jdYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=wOjgETEggr7acXmXSIGKLYA84kpLrcA+aOyLjNXDSaw=; b=lMfV+ZL9ONzn7j6+ZvIwzB9mp+JupawBgNpTn+kkcyXrZpcYCX4E4Ybc5UXQHgJxuJ PQC6kITQsb6t0eV+wrP7K2aa2CMBy3JMUw+QrY+vErjvkZy5CE5GwGLoQB041piCm0ab ri7KmWbNILTqjpljQq7fb+PcFDJnBXwtxzSYbCLEnJYDZHY/IYbyT6DTcE3zor1ojDiu b5rMBzXpf10fk/h6HZHg2IqWkcINxpsj9mXBNZFlzWBzYfcVwNbgOFM77CbkmHcLlBhB u4v6AqX8e03OumPYIIk//dfzoPrhinZUsNKZEZzq1c+LQd5HX93izAzLuwxE7dMpFamp MZVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=L24u5zqD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si161368otk.80.2020.03.03.16.44.22; Tue, 03 Mar 2020 16:44:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=L24u5zqD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387402AbgCDAnF (ORCPT + 99 others); Tue, 3 Mar 2020 19:43:05 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:33472 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727864AbgCDAnF (ORCPT ); Tue, 3 Mar 2020 19:43:05 -0500 Received: by mail-qk1-f196.google.com with SMTP id p62so7106qkb.0 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=mXgc9jFGobz5Qeac5C/Toemryl364ufEKQBtDYGHjlsTg8AvJ+bAWqoFI0e8F6hmat QQXRRQoCQgisJHbabMb+6vcaR7Yn76iFeOaPJ4+C3uq9IoboA0UaEXuERmVxOn5kpxKZ j9md/mAkfgLOqQaPGsBQJCzkhzYHIg0QsTUy206pr98XNBqv3EIPFr3KtYsmIN7OLDir TY42Sj8oSu5bMrnNCQ1RyOdT6k7oZmJoNYyQGXqWsMCgK60Vh165rntTwFe8epBIs4e3 3LV+77f44akkz7l1RsaaInF8W3rH6Yjy5HWGtWvJen/MAgPQ+Gn1CUdDf6WS3aNOxwXv ssfg== X-Gm-Message-State: ANhLgQ2WbOSxtXjMg8zEpe+mNIRVnHEl75hqT996SBJ+8n/W8LXrLo70 sbwF9pJhvVfAx8aKRmIIDH0nLQ== 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.