Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp300509yba; Thu, 18 Apr 2019 01:16:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfJwvcJZpoJans6lRJ6eqVf1dbQzVcilwzO38MGSMMHnijd6PcPi4I+X5ZYPa4xtaxgd97 X-Received: by 2002:a17:902:9a89:: with SMTP id w9mr95049685plp.126.1555575409089; Thu, 18 Apr 2019 01:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555575409; cv=none; d=google.com; s=arc-20160816; b=OC0gEhTiC4NkxJmVo99EpyLRR0v+sa0GZRcuZbTaf/J1cqlmN7YznW+oqET9WdeT+5 5wCOzF7T0wXmjoklnWA2FJIKXgevFNV9Oaj5pbma9ToJs3/w2bC8NsRxyKNq02uzcv7z 2deLWqlT/lS3ji5igBRVxCsoYPPefc/W7ZBY8OORr2KPZMgBrCSyDI5Tp/O6R2PYsPSW cw4z+RscW5F9Yv2Qn9xuty55KS+yDxVIWYBn3HVkWXkU49zJYuLhCfGglaqnE5XYC7/1 fTo1sy7YjWvdOpEx6JHCDy2SDQmBZ0c0h3ERkjCWXlblxfMFfVMTWwmkRCWxmGPsvu44 Bu0Q== 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=N323ote5HssxsLbgpRKGomemLtnlwkK3ixDMsYVRR2E=; b=owfLy033oUllmkoQ2RUn/JWOPAEhu2B112n4jXg3Pv0nw7SNFA+i3xnXDmJPH7WROi BYgQRXD7UWX9ZaZBctAZLuZgJgRnc0Caauwu+yAg7EJY2IuCGZvjewrsIAhZCbgSxjRI mHEEq3D/4iEYvbatw7Ij/FlcoOY31+l46vDaVlgEgM6BOo4n5tUPyT24n3nGKHym22K8 genzPZ7Gw49ZZb9L/CEOVszBiK8sIhOLtuColbIX8YQRBdClgQojhHUZODZP9BZiGEr4 k+ynrEblgb15sAjaDPa06RlDGlwXkA25qPGqsc3514W3Dnb+syrH3l42tI1r6ssvzokD hGQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WMYdzWgQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si1449364plq.400.2019.04.18.01.16.34; Thu, 18 Apr 2019 01:16:49 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=WMYdzWgQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388197AbfDRIPm (ORCPT + 99 others); Thu, 18 Apr 2019 04:15:42 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42664 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfDRIPm (ORCPT ); Thu, 18 Apr 2019 04:15:42 -0400 Received: by mail-lj1-f193.google.com with SMTP id v22so1123471lje.9; Thu, 18 Apr 2019 01:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=N323ote5HssxsLbgpRKGomemLtnlwkK3ixDMsYVRR2E=; b=WMYdzWgQaP+pXUvSIR0Au7VkGGsnRl6OCThTg4EgOhwD8wOevcHwx+wJU11rkan+k9 mCfqu5ph/kf5FsMAwMRbizVoepAdM6+vYV8m+xe3GqrGQZLrsB5esZVa91DzWZxaG6Ps CQI0D1agoPwX01DUSe5CHaLm8J7aoOzub6m+L+4eXpRxTVNMFl63TopOk4asM/HDoQlS SIgpzsz5OVI5ASSTTtdc2vJHlGZOiKZr3LDH9KGpW+udXkX4/irjjCCJYf3woOXsCdc+ bYiVHodrDUaDggrr7a987OZYleMblygMql7e4P6dBn4GyZqk4Q+uLeM0JfRQKuTgb1Yr 1exA== 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=N323ote5HssxsLbgpRKGomemLtnlwkK3ixDMsYVRR2E=; b=Z1sNjBfpwvoonEgqxaoPpuflaaQ8+hh/yyi8vbcJ+pSMf5uLP8+YYXlLN2yUWsl1dK NvWlQEk8u4stK6t84sISyGybmVDX+xWh1YnYoVosC3IHCls/0SHvVSUe2OhegJJTB39g YuN7jyudQXn2hACYm0J/kKLLCvSndHz93OHF9NZX09LoHMyudTn54IyOSF/GA6tv+07N AafFLreN5oYj7TL2hrlyMTONdp4F+oF7ZQO3UTL4LIrEDkV4LnCPsKpy5lrynUco82+a 6+qx7OAEZJ1FHQ1Tp2DluksUiTwCVFZ0FWEGXuzaoC1UBrdtVKImDw3ml1T5/Z9vXCkG VvQg== X-Gm-Message-State: APjAAAWmMWRya0eAm66a2Rmg4y/pE8UFDbRhyrtMBJ4yoAED3TYQKStb qsc6g4HDdvdSnAoQYFytXak= X-Received: by 2002:a2e:8316:: with SMTP id a22mr10057018ljh.171.1555575340347; Thu, 18 Apr 2019 01:15:40 -0700 (PDT) Received: from esperanza ([176.120.239.149]) by smtp.gmail.com with ESMTPSA id v11sm296970lfb.68.2019.04.18.01.15.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2019 01:15:39 -0700 (PDT) Date: Thu, 18 Apr 2019 11:15:38 +0300 From: Vladimir Davydov To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Michal Hocko , Rik van Riel , david@fromorbit.com, Christoph Lameter , Pekka Enberg , cgroups@vger.kernel.org, Roman Gushchin Subject: Re: [PATCH 0/5] mm: reparent slab memory on cgroup removal Message-ID: <20190418081538.prspe27lqudvvu3u@esperanza> References: <20190417215434.25897-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190417215434.25897-1-guro@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Roman, On Wed, Apr 17, 2019 at 02:54:29PM -0700, Roman Gushchin wrote: > There is however a significant problem with reparenting of slab memory: > there is no list of charged pages. Some of them are in shrinker lists, > but not all. Introducing of a new list is really not an option. True, introducing a list of charged pages would negatively affect SL[AU]B performance since we would need to protect it with some kind of lock. > > But fortunately there is a way forward: every slab page has a stable pointer > to the corresponding kmem_cache. So the idea is to reparent kmem_caches > instead of slab pages. > > It's actually simpler and cheaper, but requires some underlying changes: > 1) Make kmem_caches to hold a single reference to the memory cgroup, > instead of a separate reference per every slab page. > 2) Stop setting page->mem_cgroup pointer for memcg slab pages and use > page->kmem_cache->memcg indirection instead. It's used only on > slab page release, so it shouldn't be a big issue. > 3) Introduce a refcounter for non-root slab caches. It's required to > be able to destroy kmem_caches when they become empty and release > the associated memory cgroup. Which means an unconditional atomic inc/dec on charge/uncharge paths AFAIU. Note, we have per cpu batching so charging a kmem page in cgroup v2 doesn't require an atomic variable modification. I guess you could use some sort of per cpu ref counting though. Anyway, releasing mem_cgroup objects, but leaving kmem_cache objects dangling looks kinda awkward to me. It would be great if we could release both, but I assume it's hardly possible due to SL[AU]B complexity. What about reusing dead cgroups instead? Yeah, it would be kinda unfair, because a fresh cgroup would get a legacy of objects left from previous owners, but still, if we delete a cgroup, the workload must be dead and so apart from a few long-lived objects, there should mostly be cached objects charged to it, which should be easily released on memory pressure. Sorry if somebody's asked this question before - I must have missed that. Thanks, Vladimir