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.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 53E55C433ED for ; Mon, 3 May 2021 20:15:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CF8AB611C9 for ; Mon, 3 May 2021 20:15:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF8AB611C9 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 271C46B0036; Mon, 3 May 2021 16:15:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 221A06B006E; Mon, 3 May 2021 16:15:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09E646B0070; Mon, 3 May 2021 16:15:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id DEFDB6B0036 for ; Mon, 3 May 2021 16:15:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9AEFF181AF5C6 for ; Mon, 3 May 2021 20:15:20 +0000 (UTC) X-FDA: 78101024400.26.FADF5EB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id EBBB680192EF for ; Mon, 3 May 2021 20:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620072919; 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=nqgS52YwzVDVjfWlq3e547UMU0Zz7FIEHtvfbJqFZ2w=; b=dLuTszZBc2sH0hXEn5BdsziArye0E1UMnK4cqrSHagxzQ80Jly0xkUreoZ3/xiYwPCyhHN 17w1FaZrvX7+256pJwoZpYB37W5yHHOPxF0DEFg6eDrUXuYzSLPfccbla0ytzypZt2vpaC gQQyqWtUKB/2QG2zNZkk+dVKQkY4CMQ= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-50-XOaE70BHNjSmk80yTfe7sA-1; Mon, 03 May 2021 16:15:15 -0400 X-MC-Unique: XOaE70BHNjSmk80yTfe7sA-1 Received: by mail-qv1-f69.google.com with SMTP id x6-20020a0cda060000b02901c4b3f7d3d9so5884579qvj.0 for ; Mon, 03 May 2021 13:15:15 -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=nqgS52YwzVDVjfWlq3e547UMU0Zz7FIEHtvfbJqFZ2w=; b=RrpL7wm9qxXTNzubwD2N0b2gEE7jOPoOFbNB3IPQ+43yhraFmXIqLo8pNHxUoMUaqU lcVnFf93OGlRNOmj+B0A+UsYDcZgfvF2VbDixXdv1emiP9xoFy65K9P9GNZv7ayAD9Zm hppt2aBLNmmsq7CPNWqK+Fltaglr0PdS670u5md8yDCYCl1jccVrMT0qjkvxiwBsqxQq lJNaWgWvQaJLGW0le/LV1EKI6ul+m1TNgAr94bBoNkQVBnLAj5in8ssUZRVTeV7pRzEM 6QoxQ/BKwHBM5uHQzBSWxev3mlmZlxvUpywKW+m+KzmrJs+5njwHCju5e4A6yJwILx8r +KJA== X-Gm-Message-State: AOAM530s1AG1IbwMbFPelVUF/occvTtCNndrVrtxhM4fCsFhF0Zl5MAj 4Gc7mUNzD1Fz9YmmYF11n8P3SnLzLb1aBtBKfsqkvqRokpEWn+P3RLm4p6R+atMSG7lHBBjSizy /+SvArdZe4Y4fmjUMgHkYoybzRHbiUBgn3Y+AZJWMXdLOfC/r7/oswKv4gWU= X-Received: by 2002:a0c:fec8:: with SMTP id z8mr22048368qvs.58.1620072914143; Mon, 03 May 2021 13:15:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAkI+kIi2aTR1+TiicexVGxSlGuAs9crPbcBlMV9//3cmTaLpe4A/7vMgqgyaYArxfQOS0uQ== X-Received: by 2002:a0c:fec8:: with SMTP id z8mr22048327qvs.58.1620072913834; Mon, 03 May 2021 13:15:13 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id g5sm1010653qtm.2.2021.05.03.13.15.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 13:15:12 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH 2/2] mm: memcg/slab: Don't create unfreeable slab To: Shakeel Butt , 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 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> Message-ID: <59afa489-3db5-3881-92a4-59b5ee82fc1b@redhat.com> Date: Mon, 3 May 2021 16:15:11 -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: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: EBBB680192EF X-Stat-Signature: kuzbdeiy8kzrpej9muxf6yj6gw71iswb Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dLuTszZB; spf=none (imf08.hostedemail.com: domain of llong@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=llong@redhat.com; dmarc=pass (policy=none) header.from=redhat.com Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf08; 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: 1620072895-254567 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 1:21 PM, Waiman Long wrote: > On 5/3/21 12:24 PM, Shakeel Butt wrote: >> 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 i= s >>>>>> allocated at the first instance an accounted memory allocation=20 >>>>>> happens. >>>>>> With the right size object, it is possible that the allocated=20 >>>>>> obj_cgroup >>>>>> array comes from the same slab that requires memory accounting.=20 >>>>>> If this >>>>>> happens, the slab will never become empty again as there is at=20 >>>>>> 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_cgrou= p >>>>>> 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=20 >>>>> caches for the >>>>> arrays. It would also solve the recursive kfree() issue. >>>> Right, this is a possible solution. However, the objcg pointers=20 >>>> array should >>>> need that much memory. Creating its own set of kmemcaches may seem=20 >>>> 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=20 >>> 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=20 >>> addition we get >>> better separation between kmemcg and !kmemcg thus save memory - no=20 >>> allocation of >>> the array as soon as a single object appears in slab. For=20 >>> "kmalloc-8" we now >>> have 8 bytes for the useful data and 8 bytes for the obj_cgroup=C2=A0= =20 >>> pointer. >>> >> Yes this seems like a better approach. >> > OK, I will try to go this route then if there is no objection from=20 > others. > > From slabinfo, the objs/slab numbers range from 4-512. That means we=20 > need kmalloc-cg-{32,64,128,256,512,1k,2k,4k}. A init function to set=20 > up the new kmemcaches and an allocation function that use the proper=20 > kmemcaches to allocate from.=20 I think I had misinterpreted the kmalloc-* setup. In this case, the=20 kmalloc-cg-* should have the same set of sizes as kmalloc-*. Cheers, Longman