Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4077462pxb; Tue, 10 Nov 2020 07:26:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/VHYwOlx/A9LMoJbWDJzgn+UczDLkfi6jJ0I4rVWNPqDi6GtHBNTBV0Fzkm5wR07Ll4Si X-Received: by 2002:a17:906:12cf:: with SMTP id l15mr21815652ejb.540.1605021973386; Tue, 10 Nov 2020 07:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605021973; cv=none; d=google.com; s=arc-20160816; b=fpDAJU6LHcp08KRz+XUvHI5h9Qpb2OOvfzXhpVFductAs97AV505fzS//5tWAiYQ+J G5ex9PYAKd8atMH49Z/ssdU7ngT7gdklIojMtFtSlavAatVsvuSdZVccTlzDNTn2JVY7 0OdGXsugiHP7SaO0o3dtLkaAkD8WAchVmbZGjl3tIxuMQpIOj8vS2cI0TuVAlug1kvZw XTcM+SYMMrZapK5m0uLYUj4q5uR1yZrcQwHQAzk0LJ8us4jTmz2DXKOxamm3lkG7Y4M0 Hn+KU4n2Pgh7o8PfdH0GlzOpbsXO78gbs6QYWQeRcGYqWbwTEJjhjbZbO2CbniXz77Z2 NjCQ== 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=K5DYC0FobzbOJlRls9qSbY8/GAak6t3HIKm/xVpE3ns=; b=dmOJ2VRMLwU4/9ZKXPBnL9IWBNxpDtHxCUB4u0DPZpYL6fjaFJEsvY+RGGos4P4c/4 LRizmyu7WN9BcrAQkaM/OYwA5mUQuT/gK9OjLT97xh0bI1MOOVYfB1l4OnixevoRZoxj 6674nDPoKMJ3xvnmV/zAeuto8rvIwTvkEEvDLnBdp7U/nIkF6RtuIkKeM7rD0LbyZJpP IL8ABe3OQESjmBUChRAXGGbb/ZE0wF0xk59oCa0tCKiH5oCeoae15QFv+re8TEOhRFBX EIr4TCLXHC8V6QNIUUOaDsGpjOVK78N4GZM1MaUGejXuVpI2M8rKjUAoR35W8F7VrGdS PDQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=FUGXZAUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f21si9678711edc.514.2020.11.10.07.25.43; Tue, 10 Nov 2020 07:26:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=FUGXZAUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1732214AbgKJPXg (ORCPT + 99 others); Tue, 10 Nov 2020 10:23:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731182AbgKJPXf (ORCPT ); Tue, 10 Nov 2020 10:23:35 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D440CC0613CF for ; Tue, 10 Nov 2020 07:23:34 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id d28so6651935qka.11 for ; Tue, 10 Nov 2020 07:23:34 -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=K5DYC0FobzbOJlRls9qSbY8/GAak6t3HIKm/xVpE3ns=; b=FUGXZAUOLHUkTcP4cjeXCSoGU8L1zbPYlFXRTukgjTvaNV4VmPdoTLN7PgunQS0e3I zz9ZrsXqcJKMJstDSanvHZjFmDfPwF6TICz+RZ1imaBp6vp+96VH6EyygGO7TuQhoG8S GzgILEKH9P0dMJIGCbHqqSgHPqPGr3LOIAC1zwVyJ2f89gG3bzXiUiTdQEzCTaw2UWoY ZbcgXnmrLbFSdpjcteVRdAXdWbz0Ccuj3CUGD+fEm09sEbpJN7SuDCHzdKNfVgT1Yqgm wkaC8IQH2WmJKPYjp2Ij8yk9VGDCLqVvsAOLwVaS1VBuSsrUt2NIlRUY4RRxqnbrz7xl Ch3g== 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=K5DYC0FobzbOJlRls9qSbY8/GAak6t3HIKm/xVpE3ns=; b=flQl98VT/ABGYaM4IcHXWBrB4nYoJgFMvr0GaUgbPeleTHzCYJAS9nms2n2T3mfuLN lV+//dp+chT0aGxetgPWFCgyh7kjck+54048jC8MQJiWT/+fyjaw7gaHQ0Zim8T9ziYi O0y7ltAU56txbASdyjcVsUGqnNJ/Wk5aFihFl5WhCOPZZHzhiMi4J96ybUhsDkm62Ov8 t60GC5RoWRQGUfYlbRdJvKzscDTLjM0FpgJTLm1xQCCBIab0ad7fyqwUJ4GTIf7tp7X0 C+oeOtbKUnAObWw82J2cu3vIrC7HQ5Hggn+UE0hLmEPQuUHz7Fpg/IC36dTfIjYE+1cV hMOw== X-Gm-Message-State: AOAM532+tMBZ79gPRv+DpQ4EaIJEcdJW8Q+oq7ZNX4U4aaUaD0s6NB/F ViJqZdvhUjyaTuH1QzckqO/KnQ== X-Received: by 2002:ae9:dc06:: with SMTP id q6mr20220970qkf.310.1605021812009; Tue, 10 Nov 2020 07:23:32 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:64f7]) by smtp.gmail.com with ESMTPSA id 203sm5869940qkd.25.2020.11.10.07.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 07:23:31 -0800 (PST) Date: Tue, 10 Nov 2020 10:21:43 -0500 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, Shakeel Butt , Michal Hocko , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] mm: memcg/slab: enable slab memory accounting atomically Message-ID: <20201110152143.GA842337@cmpxchg.org> References: <20201110010615.1273043-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201110010615.1273043-1-guro@fb.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 09, 2020 at 05:06:15PM -0800, Roman Gushchin wrote: > Many kernel memory accounting paths are guarded by the > memcg_kmem_enabled_key static key. It changes it's state during > the onlining of the first non-root cgroup. However is doesn't > happen atomically: before all call sites will become patched > some charges/uncharges can be skipped, resulting in an unbalanced > charge. The problem is mostly a theoretical issue, unlikely > having a noticeable impact ion the real life. memcg_online_kmem() is called from .css_alloc rather than .css_online, at a time where memcg is brandnew and the css hasn't been set up and published yet (the refcount isn't even initialized for css_tryget()). I don't really see how charges could race with that. We may want to rename memcg_online_kmem() to memcg_alloc_kmem() or something. > Before the rework of the slab controller we relied at setting > kmemcg_id after enabling the memcg_kmem_enabled_key static key. > Now we can use the setting of memcg->objcg to enable the slab > memory accounting atomically. I suspect that code comment has been out of date since commit 0b8f73e104285a4badf9d768d1c39b06d77d1f97.