From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 9347C2DB7AE for ; Tue, 3 Feb 2026 15:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770133115; cv=none; b=DDLs49PTcKjtX/PzQaybbAem/eRJmPGjegUzGZO7DcD8ru/KCfZ03ASV8RuqfkkOA0lVulVCAUg2w0fGt4yms8j6Z9aaj+DnLvJi8SgSCSjRkYK1va1C34mCAvwkevQpdUaoc6MpdQM5mNkueQP+kFaK9pZ84lbes8T/HLobuR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770133115; c=relaxed/simple; bh=9dkOL9WCsK0uU5ILftSBFEZ1TlCgDoh6q/l5wlxwtlQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u2iGYq4VPbhsGqtQ02cZdi1NM/sx7KKI/00sndWXxNnzfhxKOV+AritwXLe4sKI1Ev7r1Z+LNc9oH837q5JJgoviai1iZNwlsZOB2k2ko3KgV2BJApspPlczzi30ixNOWo1dIosX7g+usqm9Rb+nZt3LehcQ0GcsyM11n3tJ6+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JKtjImyk; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JKtjImyk" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4801bceb317so53373855e9.1 for ; Tue, 03 Feb 2026 07:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770133112; x=1770737912; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5h76k9K3qFcgY90MofiTdAnuRfQxtWeUNCZad/0hgRE=; b=JKtjImykoutBQTj5Xfd5HwCS5KRPipLcJWpo7gxagdp95+EuGgiGDF4emQCMqhhPKi JEvKl19o8P14+q+BqB8kiyz5wFB6qsUMbLBbBN9Wmk/yM7I7H5YGP5oElTym9X9FCqc8 7NtZSO/qXdmYO5U+OPGeAi0tT0xXaRSBmRtvXlNrLQYjcZ02Ykpbdfz1eri5g4McI7x2 h2X0m0D1ZbIvD1aLRZU79Lpyh7XgT6iJ4uhx2kCmtiHlB3XwdEfU0Ertv28lhmHysC++ RsxylX1h2U4FnvoUJXh1UddTvupGqcp2jD72wZxX5S9TcD6NGZ9gM7PXl/hcuXtz7/5O 5s3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770133112; x=1770737912; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5h76k9K3qFcgY90MofiTdAnuRfQxtWeUNCZad/0hgRE=; b=C7l2MI22sLacLBhkylTzl6m3Ia75po2qv0sLZ3jOJ+T2dhlyurt1GtsNSIsfqp4B67 PSDv0dR6QqobLGvVDFfyMcrKMWv5TPY6fpQ38x2MfFrhEbszk7cqHJ4Sq1nVb7ijnOvR 81+PWC9LtFWP6Zn0TtrfY53ZyvGJMYS/Z/nvcUcsuwsMbcULGMO619B0NZ8QB4bfnNOZ dMxsf57dGnfQ3gDSDKNquEl1yNkJMU6sKfTXtpncEQ7EMY6QJuDcJ6sEZHJW4w5Qk7Ql DNJMTcyIJ/bDAApak8L3vsqd4k06VSSxCW7UTPoBReROAyChSwtRpzMlJsnsZ01ncSuC gdSw== X-Forwarded-Encrypted: i=1; AJvYcCXM1jFyymPNF5QyhSw6W3Rsic+FYtWc9SuXaE4HDT/hozWi7sT6Iv+ebyP8U2ljSQkNh3EXNpbFzreJAJY=@vger.kernel.org X-Gm-Message-State: AOJu0YwmBs6rQSPvcpicf9+1PvTwrivK4ISbiHkrTlnjukTtxGzpQd6I KIJDMJLhhYpW3pjs7TROaStVmxh5FKKV7SZeH0wSWWAcRZFd+qkJ6Gh8lzqzu8hjci+pHLrRoBW X3g4zpyGUghbFFEdRzw== X-Received: from wmby20.prod.google.com ([2002:a05:600c:c054:b0:480:68eb:6c8d]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c16d:b0:47e:e87b:af8 with SMTP id 5b1f17b1804b1-4830e9667d2mr583395e9.21.1770133112080; Tue, 03 Feb 2026 07:38:32 -0800 (PST) Date: Tue, 3 Feb 2026 15:38:31 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260131154016.270385-1-shivamklr@cock.li> <20260131154016.270385-2-shivamklr@cock.li> Message-ID: Subject: Re: [PATCH v2 1/3] rust: alloc: Add shrink_to and shrink_to_fit methods to Vec From: Alice Ryhl To: Danilo Krummrich Cc: Shivam Kalra , cmllamas@google.com, gregkh@linuxfoundation.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, vbabka@suse.cz, Liam.Howlett@oracle.com, urezki@gmail.com Content-Type: text/plain; charset="utf-8" On Tue, Feb 03, 2026 at 04:19:14PM +0100, Danilo Krummrich wrote: > On Sat Jan 31, 2026 at 4:40 PM CET, Shivam Kalra wrote: > > This implementation guarantees shrinking (unless already optimal), > > because the kernel allocators don't support in-place shrinking, > > a new allocation is always made. > > I'm not sure we should go in this direction. There is a reason why krealloc() > does not migrate memory between kmalloc buckets, i.e. the cost of migration vs. > memory saving. > > For Vmalloc buffers the story is a bit different though. When I wrote vrealloc() > I left some TODO comments [1][2]. > > (1) If a smaller buffer is requested we can shrink the vm_area, i.e. unmap and > free unused pages. > > (2) If a bigger buffer is requested we can grow the vm_area, i.e. allocate and > map additional pages. (At least as long as we have enough space in the > virtual address space.) > > So, I think we should just use A::realloc(), leave the rest to the underlying > specific realloc() implementations and address the TODOs in vrealloc() if > necessary. > > [1] https://elixir.bootlin.com/linux/v6.18.6/source/mm/vmalloc.c#L4162 > [2] https://elixir.bootlin.com/linux/v6.18.6/source/mm/vmalloc.c#L4192 If kvrealloc() does the right thing, then let's use it. Alice