From patchwork Tue Jul 30 18:49:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747781 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 9FE51C52D1D for ; Tue, 30 Jul 2024 18:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33B936B0089; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECFD6B008A; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B42B6B008C; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F3C476B0089 for ; Tue, 30 Jul 2024 14:51:02 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 67138160441 for ; Tue, 30 Jul 2024 18:51:02 +0000 (UTC) X-FDA: 82397311164.21.23F525B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id C277AA000D for ; Tue, 30 Jul 2024 18:51:00 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AOgF+9qB; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722365399; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ew056S4HBySpe0eFO22xy2n+QYBibltBTyZ8JZz+eZg=; b=s8XWLuHQDZNPtd8tMR5MkWdPERMtTMvdbGteNbtaHlrh8Ufk+ZEnocZp3GHnSBmvpaV9pJ /9K/LSKwFId3vHsko+b3bAzRvdzXlNL2r3E/EunHBpQeH60UdJ1UYEDHl/fh3T/vbKXIHQ 9KBviuAL7OCbUNNAEzadjfkXfrZ2o24= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722365399; a=rsa-sha256; cv=none; b=Iqr7apGc3lmnzBrWW4D1i6OcwT5gkFMrIjrNRTajxmOOoL+cKiEkX1zRHX/1a0M+JNc072 wEe6wP4FzWjyNfi4lAm1qf9pCf1eRAmsyHmNFzSrg4m3Nbc6DMa6MpI0DkIE4E4p8YEYpD HnDeBduBca4XlB/qKqyPxmyyB3tboGc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AOgF+9qB; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E2D0662039; Tue, 30 Jul 2024 18:50:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C974BC4AF0A; Tue, 30 Jul 2024 18:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722365459; bh=pqmv76F1WcFutmWjI3wHquYQ2ukivLAaozJiVBwDm7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOgF+9qBGFqKxJ8z4A6PgTFI5uYlUNekNx9SPS/SqWo35zBpPaiN87qT3ktO1zdzc QMYeHnTcqQxbUhysQGYmIJuey8q1zASAdVZHZpDbQ4KXgeW8lS5IAeIzAW5X/JpYj0 b7QuzOIKrpAu8L5rZHQzMcFcCt7JqP852MttQgYl1iRORwFDUhmGoLvRzpOjR6etsA XrX9PPOBBOMCeKCm517hKCADyt6UPMZwI+v7THiGeG8m4+I1h7XwuwyfVv6zs0JqLW 6pQZCszlfzoYzSgVnhz4MwQ1sQJINCMAjFtLcTETveHdGHdo7+v/nb1ukBSVJrfJKt EpnCk755lK3gA== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, vbabka@suse.cz Cc: mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 2/4] mm: vrealloc: consider spare memory for __GFP_ZERO Date: Tue, 30 Jul 2024 20:49:42 +0200 Message-ID: <20240730185049.6244-3-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730185049.6244-1-dakr@kernel.org> References: <20240730185049.6244-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C277AA000D X-Stat-Signature: 3u7wn7nefasrxmmy3yaa6kuzskou5tkz X-Rspam-User: X-HE-Tag: 1722365460-233280 X-HE-Meta: U2FsdGVkX1+NbQBgXwXZXWfLIIHhJ4VSV3LHRhZD+x4RtNMJbuqIxU+uqp2Idt7O5Y5P/Wj1eM6qnYqVL5hERoLkCsYuMxgizWbk4n5AiiuKEPiPGK/qUbqFec2H90dTjqGox6e301d4MeetKBlTmzaMSfaqTz4TaWhtHibQ0QY+lGgxDHud2U6oLd0VoVbUBYBPSVicEZneIcB2XkTmzgl/Iq12Oc3ocFJuaqHKuNWgdJmMhvvX7yKswbJ+s4AR+MRdR3PhBG9VPgTG/EQG7GgX6joL33TTv4uuzItdexOEGNqNpzhwQVK+OwaWaeJGT1T/zX1jQJNCKzSFfZ4TfmmXc4vpmm9KV+YwHLlIEEjKqzJooPib/RBdKNLIDdvDdbr+2H8NysMCjodMaHfKFBLc5rCXda6CLR3Jgt+GfLUzSShKu23RmcJgVX20hUOsulrfzzGKcGjZ26c5Ai+/ubwuuIiRXTVRWsgyqH9+sv4bmVaLwd8Miuk6IcojE5ESnTj28+a8rOn8NV/+mYXl8tddzAM1VfDV2rHBnOuU4jRw/8jz0jtIchdXaxpIAGsGZWLYQaXEv5pOuLJaaG9Mx4HjpVTLVD8DCJwTLMlk2wjtk/eBAVV1CyHQEtjI0ENPI1b8MdgKffMfJhaxjoLBG5P4SK5hYptpjPEJywtgDEx1kZbx0pybLPhMUmQjAzUycCMQVg6wjAk6GOAKA9/lo5XpNcXrm+n+okSYe8Gdzebutbdn6lZcX5Q7FdPVYVofIufn2NFfhHAV7eORyCrFcjbh6kynxsHczEln6Q5Kw4fv8wyFhjJ6jUOL+6X7wC8BRb26Dleo6RN/+V1Lupzcd6DQGUDNoHQBijTeTpscKoO2Vvd5Ea0AlSfwoVt3PaWXMnElpKF6e7hythTVcdUWfo8OMk6+P87aZeYg0mXePUMxIFpBKva+DL6dqGU89nC2f6gRa9SV590PxPrNmub q8z/IEc/ 5StFHACZY5EuJhr7tkucycAZOoPDhbN0bBO3m87a952e1oXYY30P8VCTe5MJfCE9xKBvldA1QJ4uuZlltOeUisoQVnYqHcap/L+dxewXKuTRwmyDzFAlpUAR++nkNEMUVQAx4z4GrgyH+qIzKT8PPnzOF0DmOE1ZIy2xdgObs/5UShZgfY/Odjg16e6s2KpvGHvqLvKC8bOoszw97aXzLZAm5x1jvPKrZu6Gb16RS4yMFKTkkx9k2lPdUniIC2x8wSNgaEn2wU2l3Y+S1s4SyV2atsstZsqNUxClY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000223, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Zero spare memory when shrinking a buffer with __GFP_ZERO. Fixes: 1f39ee9615a8 ("mm: vmalloc: implement vrealloc()") Signed-off-by: Danilo Krummrich --- mm/vmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 2a6d4ce57b73..6a2fef6378e4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4077,12 +4077,15 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) old_size = get_vm_area_size(vm); } + /* + * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What + * would be a good heuristic for when to shrink the vm_area? + */ if (size <= old_size) { - /* - * TODO: Shrink the vm_area, i.e. unmap and free unused pages. - * What would be a good heuristic for when to shrink the - * vm_area? - */ + /* Zero out spare memory. */ + if (want_init_on_alloc(flags)) + memset((void *)p + size, 0, old_size - size); + return (void *)p; }