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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 D82B8C433ED for ; Mon, 3 May 2021 15:32:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 625186117A for ; Mon, 3 May 2021 15:32:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 625186117A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A186C6B0036; Mon, 3 May 2021 11:32:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C8E46B006E; Mon, 3 May 2021 11:32:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86A506B0070; Mon, 3 May 2021 11:32:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 6CCE36B0036 for ; Mon, 3 May 2021 11:32:27 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 32B1E12C2 for ; Mon, 3 May 2021 15:32:27 +0000 (UTC) X-FDA: 78100311534.30.9A0BDE7 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf20.hostedemail.com (Postfix) with ESMTP id E60C5F2 for ; Mon, 3 May 2021 15:32:18 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 59593B01F; Mon, 3 May 2021 15:32:25 +0000 (UTC) To: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Shakeel Butt Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org 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> From: Vlastimil Babka Subject: Re: [PATCH 2/2] mm: memcg/slab: Don't create unfreeable slab Message-ID: Date: Mon, 3 May 2021 17:32:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <4c90cf79-9c61-8964-a6fd-2da087893339@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E60C5F2 X-Stat-Signature: bcs6rqoodxtadgxq66pbbeqw9tboq31w Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1620055938-33524 Content-Transfer-Encoding: quoted-printable 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 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 happen= s. >>> With the right size object, it is possible that the allocated obj_cgr= oup >>> array comes from the same slab that requires memory accounting. If th= is >>> 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 fo= r the >> arrays. It would also solve the recursive kfree() issue. >=20 > Right, this is a possible solution. However, the objcg pointers array s= hould > 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 alloca= tion 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. Vlastimil > Cheers, > Longman >=20