Re: [Powertop] A series of patches towards limiting memory corruption and foot print

Kalowsky, Daniel <daniel.kalowsky at intel.com>
Newsgroups dev.linux.lists.powertop
Message-ID <4628F0C61321354285DF2950999754456DF935BE@ORSMSX114.amr.corp.intel.com>
Sorry about a second post, looks like email stripped the attachements.  Second attempt here.

From: PowerTop [mailto:powertop-bounces(a)lists.01.org] On Behalf Of Kalowsky, Daniel
Sent: Tuesday, April 29, 2014 5:15 PM
To: powertop(a)lists.01.org
Subject: [Powertop] A series of patches towards limiting memory corruption and foot print

Hi Powertop,

I've been working with the interactive mode and have run into cases where powertop will crash due to a series of memory corruptions.  The following series of patches have helped to reduce the frequency of the issue, although not completely solved it.  The issues arise much faster on platforms where there are constrained amounts of RAM to work within.

Patch 1 - When shutting down the interactive display, the display bits of memory is not correctly released.  This patch provides a method for correctly doing so.

Patch 2 - Solving a documented memory leak with a non-elegant solution.  The path either adds the bundle to the stack, or it forgets about it.  If it is forgotten about, make sure to clear that memory before moving on.  This is done with a simple flag variable being set.

Patch 3 - When the tuning window is updated, the current pointer is just set adrift and not properly free'd.  This patch catches that issue and removes the dangling pointer by holding a reference to the pointer until it is reset or specifically free'd.

Patch 4 - Someone actually added in the code to create a onetime pretty-print array, this patch just puts it to use by setting the variable.

Patch 5 - Limiting the buffer copy to the size of the allocated buffer with snprintf.

Patch 6 - There exist some processes and entries that can and do extend beyond the length of these buffers.  This limits those entries so as not to corrupt other memory on the system when in interactive mode.

Patch 7 - This is an untested patch, but follows along the same lines of Patch 6.  It applies the same principals only for the report method.

Patch 8 - Creates a clean_shutdown function that can be used to cleanup the memory space at shutdown time.  Calls upon parts of Patch 1 to make this happen.

There will more than likely be some more patches in the future as time permits.
attachment.html (text/html, 5.2 KB)
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.EmailStyle18
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
span.EmailStyle19
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Sorry about a second post, looks like email stripped the attachements.&nbsp; Second attempt here.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> PowerTop [mailto:[email protected]]
<b>On Behalf Of </b>Kalowsky, Daniel<br>
<b>Sent:</b> Tuesday, April 29, 2014 5:15 PM<br>
<b>To:</b> [email protected]<br>
<b>Subject:</b> [Powertop] A series of patches towards limiting memory corruption and foot print<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Hi Powertop,<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">I&#8217;ve been working with the interactive mode and have run into cases where powertop will crash due to a series of memory corruptions.&nbsp; The following series of patches have helped to reduce the frequency of the issue, although not completely
 solved it.&nbsp; The issues arise much faster on platforms where there are constrained amounts of RAM to work within.
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 1 &#8211; When shutting down the interactive display, the display bits of memory is not correctly released.&nbsp; This patch provides a method for correctly doing so.&nbsp;
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 2 &#8211; Solving a documented memory leak with a non-elegant solution.&nbsp; The path either adds the bundle to the stack, or it forgets about it.&nbsp; If it is forgotten about, make sure to clear that memory before moving on.&nbsp; This is done with
 a simple flag variable being set.&nbsp; <o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 3 &#8211; When the tuning window is updated, the current pointer is just set adrift and not properly free&#8217;d.&nbsp; This patch catches that issue and removes the dangling pointer by holding a reference to the pointer until it is reset or specifically
 free&#8217;d.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 4 &#8211; Someone actually added in the code to create a onetime pretty-print array, this patch just puts it to use by setting the variable.&nbsp;
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 5 &#8211; Limiting the buffer copy to the size of the allocated buffer with snprintf.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 6 &#8211; There exist some processes and entries that can and do extend beyond the length of these buffers.&nbsp; This limits those entries so as not to corrupt other memory on the system when in interactive mode.&nbsp;
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 7 &#8211; This is an untested patch, but follows along the same lines of Patch 6.&nbsp; It applies the same principals only for the report method.&nbsp;
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Patch 8 &#8211; Creates a clean_shutdown function that can be used to cleanup the memory space at shutdown time.&nbsp; Calls upon parts of Patch 1 to make this happen.&nbsp;
<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">There will more than likely be some more patches in the future as time permits.&nbsp;
<o:p></o:p></p>
</div>
</body>
</html>
powertop-patches.7z (application/octet-stream, 3.9 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.