From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 6288A18C008 for ; Wed, 7 Jan 2026 01:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767750446; cv=none; b=d+6sUynIWdCbe4l+DLqMMvu3bo6FLP2U4oW/oQ4Bo8M3CZQf7BTQ08dXRR6pSsCn9DThv9E/DvWhy1pjuzohM1lDlfags152jNCr+ES18vTIz2bup9eepysfTMkCscVmO2O8kIUBXH5uVjKwoU4DiHA1ECculEE2k80X2J6MNKI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767750446; c=relaxed/simple; bh=jLXi0znS7WYEwkEk9PrWkzM4hv/8LNw96t0l0jl3fn0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XekGy2rYDBOvDfMkm6jan8TloDYfoWZvM8/ffnclQ7Z6TEYYQfmTeTxNYmaEMuyBwc40YvDYyJq79kpKw2/NLfp27BCgNHDbOO0EdL8Se1TcXWub62mROPJwLpvyTtl8siW0JsUGZIqXxqNdm/gFyjCgR7IH7+PlCP6lMojCsYI= 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=f+hDhMfU; arc=none smtp.client-ip=74.125.82.53 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="f+hDhMfU" Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-11f2eac9726so364411c88.1 for ; Tue, 06 Jan 2026 17:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767750444; x=1768355244; 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=RoXDYEWmsDDUhtVNh/8jymS7BJoQBbn8Lv407Kkn1KI=; b=f+hDhMfUeB3r71FAtAsfOxIUvGQYJRnF6g9Zf1T0JCYC3Tst1V/PlVFSo4dy9ueREM Nqph7Ze4Xhn4XxJPyq/5/3hHFaFI7OhcE468p/HMbB3CMAbO8nGkmZlELa62U95U+c8Z Q/4skNZwYUgx68hK3qjupzwgz9D90a4mHsOfnWHnxhh4LLP3aS/0Icj7dy838cS9mhnr SDt71cLLg8AooZpMu1WfX35ogGWTFnA3iO85E3Sl1yGZ4j2mu7wTD3FJls3CR3TX8BEr TLCk66OrgxXhW2egkP1XZw9Do8s+TZ1kY+6yGxdL6kz09xpANkjVOqxrzKjs/1BFrBh5 os1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767750444; x=1768355244; 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=RoXDYEWmsDDUhtVNh/8jymS7BJoQBbn8Lv407Kkn1KI=; b=Avf0Jdp1KfgN4avML9ZFxLp76SsqpTTqpZd+Zg6OY53S9ZEC7RukEbRzjovInde2z6 NX+ngEsRAvQo8orFvpo4xEaZRp/o4o+8ALDsFxjTyJ91neP1xfOnQYmNaybz5MQE+HAx coSYZjzt6gUPW1qpPl07sr2+S3/PWQcDYSPBdGSUDDsDpa4NDUQ67MtESCDtn3ZUPp5L TngOnedsNC+efOWq27wBJedjR1aPhbt7RmcfTwizfNXLKGFS82vUeZc4tQwzjymBlEAW +Zyz3Z/3fwUxzLO3WXpS9oFKU1gDDVmuh+UvBCmsyaaqPnzawdKlx2kl0frr6liQzvBf Intw== X-Forwarded-Encrypted: i=1; AJvYcCV2m4GQ0NBQoKNla4VuI65wDITwAysMf2ZWPYN0phcG7Wpw0n61p2g0FLR9g8zgeRiGR4u0IQKvCHMIxZE=@vger.kernel.org X-Gm-Message-State: AOJu0YwXJexjGqxWO14dFNn6DhbHXBW/6XImzzgXgrcUGpfLtcTOEG8Y w3ELtx3T87rqtA00pJ/RGUCwdbOwEINOY8y3E1htBJf0KRhlirnzmpNQq7zr+w== X-Gm-Gg: AY/fxX6xWXAVLkZZc5INx96YaRMnoCdEVic/CwK/TvivtW1MeJ0zgOxlOlbC0zKxSuk 9TRfMsxMFp6L7kXHOT69QQ6dJmJBFogVDx0weVCq00j444wbubcUB6CcORHBhFMq9EQ9VuLAtK4 E8qOGz15YZz2W5rRq+ePLt44cxIYd8xUoxwLuwUDVU2/AyDQFH0qKactqxVmqn4kp2gaC1QJ9bg 5aVt09xOTK6GKI6NfffYJdZOZWeelRcFvOZtLpcAYAZ9wqWxAQ1+XO79H+itQpfid7cTA3bHKK2 0UQHEV3AzTMLiwYHuXL3EyRnoa0c8LNskUAI2Fm1T+kmqZYpYDHjU3Pqhna4nKFhRAkcw5VDxJx p7IjQE0HAHTQigqNFcw/+E6uh8dTrkijfNnbWIIrJ58DS893xpEU0/SH4ORB8b7ANaRS9AgCY+O IiDFKU4hq7DM/rP9p/TLwpHWNH X-Google-Smtp-Source: AGHT+IEBpLAJzTQzgBsTEVf6wzVZRDlzQHQzRM8jri8pFBsZkHkAcBX5ssubNOWpTGNglJ93oQJBYw== X-Received: by 2002:a05:7022:2584:b0:11e:3e9:3e94 with SMTP id a92af1059eb24-121f1b59840mr3973277c88.25.1767750444238; Tue, 06 Jan 2026 17:47:24 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121f243421esm8308978c88.2.2026.01.06.17.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 17:47:23 -0800 (PST) Sender: Guenter Roeck Date: Tue, 6 Jan 2026 17:47:22 -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: <6909622a-7d96-41ff-aee1-d3b216033cfe@roeck-us.net> References: <20260107002428.2904852-1-linux@roeck-us.net> <20260106195241.166f4115@fedora> 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: <20260106195241.166f4115@fedora> On Tue, Jan 06, 2026 at 07:52:41PM -0500, Steven Rostedt wrote: > On Tue, 6 Jan 2026 16:24:28 -0800 > Guenter Roeck wrote: > > > if (pg_unuse) { > > - unsigned long pg_remaining, remaining = 0; > > - unsigned long skip; > > - > > - /* Count the number of entries unused and compare it to skipped. */ > > - pg_remaining = (ENTRIES_PER_PAGE << pg->order) - pg->index; > > - > > The above needs to be fixed though. Yes, and skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE); is also wrong. That means WARN(skip != remaining, "Extra allocated pages for ftrace: %lu with %lu skipped", remaining, skipped); will be hit because because 'skip' may be inaccurate. Example with added debug log: ftrace: skipped: 654 pg_remaining: 313 skip: 341 (3) pages: 310 remaining: 2 ------------[ cut here ]------------ Extra allocated pages for ftrace: 2 with 654 skipped WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:7299 ftrace_process_locs+0x5a8/0x5c0 ... ftrace: allocating 52250 entries in 308 pages ftrace: allocated 308 pages with 4 groups The warning is seen because the number of pages needed for 341 entries is mis-calculated as 3 instead of 2. That means I'll need the added code from v1 to calculate the correct value for the number of pages needed, at least if you want to keep the validation code with the warning backtraces. Thanks, Guenter