From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (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 4CF5213B7A3 for ; Wed, 7 Jan 2026 01:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767750976; cv=none; b=caaBxFL/DVQtiXlM3cyQKwTO05RoUENBND2hfKYFJ2mfjGigT2a9p+44jnI+pEN1kv1fiS8DreMW0VYWDpWHYMvSu+ANlm20rydIV0qUQIxzO9ooHTgXW0w4IrdYu2h2+YxMJUbHfcbBKRjiR2WRTxNlRrHVN47i6sUIXMORbNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767750976; c=relaxed/simple; bh=i9CvjPjYzHpXfy395Iu7hC/J5xvVGAm9SRv099YEo+0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qSx+4fmoqvDda8+sVP7M2RKd2wP6gi1FncniLKJQYhfu/fMOTZvzPSmPeAcQqLoiKmEbhSU5J0cylELLvKehEuajNOK8pPkUJGHOxjhJn0QRc0wTIZvqzJnl8VO+h2ChtVH52MejJOfCFPdwCcOrqeNo9CNvLru7+8YE4xSJABw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E0ov6vfc; arc=none smtp.client-ip=74.125.82.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E0ov6vfc" Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-121b14d0089so1053917c88.0 for ; Tue, 06 Jan 2026 17:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767750974; x=1768355774; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=VlVS6vkxouJ7ZRpCqrQRqBlJbY8szTHfi0a3hUoZ0w0=; b=E0ov6vfcn4eFH2cc2//o7Wrm8t3qXZxQ0Wwpyb1VfNNJ/+mX5qvdOTPXVvaLx5LmuT oVhBIQjr8MFQ+UhPIaHWwTtjpfLcs+S3tCZpD98F1rA3cfYkclg4KmuYZs/E+ap4AeB1 g9EgOnA7tZ6Plz4ii5FRj3B5WIrdKyuNs5klPDIbj09lNO5tSdBWBX2v985HIBJYqRy0 AOtUd3+kMvZX/h46fxoRawbgVpo/wQ3O8Djn5OZcEJpNK4nHfUPQeHm+6IPU7exJ/UNc i4wSdee4Rbh3J6Y/ppiI2/DfzLodnhaSz6zexfYNUHJSr//qgJiSqDj2aCVmtHCDEFPZ ltSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767750974; x=1768355774; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VlVS6vkxouJ7ZRpCqrQRqBlJbY8szTHfi0a3hUoZ0w0=; b=KOe4y9UCRQaDbwu99rHvHso2J9ROVnoDb8YvL4fwc2r3xjYoPjo8srq+CgQY+c2NG8 OaTSdCI08/MM4an4bmNL7KwWPn1DTp9Vc0sITYJRT6CDDYJprYQQ255zRK466tGNazcw 0CCfuo/46Wc+qLaOiTdviNfhYCoaNJA7CKh3Uw3nHRXdLdJpDzUYqxp2lcwhelhqlECp f1ftz1Lli65fWZXvj0yoWouetAIqwtSPqiYTUVK4KTnfzd3M6Dkikx343yFxlXciQ9I8 ll0xiZE3euXGStZbufggIHLlVNNLl0E4f1D/oU9d1gzTGCLVj4potSbZH9wP1F5IBqa8 ohBQ== X-Forwarded-Encrypted: i=1; AJvYcCVzSM55a37NBkDoGuNCvLFBCnIDUO5rPgE3Yc9FWCm7KOAMQqkDGOTfzKyPDbP70KObdF2pjLYAPTfso+s=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3DjtD43lEQT3iC94FCVPCU4pn1C3Rm2f9fLvhPiHPn/7e/jWx +hHm6vI1gnhtmpt28Qb6LcAu3djFmJEq0KnADyZDbh0JbUymHXmjWwmf X-Gm-Gg: AY/fxX7NwPKdN9sDB99Tyiq1I01fUErqrvLe+bPT/P8tQWxNoR+crVUnXteI6cdtFZg xnI5eu3TIT5g1+iJOvJCLD4gbQudhW0Hkm1Kg1JmqmRwMsTxYhsyqA5Qomt1E9+uGx0/Q9mWIbi 9ivvhl80rsG/YBjCgYgUUqaDqvqWx5djJioDS5KBYdFzTH9CpKqgpZR5ewlljnEDpm+8XGQWqDP 5yz7xLmmHUhPa89XIIN3WP419G9xTdeK/HK1Gcp4MeWcqQ+qUjRFbVMBf0ZZU9fGSVAeRNkg6Ti BzHSJ6zl7XbkrRbsROHuMz/4IMqCPK651sKYeou7dBWoZZvdbAiHuY6fz3Xwr7Jn9Ba40t3IvsF Mt5tiY7pSngPV2N76z4tRjX0D1v2pMMmnSBW+3gqWVkwwpIKQ31th+eIhRme5W+BxNGpl4YBWYO 5xLPzwRKCOZQfWEEmjR+3QPg4y X-Google-Smtp-Source: AGHT+IEBWQtWJBseWfjNgkmXq7j6uMZfwSor2aBaCRQOVa9jlxzgUupLVdrE+xkHOoSJNLYUTSRXPg== X-Received: by 2002:a05:7022:697:b0:119:e56b:98a5 with SMTP id a92af1059eb24-121f8b0db87mr773223c88.12.1767750974079; Tue, 06 Jan 2026 17:56:14 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121f243421esm8332977c88.2.2026.01.06.17.56.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 17:56:13 -0800 (PST) Sender: Guenter Roeck Date: Tue, 6 Jan 2026 17:56:12 -0800 From: Guenter Roeck To: Steven Rostedt Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH v2] ftrace: Do not over-allocate ftrace memory Message-ID: <3cd8b2bf-c18f-4fb2-85ff-afcaaa1b38ca@roeck-us.net> References: <20260107002428.2904852-1-linux@roeck-us.net> <20260106194355.66cf869e@fedora> <20260106203352.539b9548@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260106203352.539b9548@gandalf.local.home> On Tue, Jan 06, 2026 at 08:33:52PM -0500, Steven Rostedt wrote: > On Tue, 6 Jan 2026 16:54:27 -0800 > Guenter Roeck wrote: > > > > Don't remove this block. It's still needed. A lot of entries are > > > skipped when adding the records. Weak functions and zero'd pointers > > > that were part of the count are skipped. This is the code that handles > > > that. It has nothing to do with rounding errors. > > > > > Sorry, misunderstanding. I thought that is what you meant with "This will > > make pages equal the number of pages that were allocated. Then I'm not sure > > we need this extra logic." > > > > What is the no longer needed extra logic ? > > I meant the added logic you had there, as I was a bit confused by the > "spaces" part. > That was just to avoid "skip" going negative in the for loop. The code below should work as well. I'll give it a try. Thanks, Guenter > The logic still needs to be updated, but I think it can be done with the > following: > > if (pg_unuse) { > unsigned long pg_remaining, remaining = 0; > long skip; > > /* Count the number of entries unused and compare it to skipped. */ > pg_remaining = (PAGE_SIZE << pg->order) / ENTRIES_SIZE - pg->index; > > if (!WARN(skipped < pg_remaining, "Extra allocated pages for ftrace")) { > > skip = skipped - pg_remaining; > > for (pg = pg_unuse; pg && skip > 0; pg = pg->next) { > remaining += 1 << pg->order; > skip -= (PAGE_SIZE << pg->order) / ENTRIES_SIZE; > } > > pages -= remaining; > > /* > * Check to see if the number of pages remaining would > * just fit the number of entries skipped. > */ > WARN(pg || skip > 0, "Extra allocated pages for ftrace: %lu with %lu skipped", > remaining, skipped); > } > /* Need to synchronize with ftrace_location_range() */ > synchronize_rcu(); > ftrace_free_pages(pg_unuse); > } > > -- Steve