Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4642703pxb; Mon, 28 Mar 2022 00:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLb7hBEAHtlU/86bkq6s62AD2paHob8YnIItemyd0/PvbFa37KLumnSqcJFTmJuLcVyeq4 X-Received: by 2002:a17:907:3e99:b0:6df:7ad3:f66b with SMTP id hs25-20020a1709073e9900b006df7ad3f66bmr26583688ejc.230.1648451149413; Mon, 28 Mar 2022 00:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648451149; cv=none; d=google.com; s=arc-20160816; b=PROY9PFmtoaWBF25vKwjU+GTYwb+1ZSHFF5dJKVmn+5LVebQyKRXMRef+XobuGLeIT bgL3JwnWtKDCflF2X9FzMxTrPNK5PTk4NAVskQFEvucHelQ51FW6Ra3/rEl0RXoaFK2n pz7FwzVw2Ki+TJp9AuMj4ZjSM5Rt9BtJVVOcdeR8E7ULEvjbNp1d/g26FurSXkVTgqgA V1oD8O3hJ+T1h5blf+ChKYMEwhDb6wizylS7iLHhSv+h44T7ZCxW8Z4OGaoXbfLuTDUG 1XYQCIz9sr3kUJRmlVxQuhzSWXTvkR0xvL6x5gkHNkypKaWs+9DSEBaCoEVEKAg3h8cq 7DAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kp+n7MjmnLTJ4vOAA537LLcCjh6KRC0etIIuCa/wcqQ=; b=N/35cBLtvDys7uTjX/amLYncQAz+UF4z04Nk3hsyex5azcbvk5zWtZQ0aLzsg1Sfg3 ow9n1Xb3rjAn86FxOHw5vAfrbxD4wafSjOx4S74hEtPPyhhgWeqBpnVdJsrVdbxsGyqH a17HMkXXRktiLj867jmbhsDdWpZziukOJtJEEIpwOPENAWI9zDpFGHFwn1iAaLM2I/5J a8oX+B7uGEK58axoAcDRoGJXi0KWkQ+xnSxmOD+4Mu6aghjpdqkyVZacLIXs9yfPIl7+ 2hbhIntMVOjvz2PxJFvI4qvbM6bNoBDmQPvYWGBV9GMom3/z5g2OKcaM1TnHccRMFZyo LmhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=icDZzCAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020aa7d708000000b00418c2b5bf73si11762101edq.597.2022.03.28.00.05.24; Mon, 28 Mar 2022 00:05:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=icDZzCAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234607AbiC0FpV (ORCPT + 99 others); Sun, 27 Mar 2022 01:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232607AbiC0FpS (ORCPT ); Sun, 27 Mar 2022 01:45:18 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B78FDB for ; Sat, 26 Mar 2022 22:43:40 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-2e592e700acso119181557b3.5 for ; Sat, 26 Mar 2022 22:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kp+n7MjmnLTJ4vOAA537LLcCjh6KRC0etIIuCa/wcqQ=; b=icDZzCAPN5GzbIs+eeeY5TNGBRG9fV3oU6z+g0Dshz7qXNcvNe25C09q2gQBxiVQKm BPvx9nsC8xFm+raqnG0tK6LL4xi/wSZ69riv36QGC9YvgpI2rEq9CqUsz7JhVmBn2gYR W3zAr1bQe+0ML/qTY18DiE8AK1LRW6NMRf6CXu/8ujOCOAg3851aNlzvCSF+ORKoq8Kh ty696EWA9jVAe8eGmqO5/uMA7L6CsQY/8BYppV4yD3ILqroCSC8AriglDCA2PuQ3Kt2k XCWm6/8wntsx4G9rdOE0LuUcoookkpQKFIlP+JA5xl1vcIsLErdvCsQ4ndWV7dWYwgCx kLzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kp+n7MjmnLTJ4vOAA537LLcCjh6KRC0etIIuCa/wcqQ=; b=u+slCl95uEtfkSq9H36PhMjbQ0rQUTRLt62EIaG3rNPrpXsMXpROiH67hYqhnSMtG2 ABC+B34VoMJCJbyowU9Yk01R3/qPOvVkQrSreQzQVFEXDQDXNUGYK2zunuiRGlOKVVrc otPR/lEEUeYc4R4pAEMkP55LT5YF23BffhRZpv+OjqdnV/DYYoYxRJEO4epXenrxUna0 d8BwnpvCkycE5409pf9QN4ACRBGlNyIvuNxsUbV0E2UW6iT5cc6ePQi93AHu/S+NfyCK hG7QELpdlCBYKoCnLqyBfdTOH91AKRWmi78WQfWor+No5p0FbHk3htf40ME9B5m1+Tfg MoMQ== X-Gm-Message-State: AOAM532ZUAJm/5OgaGWTATs4ybaiX3EO0yXp+aPX46DYC1S7Ciysoz6G 9FMxd8Coz4GzHonX4T5e6hNh4c69e3+ZdgfQKCjSZw== X-Received: by 2002:a81:5dd6:0:b0:2d6:3041:12e0 with SMTP id r205-20020a815dd6000000b002d6304112e0mr19479093ywb.331.1648359819570; Sat, 26 Mar 2022 22:43:39 -0700 (PDT) MIME-Version: 1.0 References: <20220327051853.57647-1-songmuchun@bytedance.com> <20220327051853.57647-2-songmuchun@bytedance.com> In-Reply-To: <20220327051853.57647-2-songmuchun@bytedance.com> From: Muchun Song Date: Sun, 27 Mar 2022 13:43:03 +0800 Message-ID: Subject: Re: [PATCH 2/2] mm: kfence: fix objcgs vector allocation To: Linus Torvalds , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin Cc: kasan-dev@googlegroups.com, Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 27, 2022 at 1:19 PM Muchun Song wrote: > > If the kfence object is allocated to be used for objects vector, then > this slot of the pool eventually being occupied permanently since > the vector is never freed. The solutions could be 1) freeing vector > when the kfence object is freed or 2) allocating all vectors statically. > Since the memory consumption of object vectors is low, it is better to > chose 2) to fix the issue and it is also can reduce overhead of vectors > allocating in the future. > > Fixes: d3fb45f370d9 ("mm, kfence: insert KFENCE hooks for SLAB") > Signed-off-by: Muchun Song Since it cannot be compiled successfully when !CONFIG_MEMCG (The following patch should be applied), I'll update this in the next version if anyone agrees with this change. Thanks. diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 9976b3f0d097..b5c4b62b5d2c 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -583,7 +583,9 @@ static bool __init kfence_init_pool(void) struct kfence_metadata *meta = &kfence_metadata[i]; /* Initialize metadata. */ +#ifdef CONFIG_MEMCG slab->memcg_data = (unsigned long)&meta->objcg | MEMCG_DATA_OBJCGS; +#endif INIT_LIST_HEAD(&meta->list); raw_spin_lock_init(&meta->lock); meta->state = KFENCE_OBJECT_UNUSED; @@ -940,7 +942,9 @@ void __kfence_free(void *addr) { struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); +#ifdef CONFIG_MEMCG KFENCE_WARN_ON(meta->objcg); +#endif /* * If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing * the object, as the object page may be recycled for other-typed diff --git a/mm/kfence/kfence.h b/mm/kfence/kfence.h index 6f0e1aece3f8..9a6c4b1b12a8 100644 --- a/mm/kfence/kfence.h +++ b/mm/kfence/kfence.h @@ -89,7 +89,9 @@ struct kfence_metadata { struct kfence_track free_track; /* For updating alloc_covered on frees. */ u32 alloc_stack_hash; +#ifdef CONFIG_MEMCG struct obj_cgroup *objcg; +#endif };