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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92D80C77B73 for ; Mon, 22 May 2023 07:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232615AbjEVHfM (ORCPT ); Mon, 22 May 2023 03:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbjEVHfH (ORCPT ); Mon, 22 May 2023 03:35:07 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F451A8; Mon, 22 May 2023 00:35:05 -0700 (PDT) Received: from dggpemm500016.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QPpyN5MqDz18LZm; Mon, 22 May 2023 15:30:36 +0800 (CST) Received: from [10.67.110.48] (10.67.110.48) by dggpemm500016.china.huawei.com (7.185.36.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 22 May 2023 15:35:03 +0800 Message-ID: <19707cc6-fa5e-9835-f709-bc8568e4c9cd@huawei.com> Date: Mon, 22 May 2023 15:35:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH RFC v2] Randomized slab caches for kmalloc() Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com> CC: , , , Alexander Lobakin , , Wang Weiyang , Xiu Jianfeng , Vlastimil Babka , Christoph Lameter , David Rientjes , Roman Gushchin , Joonsoo Kim , Andrew Morton , Pekka Enberg , Kees Cook , Paul Moore , James Morris , "Serge E. Hallyn" , "Gustavo A. R. Silva" , "GONG, Ruiqi" References: <20230508075507.1720950-1-gongruiqi1@huawei.com> <5f5a858a-7017-5424-0fa0-db3b79e5d95e@huawei.com> From: Gong Ruiqi In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.48] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500016.china.huawei.com (7.185.36.25) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/05/17 6:35, Hyeonggon Yoo wrote: > [Resending this email after noticing I did not reply-to-all] > > On Fri, May 12, 2023 at 7:11 PM Gong Ruiqi wrote: >> [...] > >>>> +#ifdef CONFIG_RANDOM_KMALLOC_CACHES >>>> +# define SLAB_RANDOMSLAB ((slab_flags_t __force)0x01000000U) >>>> +#else >>>> +# define SLAB_RANDOMSLAB 0 >>>> +#endif > > There is already the SLAB_KMALLOC flag that indicates if a cache is a > kmalloc cache. I think that would be enough for preventing merging > kmalloc caches? After digging into the code of slab merging (e.g. slab_unmergeable(), find_mergeable(), SLAB_NEVER_MERGE, SLAB_MERGE_SAME etc), I haven't found an existing mechanism that prevents normal kmalloc caches with SLAB_KMALLOC from being merged with other slab caches. Maybe I missed something? While SLAB_RANDOMSLAB, unlike SLAB_KMALLOC, is added into SLAB_NEVER_MERGE, which explicitly indicates the no-merge policy.