From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 74101285C91 for ; Tue, 6 Jan 2026 23:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767743293; cv=none; b=IBKTbBPBNmLmOaGZyQ/4yUCFmyAN0qV6DFvlH82ko+8LJU7dWHiNAFMSnTDRvwXQrRQdSsGpwPtvxNJwv+x7GwdS1kYXoFYe2YgcN3o9knx6LSTwxThp4t9flZ7tIJJbz7g9lJH3uAJMwQVNx8ETSQ2Q18bbs6NArIZHMWVX8sE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767743293; c=relaxed/simple; bh=qT8QyIEYv5VwZK/5mmr9XyMl+ChjYtNyi2gpBcHHnpE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BLIa4qDiHn6lrJ46NkLRh/obICxKMM9MaVCsnykVkCjFNH/q2MdwG9i+YAwymjMafBLYAVGHaSojo9Pr/RduvEFLxFnQxIrSYuMHONcTZ3KxJ4L0VFWH/+fLSHJ/J5mWOJt9AviVNsrxaifboebwjiQcElbImp1vG8PJvPmxCFo= 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=lbULiC9p; arc=none smtp.client-ip=74.125.82.54 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="lbULiC9p" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-11dd2370722so1595016c88.1 for ; Tue, 06 Jan 2026 15:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767743291; x=1768348091; 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=yOWlu2AaGJvFmo8hu/TEBLcfBRHDijI3UTwZStUFhtw=; b=lbULiC9p6oEGD4D6nqjuhUD9PWva9FQeHGJi08M2mat4j12NruayQ0EXq2cCAzB8vM rGunygZVYU4KanfMoJHiY2hBR1rZMZaZgeKiPHPUbEXFiXAPng95hd+9yzyRlaNAN3oU e3VuzdyvlV3o88zfT6N7xTu8iwldhsA/vbETuWYyQi6yvI00C8Z2jFJ8uFAaYF3auYCF zuW82jSjbppsoPX3RvkeA8GIRMbdrrwcJbrEbso8NWnDTKK7AAHyTaaAIagA6brv1R52 7RZmINIgsBk/DD6Y5EdiMOQ/FQFgSQuzfqPajiId2laHHlNPCp234c4oL+ZW9DrMfzpD YuPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767743291; x=1768348091; 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=yOWlu2AaGJvFmo8hu/TEBLcfBRHDijI3UTwZStUFhtw=; b=N8a2mF2kKGiKYQ1D7Q3pu0yzaWDmIbEmQY8pdduAwkYM5VFEyjw3emjcJ21LB/6oDX K8A7walLmaCE/9zSrGIwtUsOEFPGG46sna94oHhxgZemDxz+6cjQqArkI2EWwtR6lm/z Frx3juYP4dy66IVNLNtyQmkKzsSyn/BZU01XjeZ8ejphKEt8L1gR0nSpHsL/xwa6GM+P ylFbM8mNz/uvR9t2Ep7C3LRzuyZRVQ4N20EHNF3v9X4lL46+vocLHw8OxxrK4I0kuxCJ lSK3AYYo3DApULWVxaZ0JlmeKukiwFP5tZsVZFlax2/S/4qaxdTePXNdvNcRE6n2Pzrh RFCg== X-Forwarded-Encrypted: i=1; AJvYcCVBlPrqih1GrHoTHWKd2j2326bxrAUnsHR3o5RTieqcM2gKgt4OdXwPZWvvGWGfOpU5BeecEdLUSJcGPCU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1cJAicFP/AFjbpf+NqAgi2RqXwbquG7V7SBD5gv6VePiXPujJ WuBAKoi8OkPaNEsCz05er77r1IoArObfky7ghUd+Y/t8r0c/dVTx4WcS X-Gm-Gg: AY/fxX6dvTm/A9pnwtEyLFeAmrVCzAv0ClOwaTOWFeet0CGLTmUFvE0EsQee1JZa98e xQ2e8li4KAVWDh8BgeHbaq3m7RP3zCAoTf7q0v9/r+54vo5crm95TDie7wGxNV4sJuqRyC7xlGK D2rClOPR47wnVMSWBR07sVNuIqgamNsykfNoJa2Kx5yblUXpB2iDFyYMYl1f7JKbEFRJAMSKfC+ op9DOpZ8GiiKvfb1/yDZAaqp2cxVptXdITva1amekY4vB+A4v4Anrhiwr2/ea/GwG6pK33O9+G+ MGMZSmJvtZUZo8Nx2AU8DqBp/QRFBs/Kd9SawbAnrAecwa6AP9ErWEneCzyEgfUW6VrQsvZHJEr qcCstBFMe+0LkUfSVSSH0HcnP00kHBAB4e+gncPhmCls7ArGzE2OnAeX6tcu5esaar/TOeeeJaR Qv+HxwzjnXqxS8gwrt8S3cLBcI X-Google-Smtp-Source: AGHT+IGf9u3SwMMLL9rLfC8ghLYF2jXHmsnIuTCRiI++vO9RDAlRP0jYEfd4kiZdHjWNU1B/Xctqkg== X-Received: by 2002:a05:7022:629d:b0:119:e56b:c75c with SMTP id a92af1059eb24-121f8b5c392mr660379c88.33.1767743291283; Tue, 06 Jan 2026 15:48:11 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121f248bb6esm7578124c88.12.2026.01.06.15.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 15:48:10 -0800 (PST) Sender: Guenter Roeck Date: Tue, 6 Jan 2026 15:48:09 -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] ftrace: Do not over-allocate ftrace memory Message-ID: References: <20260106203533.2896197-1-linux@roeck-us.net> <20260106161844.02ab387f@gandalf.local.home> <0a9cd12e-6db8-4b41-979e-95f06e9390f6@roeck-us.net> <20260106183815.33fa41f9@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: <20260106183815.33fa41f9@gandalf.local.home> Hi Steve, On Tue, Jan 06, 2026 at 06:38:15PM -0500, Steven Rostedt wrote: > On Tue, 6 Jan 2026 15:05:25 -0800 > Guenter Roeck wrote: > > > > > /* > > > > * Use ftrace_number_of_pages to determine how many pages were > > > > * allocated > > > > */ > > > > pages = ftrace_number_of_pages; > > > > > > > > start_pg = ftrace_allocate_pages(count); > > > > if (!start_pg) > > > > return -ENOMEM; > > > > > > > > /* ftrace_allocate_pages() increments ftrace_number_of_pages */ > > > > pages = ftrace_number_of_pages - pages; > > > > > > > > > > That might work, assuming that the code updating ftrace_number_of_pages > > > is (mutex) protected. I don't immediately see that, and the > > > "mutex_lock(&ftrace_lock);" right after the above code makes me a bit > > > concerned. > > > > > > > One way to avoid the locking problem without potentially risky code changes > > would be to pass a pointer to pages to ftrace_allocate_pages() and to > > ftrace_allocate_records(), and to update it from there. I tested that and > > confirmed that it works. > > I was originally going to suggest that, but when looking at the code, I > noticed that these variables could be useful. They are only updated on boot > up, module load, module unload and when module memory is freed. > > But looking into the module code, these updates are done outside of the > module_mutex. This means these values need to be converted to atomics as > they are updated without any protection. > > Yeah, better to just get the value from passing in a parameter to both > ftrace_allocate_pages() and to ftrace_allocate_records(). > > Something like: > > unsigend long pages = 0; > > [..] > start_pg = ftrace_allocate_pages(count, &pages); > > [..] > ftrace_allocate_pages(unsigned long num_to_init, unsigned long *num_pages) { > [..] > cnt = ftrace_allocate_records(pg, num_to_init, num_pages); > > And have ftrace_allocte_records() have: > > pages = 1 << order; > *num_pages += pages; > ftrace_number_of_pages += pages; > That is exactly what I tested. With that, I assume I can drop the code to update pages in ftrace_process_locs(), inclusing the warning backtraces. I'll send v2 with those changes. Thanks, Guenter