Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp714594pxy; Wed, 5 May 2021 11:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFvsE8+Tkp6LOHwjxlc1kLcJ/0jLqVkm7/vhRNmNRtROTQ0leF735aPZz1Es1r3wxqfce1 X-Received: by 2002:a17:90a:f690:: with SMTP id cl16mr24040pjb.207.1620241098668; Wed, 05 May 2021 11:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620241098; cv=none; d=google.com; s=arc-20160816; b=qPc+LhiB8nUZsyoitWc8Z2MCU8mQcQpKx2C64J1P6j1k3Un/nB1e8qlPvYimqbttIo oMfp7TlYoGgeGWqU+NFGCZz5xNHInCEplbBrHidDt4Myg9FtpJHf9+0zjHEVpD6XVA4i BuLSG+SijX3m8mob6KY0It2TwqU3rDustfVA9REuDM4P68ucZb+n5lhWXGJtoLZVIum8 j30QgC8Zjl4i+sz1PBewsSkd5d+xJcioCG73MRJSLUC06HM+TWbz6xzIWaT222z3ePwt khwb9DlGz/zH7Pn6gZP8iaNvYP2dTJjqG781OJ073JacXuqel/jVlQNzLhlIIEAmgZqW LbtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=RLt9keyCtnOhXLfxqmhiGEZ6r/sGiYdHdPIuhsn7KMg=; b=sPVvstskitxVwCUTfEkGbt/mhWowtEEoLlGn39h9Ji4Wx+f9506L2hx4T/KPhS7pWK rcIj8kgWhNxNnZ5cDjk2AhJuLrDaCLAGiDy9erpNDYlmKKX4p7eEta4fCynxqQiiorH7 yYM2WP3ouNA4zQPitI3Xf2Xw3GawgI74rWJSk6JIKEDTidtocPzq6zB4mWQB8KjrXlBr 81YqHY2JM7b+HkD+Jeq5Cg8Gvym89eFpQ2LtEqDMgUnWa8O1FdJCxYbVKxmP3ukFfsEk Kida8xLGexIGuDD2ShwlwhgRZFX23SqbkBJcKnSKp2Yqiv88PgaGEhq59yncHWtObHtP Xldw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QKKI6vBP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s19si66847pfu.44.2021.05.05.11.58.05; Wed, 05 May 2021 11:58:18 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QKKI6vBP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235020AbhEES55 (ORCPT + 99 others); Wed, 5 May 2021 14:57:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55566 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234277AbhEES55 (ORCPT ); Wed, 5 May 2021 14:57:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620241020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RLt9keyCtnOhXLfxqmhiGEZ6r/sGiYdHdPIuhsn7KMg=; b=QKKI6vBPZP8qipV3O5mdDifi/b4xPXNN/PtzOiPMBHlvp53tMOVtCjlMYnnyH6bSaub92c W3/Kt9J44RzkN229zn4/vqnjG+tSZ4YKfWT/7T3K/H55rfXKE27Hh1rJIQEQOnaTTQB+Lq thLy2a2u/6qYYAGHOshJEDIL/8VqlsI= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-502-08dEve1LPP2zX7dBPgiKjA-1; Wed, 05 May 2021 14:56:58 -0400 X-MC-Unique: 08dEve1LPP2zX7dBPgiKjA-1 Received: by mail-qk1-f198.google.com with SMTP id c4-20020a3781040000b02902e46e29acf5so1803230qkd.22 for ; Wed, 05 May 2021 11:56:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=RLt9keyCtnOhXLfxqmhiGEZ6r/sGiYdHdPIuhsn7KMg=; b=dSZ1JJUEkFVVvCRUI1YYrl+jmMquMRMkpcnD63lxAMoaZ+ApX978Y3fBbO80rLe+0c oN1UOra55Jku38DDnREUF5oowaCpUY3KiMxdsQB5T+CWtX/nmeG1MPPrrtwHJY+AiZRo VlmkU1ZO1WRd/INE6NlaDBv1a235boodyYi+KOQW2/84mpfekMbo5HoybLOaLrfOf8Aq VcIFGfqdWUBv6DCDhaeVKeqRsv73YM2pvqu2OE5jLwQr5f1NJY9gVuxnNbrs9BLTcOtM reZW7/p4ZELSn3hNuxKqNyLYjOM0RKxmeAWT9dm8+PdjwlKe+JQtujmPDdqb7dnX2CM/ 3s6Q== X-Gm-Message-State: AOAM532Jy3rjRzqAPrWd5AsIeeoU8nKuFjinxcqp2G3ck0biZCjXGoDt 96T4EJnYuL982c6ErSBSoiRUGIYG/Ap+aDqGZ0SeQWgQS+fjug7cu6JA6LEHV6oEtJpYcygJi/H 37PD8BUdumCz17eNOGGTcw0l3 X-Received: by 2002:a37:745:: with SMTP id 66mr204366qkh.5.1620241017477; Wed, 05 May 2021 11:56:57 -0700 (PDT) X-Received: by 2002:a37:745:: with SMTP id 66mr204360qkh.5.1620241017317; Wed, 05 May 2021 11:56:57 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id a195sm109640qkg.101.2021.05.05.11.56.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 May 2021 11:56:56 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v3 2/2] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Roman Gushchin , Waiman Long Cc: Vlastimil Babka , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Shakeel Butt , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20210505154613.17214-1-longman@redhat.com> <20210505154613.17214-3-longman@redhat.com> <235f45b4-2d99-f32d-ac2b-18b59fea5a25@suse.cz> <4e4b6903-2444-f4ed-f589-26d5beae3120@redhat.com> Message-ID: <1b235531-e165-954a-74b1-d3477c2a4b87@redhat.com> Date: Wed, 5 May 2021 14:56:55 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/5/21 2:38 PM, Roman Gushchin wrote: > On Wed, May 05, 2021 at 02:31:28PM -0400, Waiman Long wrote: >> On 5/5/21 2:02 PM, Vlastimil Babka wrote: >>> On 5/5/21 7:30 PM, Roman Gushchin wrote: >>>> On Wed, May 05, 2021 at 11:46:13AM -0400, Waiman Long wrote: >>>>> With this change, all the objcg pointer array objects will come from >>>>> KMALLOC_NORMAL caches which won't have their objcg pointer arrays. So >>>>> both the recursive kfree() problem and non-freeable slab problem are >>>>> gone. Since both the KMALLOC_NORMAL and KMALLOC_CGROUP caches no longer >>>>> have mixed accounted and unaccounted objects, this will slightly reduce >>>>> the number of objcg pointer arrays that need to be allocated and save >>>>> a bit of memory. >>>> Unfortunately the positive effect of this change will be likely >>>> reversed by a lower utilization due to a larger number of caches. >>>> >>>> Btw, I wonder if we also need a change in the slab caches merging procedure? >>>> KMALLOC_NORMAL caches should not be merged with caches which can potentially >>>> include accounted objects. >>> Good point. But looks like kmalloc* caches are extempt from all merging in >>> create_boot_cache() via >>> >>> s->refcount = -1; /* Exempt from merging for now */ >>> >>> It wouldn't hurt though to create the kmalloc-cg-* caches with SLAB_ACCOUNT flag >>> to prevent accidental merging in case the above is ever removed. It would also >>> better reflect reality, and ensure that the array is allocated immediately with >>> the page, AFAICS. >>> >> I am not sure if this is really true. >> >> struct kmem_cache *__init create_kmalloc_cache(const char *name, >>                 unsigned int size, slab_flags_t flags, >>                 unsigned int useroffset, unsigned int usersize) >> { >>         struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT); >> >>         if (!s) >>                 panic("Out of memory when creating slab %s\n", name); >> >>         create_boot_cache(s, name, size, flags, useroffset, usersize); >>         kasan_cache_create_kmalloc(s); >>         list_add(&s->list, &slab_caches); >>         s->refcount = 1; >>         return s; >> } >> >> Even though refcount is set to -1 initially, it is set back to 1 afterward. >> So merging can still happen AFAICS. > Right, thanks, I already noticed it. Then yeah, we should make sure we're not > merging KMALLOC_NORMAL caches with any others. > That should be easy. We just set the refcount to -1 for the KMALLOC_NORMAL caches right after its creation then. Cheers, Longman