Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2932992pxy; Mon, 3 May 2021 11:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5QIdrgNBYvnGvPRlvW3w6dyi1g5RUo+VmFPaHG+F4HxkZh6iudIVFq96nbR8PFxcWBd71 X-Received: by 2002:a05:6a00:2b5:b029:28e:9c4b:b8b4 with SMTP id q21-20020a056a0002b5b029028e9c4bb8b4mr6199433pfs.22.1620065437365; Mon, 03 May 2021 11:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620065437; cv=none; d=google.com; s=arc-20160816; b=b7mRNQTWsNVeeAcZOx2/PxLFAMOVnHPD/T0d5BSGoKTL3CUyMncYCEJSYkqBpxNvXf TCuziT4xujfD7BoVizWXiCPM/ceTH+hRBi5jiYV1GSGy8j0Rmw6h2M2uq/U10gJl8R3E UOpICtOnKHhmhJnf9fsOabETkVlSonj6WsTO2B+KjYX2uOEKgozrcuyZ30thH0m5N6BU evdWFSbJ+GCHVr22iTpG0K2RaBhfWXJBiofrlGQNgqTe0n9MY3qCkhuMcwRmteLUS2dO tHRHzS9aue/WFSjVF3Vep78WNTQ/MLpKPt4y/+hYb5+t7gRCqwMWisis7ajlS9ntR0Ut xp3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=W96LQ5ws50PeBqmi6Tqyokcu71irUaZsvFKrRdbNqzA=; b=Sq0D1RbnqTHII30Rt7HuC+R9V9IPm/Gwhk1lu8SCfoiFUcksfN+1OIfHEEMpbgSf4I Irb3MmgPbyvRoGZnZyad3u84ZF40bprbjv/VLGR+H+LGw0620EQpCaxwFSKTF6k9UZSS YRO4R00+z73tvdVl4zo3UcKKiXoo/tZVXDeuu/4t1z6V/elWRss6KVHPjS9eHvR9NUx6 e0n9BreXTlGHqALwo5IuM9VnIaHtHn2T8qkzgb3lrWOPR3WzABtKR0Yna1Qsml8W1XW7 YoS37GI4t62s6VCxzF/+rcXgLsHpeFcMA9nwG23ibX1Y1eek9oSySH6Jwf3IDbtfBaC5 GuNg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si472862plf.299.2021.05.03.11.10.24; Mon, 03 May 2021 11:10:37 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbhECPdU (ORCPT + 99 others); Mon, 3 May 2021 11:33:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:41454 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbhECPdT (ORCPT ); Mon, 3 May 2021 11:33:19 -0400 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Vlastimil > Cheers, > Longman >