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=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 A2291C433ED for ; Wed, 5 May 2021 23:19:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CEDC761185 for ; Wed, 5 May 2021 23:19:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEDC761185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C4606B006C; Wed, 5 May 2021 19:19:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54DB36B006E; Wed, 5 May 2021 19:19:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3790C6B0070; Wed, 5 May 2021 19:19:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 182A66B006C for ; Wed, 5 May 2021 19:19:30 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BCE64181AEF09 for ; Wed, 5 May 2021 23:19:29 +0000 (UTC) X-FDA: 78108746058.13.F789E4A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 430EDA0003B5 for ; Wed, 5 May 2021 23:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620256768; 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=42NhY9pIv+uXlb41VZhPnr08pYEJ08Pi29tdv81LhX8=; b=Mp5X4gw9sAQN1MsvWogvUs6YaqvOl8JIcDFVZmwOEmDSRj6/uot3a43y2L1cgNl2qKrPl3 ah30XGb9kbHYVXwZeV3eW+oTSzD9K3Zbc/3OCZLd4F//eufbbgtr+VwgSXzfnBqIbkvHPw Uw3EbOkobrfBkUF/6DOGwzv+PCwV0A0= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-130-FhMEZP__MCuSEww8bbau7g-1; Wed, 05 May 2021 19:19:27 -0400 X-MC-Unique: FhMEZP__MCuSEww8bbau7g-1 Received: by mail-qv1-f71.google.com with SMTP id h17-20020a0cb4d10000b02901c51890529dso2791526qvf.18 for ; Wed, 05 May 2021 16:19:27 -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=42NhY9pIv+uXlb41VZhPnr08pYEJ08Pi29tdv81LhX8=; b=RU0rLMLULVA5L/etyJOX3TLvqSnUhlV1IZMU/vlhWoS6AU8+1sibpu7Yiq8NU/k8dC YV5CC0sVyAgjlUM5NdJJSFQg19sizSFKfwguLPAp3wtUcpqHrxFxbrVrk8APQORf44CJ jH3VMRq9i8YB9Swb1VIMEFXZ8WGfrBkCw/HJwvPKAE/ADKFLhOx/lVRoLDJNRlOK+ZKs RIcvagGqYo87BxqkPR07BI6GhIvTNUaSMdoN/H9tHcSrXyWvS5dBoKkMVycZ9p0vm5M3 YLv+M5EXtZLrJ2vxRfQHxWkdf3mZ2zdN5pGiC5fPWXLMinvff5F9g7UKddJKuT097/Jy kf9g== X-Gm-Message-State: AOAM530QdHuuFCQ/sh6asKxYoqUKKTRKpgOiUf+oOq3pT0A/aEQzeyfa CIkk/ek5vGn3AsKsC69s6nYYHl45nQi9qNeYy53XeA6kf4JuppXUtNTUN3VelEWX+fR6a/tIa2t 0Ee6YM7Tzk5ZwBMFz75sh4EwHkAxcH2RjOfEo7G2PQEwHDbC9ZfiDOSWERkI= X-Received: by 2002:a05:6214:e82:: with SMTP id hf2mr1260052qvb.22.1620256766528; Wed, 05 May 2021 16:19:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrf6/P25SquN9SJbJPN+P3WLa7pQBOu70auUucnAsduD5gcjZBVPI39mewNtJuN0YMSZCgHQ== X-Received: by 2002:a05:6214:e82:: with SMTP id hf2mr1260019qvb.22.1620256766268; Wed, 05 May 2021 16:19:26 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id i129sm621947qke.103.2021.05.05.16.19.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 May 2021 16:19:25 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v4 2/3] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Vlastimil Babka , 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: <20210505200610.13943-1-longman@redhat.com> <20210505200610.13943-3-longman@redhat.com> <935031de-f177-b49f-2a1d-2af2b519a270@suse.cz> Message-ID: Date: Wed, 5 May 2021 19:19:23 -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: <935031de-f177-b49f-2a1d-2af2b519a270@suse.cz> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Mp5X4gw9; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf15.hostedemail.com: domain of llong@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=llong@redhat.com X-Stat-Signature: 7tn19eqf71tmzh6y13dp8x3jns5oug13 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 430EDA0003B5 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620256763-26947 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/5/21 5:41 PM, Vlastimil Babka wrote: > On 5/5/21 10:06 PM, Waiman Long wrote: >> There are currently two problems in the way the objcg pointer array >> (memcg_data) in the page structure is being allocated and freed. >> >> On its allocation, it is possible that the allocated objcg pointer >> 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. >> >> When it is freed, the objcg pointer array object may be the last one >> in its slab and hence causes kfree() to be called again. With the >> right workload, the slab cache may be set up in a way that allows the >> recursive kfree() calling loop to nest deep enough to cause a kernel >> stack overflow and panic the system. >> >> One way to solve this problem is to split the kmalloc- caches >> (KMALLOC_NORMAL) into two separate sets - a new set of kmalloc- >> (KMALLOC_NORMAL) caches for unaccounted objects only and a new set of >> kmalloc-cg- (KMALLOC_CGROUP) caches for accounted objects only. All >> the other caches can still allow a mix of accounted and unaccounted >> objects. >> >> 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. On the other hand, creating a new set of kmalloc caches does >> have the effect of reducing cache utilization. So it is properly a wash. >> >> The new KMALLOC_CGROUP is added between KMALLOC_NORMAL and >> KMALLOC_RECLAIM so that the first for loop in create_kmalloc_caches() >> will include the newly added caches without change. >> >> Suggested-by: Vlastimil Babka >> Signed-off-by: Waiman Long >> Reviewed-by: Shakeel Butt > A last nitpick: the new caches -cg should perhaps not be created when > cgroup_memory_nokmem == true because kmemcg was disabled by the respective boot > param. > It is a nice to have feature. However, the nokmem kernel parameter isn't used that often. The cgroup_memory_nokmem variable is private to memcontrol.c and is not directly accessible. I will take a look on that, but it will be a follow-on patch. I am not planning to change the current patchset unless there are other issues coming up. Cheers, Longman