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 A1FFBC2BBCA for ; Fri, 28 Jun 2024 09:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 084C26B00AA; Fri, 28 Jun 2024 05:17:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 035236B00AC; Fri, 28 Jun 2024 05:17:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9016B00AD; Fri, 28 Jun 2024 05:17:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE7BB6B00AA for ; Fri, 28 Jun 2024 05:17:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6332916193E for ; Fri, 28 Jun 2024 09:17:20 +0000 (UTC) X-FDA: 82279743840.04.2EFAB60 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf28.hostedemail.com (Postfix) with ESMTP id EFFC6C0013 for ; Fri, 28 Jun 2024 09:17:17 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBIXEal4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=O9bOmpwC; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBIXEal4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=O9bOmpwC; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719566229; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HPSHi62iPTx8+bcpaYNNSvFsA8tFGLe7dcFFpmR9SXg=; b=KF5oEz4PHqyxbCLNgmYeyBNvmT0rs9ECMOO+qGar1soYzHEUSxH0gmltG4cAlrARcRcExW 8Cas+9MDbS58B+d+vc19cN+/Pg0wE7XgqOD+TA1d3HMkcbi+xSzodKPDyI1oyf9RWeFuOI 3sb/yggWeO2QOUOatzAeTfAysqzE+h0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBIXEal4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=O9bOmpwC; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBIXEal4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=O9bOmpwC; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719566229; a=rsa-sha256; cv=none; b=aUOGZge1Igh58R3cFKVm/FtsRIgpi6eyPuSzlIOqq5fU/wkeW3FSnHbDK6PJL/izKy8Smf mjVcmWeVd5iguvWUX1+Fy8+Ax6eTm4Dw1iTXbXDyKJBYWeSALCXLfKSoxP7FT1SEYDh7j7 pSBAPx2Od7O0Uq08j2oq7DfK7URKFmQ= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 586771FCF3; Fri, 28 Jun 2024 09:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719566236; h=from:from:reply-to: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:autocrypt:autocrypt; bh=HPSHi62iPTx8+bcpaYNNSvFsA8tFGLe7dcFFpmR9SXg=; b=BBIXEal4J/XIOdojlnmLuvCWSPm05vaBiEdlESdarzm5XHO5Z4VzjBNtlMRZz4Iaafv25r ytmROKqhfyHYNE6cwy6gfnnH1LzZtix9A5PlS4rXczVmWLrPL4lVgk+usBhbbw3e4GbCr2 lsLsrgeIn9n83utj7c4Q4k/G8ZU4N6Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719566236; h=from:from:reply-to: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:autocrypt:autocrypt; bh=HPSHi62iPTx8+bcpaYNNSvFsA8tFGLe7dcFFpmR9SXg=; b=O9bOmpwCE5KW3Un9+gNnNcrn5EtdNWnQ1ZmlPIzwdDacoyav/pE14AI95LHbxr1vghCqsS 4aRp5sZ1pj0INTAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719566236; h=from:from:reply-to: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:autocrypt:autocrypt; bh=HPSHi62iPTx8+bcpaYNNSvFsA8tFGLe7dcFFpmR9SXg=; b=BBIXEal4J/XIOdojlnmLuvCWSPm05vaBiEdlESdarzm5XHO5Z4VzjBNtlMRZz4Iaafv25r ytmROKqhfyHYNE6cwy6gfnnH1LzZtix9A5PlS4rXczVmWLrPL4lVgk+usBhbbw3e4GbCr2 lsLsrgeIn9n83utj7c4Q4k/G8ZU4N6Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719566236; h=from:from:reply-to: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:autocrypt:autocrypt; bh=HPSHi62iPTx8+bcpaYNNSvFsA8tFGLe7dcFFpmR9SXg=; b=O9bOmpwCE5KW3Un9+gNnNcrn5EtdNWnQ1ZmlPIzwdDacoyav/pE14AI95LHbxr1vghCqsS 4aRp5sZ1pj0INTAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 26F2F13A9A; Fri, 28 Jun 2024 09:17:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5kYmCZx/fmYYMQAAD6G6ig (envelope-from ); Fri, 28 Jun 2024 09:17:16 +0000 Message-ID: Date: Fri, 28 Jun 2024 11:17:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/6] mm/slab: Introduce kmem_buckets_create() and family Content-Language: en-US To: Alice Ryhl Cc: Boqun Feng , Kees Cook , "GONG, Ruiqi" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , jvoisin , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Jann Horn , Matteo Rizzo , Thomas Graf , Herbert Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, netdev@vger.kernel.org, rust-for-linux@vger.kernel.org References: <20240619192131.do.115-kees@kernel.org> <20240619193357.1333772-4-kees@kernel.org> <202406201147.8152CECFF@keescook> <1917c5a5-62af-4017-8cd0-80446d9f35d3@suse.cz> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvHGTjKbJzC2xpFcY0DQbZzuwsIZ8OPJCc LM4S7mT25NE5kUTG/TKQCk922vRdGVMoLA7dIQrgXnRXtyT61sg8PG4wcfOnuWf8577aXP1x 6mzw3/jh3F+oSBHb/GcLC7mvWreJifUL2gEdssGfXhGWBo6zLS3qhgtwjay0Jl+kza1lo+Cv BB2T79D4WGdDuVa4eOrQ02TxqGN7G0Biz5ZLRSFzQSQwLn8fbwARAQABzSBWbGFzdGltaWwg QmFia2EgPHZiYWJrYUBzdXNlLmN6PsLBlAQTAQoAPgIbAwULCQgHAwUVCgkICwUWAgMBAAIe AQIXgBYhBKlA1DSZLC6OmRA9UCJPp+fMgqZkBQJkBREIBQkRadznAAoJECJPp+fMgqZkNxIQ ALZRqwdUGzqL2aeSavbum/VF/+td+nZfuH0xe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ZgAKCRAiT6fnzIKmZOJGEACOKABgo9wJXsbWhGWYO7mD 8R8mUyJHqbvaz+yTLnvRwfe/VwafFfDMx5GYVYzMY9TWpA8psFTKTUIIQmx2scYsRBUwm5VI EurRWKqENcDRjyo+ol59j0FViYysjQQeobXBDDE31t5SBg++veI6tXfpco/UiKEsDswL1WAr tEAZaruo7254TyH+gydURl2wJuzo/aZ7Y7PpqaODbYv727Dvm5eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Action: no action X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: EFFC6C0013 X-Stat-Signature: smb4wyzcb9uu35nqa3u867y1ehdfsdw4 X-HE-Tag: 1719566237-678255 X-HE-Meta: U2FsdGVkX1+C4H9KPjE1QD8xL21AeJplHytMGjPdB2qCSSJAjlkS6ABGWz40wixg/SbU0OAfAYhljBc2DiPJuKznKHlqzKcevxohp2rJbsklCNi94SOG2BelWMDyNPMXFqA9BoWqr6TzysdHFpRigzNUWktBDbuqV5TtCjyJwk+8Qje8jlm9gBokxFNYPxJq+aMkLFPeinT3pPa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56YTi17aC8nq3RGvNz6rTQRV3xCwykRQUJI8ptMwRO5OE377jvIXvBPUzRDNRofd0NzlTfAgR//QyA9rPQfz4OAkhOzl2aQz4dBgiUn/WxFbcupUsK3 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: List-Subscribe: List-Unsubscribe: On 6/28/24 11:06 AM, Alice Ryhl wrote: >> >> >> > >> > I took a quick look as what kmem_buckets is, and seems to me that align >> > doesn't make sense here (and probably not useful in Rust as well) >> > because a kmem_buckets is a set of kmem_caches, each has its own object >> > size, making them share the same alignment is probably not what you >> > want. But I could be missing something. >> >> How flexible do you need those alignments to be? Besides the power-of-two >> guarantees, we currently have only two odd sizes with 96 and 192. If those >> were guaranteed to be aligned 32 bytes, would that be sufficient? Also do >> you ever allocate anything smaller than 32 bytes then? >> >> To summarize, if Rust's requirements can be summarized by some rules and >> it's not completely ad-hoc per-allocation alignment requirement (or if it >> is, does it have an upper bound?) we could perhaps figure out the creation >> of rust-specific kmem_buckets to give it what's needed? > > Rust's allocator API can take any size and alignment as long as: > > 1. The alignment is a power of two. > 2. The size is non-zero. > 3. When you round up the size to the next multiple of the alignment, > then it must not overflow the signed type isize / ssize_t. > > What happens right now is that when Rust wants an allocation with a > higher alignment than ARCH_SLAB_MINALIGN, then it will increase size > until it becomes a power of two so that the power-of-two guarantee > gives a properly aligned allocation. So am I correct thinking that, if the cache of size 96 bytes guaranteed a 32byte alignment, and 192 bytes guaranteed 64byte alignment, and the rest of sizes with the already guaranteed power-of-two alignment, then on rust side you would only have to round up sizes to the next multiples of the alignemnt (rule 3 above) and that would be sufficient? Abstracting from the specific sizes of 96 and 192, the guarantee on kmalloc side would have to be - guarantee alignment to the largest power-of-two divisor of the size. Does that sound right? Then I think we could have some flag for kmem_buckets creation that would do the right thing. > Alice