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=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 7885EC388F7 for ; Tue, 10 Nov 2020 15:23:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C677E20795 for ; Tue, 10 Nov 2020 15:23:36 +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="FUGXZAUO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C677E20795 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 45B226B0068; Tue, 10 Nov 2020 10:23:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E67E6B0071; Tue, 10 Nov 2020 10:23:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AC846B0072; Tue, 10 Nov 2020 10:23:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id E45636B0068 for ; Tue, 10 Nov 2020 10:23:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 82BF0180AD80F for ; Tue, 10 Nov 2020 15:23:35 +0000 (UTC) X-FDA: 77468877990.09.net26_14073c4272f6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 643E7180AD806 for ; Tue, 10 Nov 2020 15:23:35 +0000 (UTC) X-HE-Tag: net26_14073c4272f6 X-Filterd-Recvd-Size: 4203 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 15:23:34 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id h15so11720132qkl.13 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=tBB+VW/FVVXMyk+Irkz7Kn/QF/bRPbDdx/3la4wipQn+BEThPTCyTl1C+mbEAPc1J6 FCQpS+Zjw0f9lk9mp9MWJP9P76S3GZa+Db8Z1IGa7o8lH35br7PQvHh6CS5PpZOZKiQn 9lyxpxBRTxrgehn4nTEJN9uJ+M6/MqFprbL7hKQzsC1xz1Xtv2+BYWbH1Me9PQ22oOMk d282KiHubt4VQgKBDCf1vkMx43k10kNDGCktdMO+xpe+3p6CX95k1UpZIwZfat9btQOg VtBugl5h7Vi58/hUzi/i9j2o38kCeGrNzpJ8WwkYJ1Cwc7AOfvQwCZg+gvWMhEpNsQ6M nZoQ== X-Gm-Message-State: AOAM530lTYlIxD9941OV/Fm52ABCaODQZQdJ/2HLD1QcbDIjJkjKispa NW5iOQMESRuDQ5eiKa5tmxRjlA== X-Google-Smtp-Source: ABdhPJz/w81kK3M3g49A8qO08fFld6TFs0sT7VUQmRNYF8+G8TbS49BlNYUAL0utDT4+QJpNUey1DA== 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> 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 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.