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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFEAAC6FD1D for ; Tue, 14 Mar 2023 13:06:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EB5F6B0072; Tue, 14 Mar 2023 09:06:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49C588E0002; Tue, 14 Mar 2023 09:06:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3644D8E0001; Tue, 14 Mar 2023 09:06:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2762C6B0072 for ; Tue, 14 Mar 2023 09:06:50 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E4D181C67E3 for ; Tue, 14 Mar 2023 13:06:49 +0000 (UTC) X-FDA: 80567528538.29.21ADE3D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 2BDDE160039 for ; Tue, 14 Mar 2023 13:06:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="IjN16Nr/"; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678799207; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CyA6aX3LWF3S0LPq2B7KDIy9+tGtAg2Aqm4KsZBo8Hk=; b=Czx7Zqr0ltXqK5mKYUAfDkimFXmI0kesFaOBfyAAonN3aSNOZKYXWIGeAFQd3XiG/ekRXs Dnzw7JusD61NYFfUcA4Kf961ACWRJfawJJXm2tSj4+xQAtKiQufs/Rik+3lEfnv/raBLaI WJ9RbwwfDged9RWjk7ZpQ1PEtR1CWKw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="IjN16Nr/"; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678799207; a=rsa-sha256; cv=none; b=IwEo6oJiygH19PszfNjzbB+mLNZoN6ewOqeKSvyhCxzH3CmGUW4RVuKgDj6rgh0G732KSN 2Xexh7emo9gwpGoRaFKLJQZanAGSS7+Qtw36SiqeNEodLJkaEB8Voi+bMbAO/wSxT2KfyX KiyLhdorFpSuiAVmySRp88Uu6QVhYyo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=CyA6aX3LWF3S0LPq2B7KDIy9+tGtAg2Aqm4KsZBo8Hk=; b=IjN16Nr/j4WtYjF4MKbc6hAh/E r1bkPgb4/YGLPSO+ZHwaIHrCj6AYOllQjfgCiURKiKyBq/kCQXyJstxnIGpP0Vp2YeHco2JAHOzMx fSXXBplsiWXjS1M9T8XQcAljcKIllA2fXBIzNlruoPlmC8WzJ+VS9zhbX79ayTGui8Q4CwDm0kTmu Jhcre75eo3MY1gtiyS20cX/f7Sdv32876LgD2fKZ45TJf/GjH/ZYl4xy5PxXk9sg9M46M1hQWZq7B X+GRLXQN4L6C2qX9h4igSgw7kW9G0VopqYa1C22FUfitHAIXtVRczeFUkUdA8DPHR+A9X2P7rg78c pS15A3pw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pc4MQ-00CvDN-HJ; Tue, 14 Mar 2023 13:06:38 +0000 Date: Tue, 14 Mar 2023 13:06:38 +0000 From: Matthew Wilcox To: Vlastimil Babka Cc: lsf-pc@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, bpf@vger.kernel.org, linux-xfs@vger.kernel.org, David Rientjes , Christoph Lameter , Pekka Enberg , Joonsoo Kim , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin Subject: Re: [LSF/MM/BPF TOPIC] SLOB+SLAB allocators removal and future SLUB improvements Message-ID: References: <4b9fc9c6-b48c-198f-5f80-811a44737e5f@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4b9fc9c6-b48c-198f-5f80-811a44737e5f@suse.cz> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2BDDE160039 X-Stat-Signature: 57u7jfy9yreh51cpw7nhma7bwmhatbd3 X-HE-Tag: 1678799206-502040 X-HE-Meta: U2FsdGVkX1+xo+xWpqE+patXpI0FzktBh9kR/Pc3TQXAB/2JG2Ka3fOneCBT9da9yN1rXCrck+/QDpj2jXPuMYnKiiqWDBLMkcPW8An0GPcCqF5iqPHZw7BkcPop8P8AuDAlJBDeTMMYL3EplXIFH6U6KEHI7VUN+jBEAjn9QNCxWhd7EZBya9UKh/R9hPOo9N98vdPZ3ymTjuDkIr4qnXF11Xny7bklNuuN29VolAIT8M1oCxhbrqRLyTkTKbQvQXhQNGkMpkFHsM6TR9QOhQU6nNGioHER2ZAgqWAkNT9psDeVF5EthlvtUSHIwQf6o+yweaQiCY1sqMqMQv8IQ/FtQpuuuCk/6tqWGjfTa2QQ9IsQtmU7bPn7lDGzQa59F9m7PHtUlbqNsJWO3kLQIDcCvEMunArN2hy9RA5Clz7FhI8z1WQ1xjitBWEf7gnxqGsxBil+rPIRXrHMe2Q9FxiJgXQuJ9RPxS722+MfN/jxzAhYdjZvpmMEjhb3wTXKBHj073smC1jljnS1AOxY2pvQZ66BVbjgScFaiqMnivAARrTmXQU4IU4XTod5hKzXYF3qsHGPXy7gn3NlBF6NoaKz22EP7po1jTL9JP63ieD0RBJKKlGKR0FwbhzTJcVM8ztnwmb9Sey91Mxo/1lzhyhEFIzRiSZIaTlb+F+06t6RxNCTPP7oLbGg4b+gVcy3bcudODX/C9Ey+AmWvHUK8icLWmTmdjNwmhao6jCq702PHrUz62jSetHb0X1RMaOIdE+HXAM/McTmS5Iz1mQxIzdDduEX9XkY38WjIck/aHfOZYsYbC8W33phObmHAcp0in6yJo84JXvymNkav1pB/l/RCnzdIzUP6kSZ8VT0LqhcjU14PSLARK3W5tpAL1xEZLF0Ienov33KnXCvKmh6ZVp4YsLi+xGye0YaBdrKTeWL/dElA4QXxYJ6FA7hjx6YIowVHT2LIlx6mCjK5jN Kqnpgwtc eZL2Q0s2HJVHZoDBpOBs2Roq8xav55P1ZpocGH6nicvp+1SF62jMnjltdx3DIt9fZFvxORrcw1ptMo7w7Dugf1XwHsIplTh/sPsmNm/rZA01CKYV1aH9r8WZBDwi9/ZMlbUFI0SxrbjwvSLP5Td2sPVqHDE3vXYKvty77cyWxCDypYyYRmPgpwX+qb87i/e8M1l0qf+5w9FWLxs2GZplKOQ4MCbpLPj8A0n+m 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 Tue, Mar 14, 2023 at 09:05:13AM +0100, Vlastimil Babka wrote: > The immediate benefit of that is that we can allow kfree() (and kfree_rcu()) > to free objects from kmem_cache_alloc() - something that IIRC at least xfs > people wanted in the past, and SLOB was incompatible with that. > > For SLAB removal I haven't yet heard any objections (but also didn't > deprecate it yet) but if there are any users due to particular workloads > doing better with SLAB than SLUB, we can discuss why those would regress and > what can be done about that in SLUB. > > Once we have just one slab allocator in the kernel, we can take a closer > look at what the users are missing from it that forces them to create own > allocators (e.g. BPF), and could be considered to be added as a generic > implementation to SLUB. With kfree() now working on kmem_cache_alloc(), I'd like to re-propose the introduction of a generic free() function which can free any allocated object. It starts out looking a lot like kvfree(), but can be enhanced to cover other things ... here's a version I did from 2018 before giving up on it when I realised slob made it impossible: +/** + * free() - Free memory + * @ptr: Pointer to memory + * + * This function can free almost any type of memory. It can safely be + * called on: + * * NULL pointers. + * * Pointers to read-only data (will do nothing). + * * Pointers to memory allocated from kmalloc(). + * * Pointers to memory allocated from kmem_cache_alloc(). + * * Pointers to memory allocated from vmalloc(). + * * Pointers to memory allocated from alloc_percpu(). + * * Pointers to memory allocated from __get_free_pages(). + * * Pointers to memory allocated from page_frag_alloc(). + * + * It cannot free memory allocated by dma_pool_alloc() or dma_alloc_coherent(). + */ +void free(const void *ptr) +{ + struct page *page; + + if (unlikely(ZERO_OR_NULL_PTR(ptr))) + return; + if (is_kernel_rodata((unsigned long)ptr)) + return; + + page = virt_to_head_page(ptr); + if (likely(PageSlab(page))) + return kmem_cache_free(page->slab_cache, (void *)ptr); + + if (is_vmalloc_addr(ptr)) + return vfree(ptr); + if (is_kernel_percpu_address((unsigned long)ptr)) + free_percpu((void __percpu *)ptr); + if (put_page_testzero(page)) + __put_page(page); +} +EXPORT_SYMBOL(free); Looking at it now, I'd also include a test for stack memory (and do nothing if it is) There are some prep patches that I'm not including here to clear out the use of 'free' as a function name (some conflicting identifiers named 'free') and a fun one to set a SLAB_PAGE_DTOR on compound pages.