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=-13.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 014FCC433ED for ; Mon, 3 May 2021 16:24:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6A5E7611AE for ; Mon, 3 May 2021 16:24:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A5E7611AE 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 D12F66B0036; Mon, 3 May 2021 12:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE9396B006E; Mon, 3 May 2021 12:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B89D76B0070; Mon, 3 May 2021 12:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 9D66F6B0036 for ; Mon, 3 May 2021 12:24:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5388D2C32 for ; Mon, 3 May 2021 16:24:41 +0000 (UTC) X-FDA: 78100443162.21.9C1F549 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 5FB2A40002DA for ; Mon, 3 May 2021 16:24:09 +0000 (UTC) Received: by mail-lj1-f179.google.com with SMTP id b21so7459069ljf.11 for ; Mon, 03 May 2021 09:24:40 -0700 (PDT) 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=TcATYEvqWtFfx/44txhT0Spsn4kumnm2+a2rXW71+CM=; b=Eaj4rKKhZajb/S9uMXpRE9KCEfy5HuJE+EtOo+Se6CW6ZyQY6bjKa68nq45phIbM8c 9TspWHri3VmH+anix1LFL9doASiwyNTqks3Vv/7hIOtmUu9iGOYIp1pDR+mJj140dErP 2zdwQ4ZzQCYdtRvlXSW3nT+Oui+b+dcaeR9qAq78qteAVIv+oBCqxsjuJawt+JhI0XDR WSEvmIiMehxJm2M0t2lllY238waLTBfzWXMAcWNGZzTHFzl8495jjZshk4PXeB+VzL88 D/Yv7r5Rda77+oUmHrJMYIxfK2ANAzAvW5iNyhVv2B933abB++3JB+BeSQFVVtKcg//l P0nw== 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=TcATYEvqWtFfx/44txhT0Spsn4kumnm2+a2rXW71+CM=; b=rPvgVEKS6cV72MltWFjuN9w4GmOlr/uSct+yOk3PjKc40/WuNr//VLepyFXt2W4GrG Um2UxdgW9+1XVLuruFbUZQ/Aw1FmLH1mQome5v5ZgEUALOj2U9p95ADst6T9DjuAiOYQ 8JMzndzbxe+53txhHPhVsbOlfTiqUWMSFIPjh4QMff8FLBkzF94RtxLiCSWzKZ7Kpo0+ 6CHs9I1CoGYKjq9SjfI8L8BeXglTv2rgYT+SLVMl5TN3u2XJwBd5/pfwN1HZl6WLobYu GF1Y5/RSV+ItETaKJelVQMtrBs4SLjckK3oIzTmSF8Hvk6srV+Nlyu7Nek5oH4+IQSNr Boiw== X-Gm-Message-State: AOAM532l9UksIAz6m0CQCU308PCgGUwCmRJIGBv8s9pjtlJYEGgSqylE RjSEnsOVsLELMs/CNXoXVwXGsBln/yt886hlyo2QaQ== X-Google-Smtp-Source: ABdhPJxwOZF5GNeOtag2xfRjfFSTBwoX7sJqPEbEXnr+f2iHHA67gp9bI5NGIDNieGQOC7JQarf3LW+/cizq2fFp46k= X-Received: by 2002:a2e:94d:: with SMTP id 74mr13275855ljj.122.1620059079137; Mon, 03 May 2021 09:24:39 -0700 (PDT) MIME-Version: 1.0 References: <20210502180755.445-1-longman@redhat.com> <20210502180755.445-2-longman@redhat.com> <699e5ac8-9044-d664-f73f-778fe72fd09b@suse.cz> <4c90cf79-9c61-8964-a6fd-2da087893339@redhat.com> In-Reply-To: From: Shakeel Butt Date: Mon, 3 May 2021 09:24:28 -0700 Message-ID: Subject: Re: [PATCH 2/2] mm: memcg/slab: Don't create unfreeable slab To: Vlastimil Babka Cc: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , LKML , Cgroups , Linux MM Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=Eaj4rKKh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of shakeelb@google.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=shakeelb@google.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5FB2A40002DA X-Stat-Signature: 4cuj8tfirbt8qgsmy7d1yzzayw9p6gyf Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=mail-lj1-f179.google.com; client-ip=209.85.208.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620059049-196096 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, May 3, 2021 at 8:32 AM Vlastimil Babka wrote: > > On 5/3/21 4:20 PM, Waiman Long wrote: > > On 5/3/21 8:22 AM, Vlastimil Babka wrote: > >> On 5/2/21 8:07 PM, Waiman Long wrote: > >>> The obj_cgroup array (memcg_data) embedded in the page structure is > >>> allocated at the first instance an accounted memory allocation happens. > >>> With the right size object, it is possible that the allocated obj_cgroup > >>> array comes from the same slab that requires memory accounting. If this > >>> happens, the slab will never become empty again as there is at least one > >>> object left (the obj_cgroup array) in the slab. > >>> > >>> With instructmentation code added to detect this situation, I got 76 > >>> hits on the kmalloc-192 slab when booting up a test kernel on a VM. > >>> So this can really happen. > >>> > >>> To avoid the creation of these unfreeable slabs, a check is added to > >>> memcg_alloc_page_obj_cgroups() to detect that and double the size > >>> of the array in case it happens to make sure that it comes from a > >>> different kmemcache. > >>> > >>> This change, however, does not completely eliminate the presence > >>> of unfreeable slabs which can still happen if a circular obj_cgroup > >>> array dependency is formed. > >> Hm this looks like only a half fix then. > >> I'm afraid the proper fix is for kmemcg to create own set of caches for the > >> arrays. It would also solve the recursive kfree() issue. > > > > Right, this is a possible solution. However, the objcg pointers array should > > need that much memory. Creating its own set of kmemcaches may seem like an > > overkill. > > Well if we go that way, there might be additional benefits: > > depending of gfp flags, kmalloc() would allocate from: > > kmalloc-* caches that never have kmemcg objects, thus can be used for the objcg > pointer arrays > kmalloc-cg-* caches that have only kmemcg unreclaimable objects > kmalloc-rcl-* and dma-kmalloc-* can stay with on-demand > memcg_alloc_page_obj_cgroups() > > This way we fully solve the issues that this patchset solves. In addition we get > better separation between kmemcg and !kmemcg thus save memory - no allocation of > the array as soon as a single object appears in slab. For "kmalloc-8" we now > have 8 bytes for the useful data and 8 bytes for the obj_cgroup pointer. > Yes this seems like a better approach.