From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f181.google.com (mail-il1-f181.google.com [209.85.166.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7FDE20E711 for ; Thu, 23 Jan 2025 15:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737644983; cv=none; b=kjrSdTZLTkr9lpmmMgvHlfEZwYtLIyxCA+y283XSkaJgXrPBmhCNJrhDdMh2l6UHUjLWWVG4ne48mPew8Fbw1Ymg5Ugj13zikrAQtAWDhHxL2WElmvOhiXLJ0eGxk3N3ytNoCFVF7VHWDGz7d3G5RnVwAGM0us3jX9ylPccNjj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737644983; c=relaxed/simple; bh=/SgpWjpy/v2XNWP1pe8j1mJKYJ7CFVUQXoIRkq6L5IE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EGcHUj/LhTvOMbtOtL1/ycLJSeHFtsjWD6Sjw76fVwQmynqJsT4AARfGT8wGNhn9YNLXzzsQ/jlU/mc+nipsQfth4DMPQkUepQBL6lH1iCldTANS+5OVnKxj8BMW7nQ29fqQlRR9zhneZntvRJt+YqcTSKlYSMoUAAmTxDLxhzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=FbdB+SKz; arc=none smtp.client-ip=209.85.166.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="FbdB+SKz" Received: by mail-il1-f181.google.com with SMTP id e9e14a558f8ab-3ce8a4e95f3so8396645ab.2 for ; Thu, 23 Jan 2025 07:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1737644979; x=1738249779; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xqnXltgy2/q3fVrb00LkipaaFrAlaQGFQURxSOjsJf4=; b=FbdB+SKznqvgRfeG5aKqbxQbKVNE7WEJsHmV5LAerqK3DZ7kj+CvCGGeoTeGgZARhg heA3VKSP34mGllaRSSjs4GbZeqFUI4RCY3/34TagAxxa7Rl00HYd8+27ydLLSPZ9iqRE 1vP9cw53rITJefUAVtBrklXbeJO2GiAD5YzMI//jsXOt7SiPRZAyYwIGWUmJ99a2rRaK vkeub/BjhVzn3JZVtKJw9Di36cZeUoc6PEO168NQZLwoPExgmiIPHdRn7C5dq1IT9DrK L8VOblBiJFvZCGYaDOpDph8OVcvXifdb0ao2PW00DhOwbslEarG7EAYO2gpQqFCGUgT9 DRyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737644979; x=1738249779; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xqnXltgy2/q3fVrb00LkipaaFrAlaQGFQURxSOjsJf4=; b=vBX6APj7uc2PMoqwGuBwSAqN8+nXsUoQ0mrnwqk3j2cDWJ8aJjQPLncA0T/6ULWZ5C 2G9hA2WZVYvEQa87I4Du0M5byouwoPYO/DZkxv3oUhsakchaVjCXvABiGkTIN4MCPpQq CKpWElZrAkZQN10ALlI5cMvoyXtUS9ubpOaPnAHTvi8pARdazLqabE9ZL+Yzmz0GRTR3 N2C3Jflr4YP8+qYmN/GLzARKsMCkQDQmfQjRW5WW7QmAeNzm4y9jZbCGaIahe0FqW2Up xtvLdWXfJJ9bhuhTmyAI6fj/VktuII1e/4ou/AhH0Yuu2kRKXpMRnHG6Yhx7I48hldi9 DZsg== X-Forwarded-Encrypted: i=1; AJvYcCWAAH05jyctSr4pnVvUOIYTyPRSYhOMfdofgykK3ReQsfNJCCpvVdXnIsaR7VnXZrSn+XjbvFZDUw==@vger.kernel.org X-Gm-Message-State: AOJu0YzeklMdxS4D6ZWlCb/cTTYak9VfuW0W+VsyN9ZN/BXbrmY7/YgT k1iPlJRgNqO2GekoCMM4dS+ZoiizEFvae9UpQZvnyEqtG1XRiIyOL+vSEL28Cto= X-Gm-Gg: ASbGnctwSLcU7yNOHCZGFlqHTpstMPAV3WuiH0WZnG0sYEq0j3d0BAnthT8TkIT91H/ rikPFXjTaz+21+jb2yOFKkYFn5GA+Tc6oLRbYbtHbV58egqOrcKV3ty1biYeTgkThsT5MkJIJx/ BXl/tXPrncp+NBshhCC5/+FTx0zesuGL5/m4tDwcKl3uP5oLOEi7sdV4wQO7Mm5wBoPXvUPzexD mw/WZ1GGklSjfyVyZ6EbsvagFdhqGQ8lgsqEnuyODlBUrX/Huua1B1hFmIFYw2JBWg5YrbayheA X-Google-Smtp-Source: AGHT+IEquHdbnktMOgDKiUOpMxhKzsQ2mPmEVWVMMHiat5rTPULiuYO4ki0A3+cm6nTfvcjJMBVtpQ== X-Received: by 2002:a92:c26d:0:b0:3ce:46e2:42a7 with SMTP id e9e14a558f8ab-3cf74410c4fmr199868195ab.9.1737644979626; Thu, 23 Jan 2025 07:09:39 -0800 (PST) Received: from [192.168.1.116] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3cfc59d1317sm1023105ab.37.2025.01.23.07.09.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 07:09:38 -0800 (PST) Message-ID: <0d886adb-81d7-4f09-b4e0-07dc7c753363@kernel.dk> Date: Thu, 23 Jan 2025 08:09:38 -0700 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] io_uring: get rid of alloc cache init_once handling To: Pavel Begunkov , io-uring@vger.kernel.org Cc: krisman@suse.de References: <20250123142301.409846-1-axboe@kernel.dk> <20250123142301.409846-3-axboe@kernel.dk> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/23/25 8:05 AM, Pavel Begunkov wrote: > On 1/23/25 14:55, Jens Axboe wrote: >> On 1/23/25 7:47 AM, Pavel Begunkov wrote: >>> On 1/23/25 14:27, Pavel Begunkov wrote: >>>> On 1/23/25 14:21, Jens Axboe wrote: >>>>> init_once is called when an object doesn't come from the cache, and >>>>> hence needs initial clearing of certain members. While the whole >>>>> struct could get cleared by memset() in that case, a few of the cache >>>>> members are large enough that this may cause unnecessary overhead if >>>>> the caches used aren't large enough to satisfy the workload. For those >>>>> cases, some churn of kmalloc+kfree is to be expected. >>>>> >>>>> Ensure that the 3 users that need clearing put the members they need >>>>> cleared at the start of the struct, and place an empty placeholder >>>>> 'init' member so that the cache initialization knows how much to >>>>> clear. >>>>> >>>>> Signed-off-by: Jens Axboe >>>>> --- >>>>> include/linux/io_uring/cmd.h | 3 ++- >>>>> include/linux/io_uring_types.h | 3 ++- >>>>> io_uring/alloc_cache.h | 30 +++++++++++++++++++++--------- >>>>> io_uring/futex.c | 4 ++-- >>>>> io_uring/io_uring.c | 13 ++++++++----- >>>>> io_uring/io_uring.h | 5 ++--- >>>>> io_uring/net.c | 11 +---------- >>>>> io_uring/net.h | 7 +++++-- >>>>> io_uring/poll.c | 2 +- >>>>> io_uring/rw.c | 10 +--------- >>>>> io_uring/rw.h | 5 ++++- >>>>> io_uring/uring_cmd.c | 10 +--------- >>>>> 12 files changed, 50 insertions(+), 53 deletions(-) >>>>> >>>>> diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h >>>>> index a3ce553413de..8d7746d9fd23 100644 >>>>> --- a/include/linux/io_uring/cmd.h >>>>> +++ b/include/linux/io_uring/cmd.h >>>>> @@ -19,8 +19,9 @@ struct io_uring_cmd { >>>>> }; >>>>> struct io_uring_cmd_data { >>>>> - struct io_uring_sqe sqes[2]; >>>>> void *op_data; >>>>> + int init[0]; >>>> >>>> What do you think about using struct_group instead? >>> >>> And why do we care not clearing it all on initial alloc? If that's >>> because of kasan, we can disable it until ("kasan, mempool: don't >>> store free stacktrace in io_alloc_cache objects") lands. >> >> Not sure I follow - on initial alloc they do need clearing, that's when >> they need clearing. If they are coming from the cache, the state should >> be consistent. > > If we forget about kasan, ->init_clear is only really used right > after allocation(). > > + obj = kmalloc(cache->elem_size, gfp); > + if (obj && cache->init_clear) > + memset(obj, 0, cache->init_clear); > > Why not kzalloc() it? We obviously could, but rw/net is 2-300b in size, and most of it we don't need to clear. Yes this is only for the "slower" path of hitting alloc rather than the cache, but it's not a given at all that any workload will fit within the cache, unfortunately. That's quite a lot of memset for those cases. But maybe I'm overdoing it and we just kzalloc() it. It'd obviously be a lot simpler. -- Jens Axboe