<html 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=utf-8">
<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;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.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>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Maybe it’s worth having some timeout in receive loop of cpc_receive? Otherwise erts_code_purger gets completely stuck, this code_server get_server stops responding too, and it leads to problems pretty much everywhere. That said, a single
high-priority process in a tight loop stops all other processes, including those of max priority.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal"> Maxim Fedorov<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black"><rickard.erlang.org@gmail.com> on behalf of Rickard Green <rickard@erlang.org><br>
<b>Date: </b>Saturday, May 26, 2018 at 10:59<br>
<b>To: </b>"erlang-questions@erlang.org" <erlang-questions@erlang.org>, Maxim Fedorov <dane@whatsapp.com><br>
<b>Subject: </b>Re: High Priority processes not handling system tasks<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">I don't know why this mail only ended up in the archive, but not in my mailbox...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">> G’Day,<br>
> Below is a chunk of code that does not look bad at a first<br>
> glance, but…<br>
> <br>
> start() -><br>
> Pid = spawn(?MODULE, high, []),<br>
> io:format("Starting... "),<br>
> erlang:check_process_code(Pid, rec),<br>
> io:format("collected~n").<br>
> <br>
> high() -><br>
> erlang:process_flag(priority, high),<br>
> endless(10).<br>
> <br>
> endless(X) -><br>
> endless(X+1).<br>
> <br>
> <br>
> start() never returns, because check_process_code schedules a normal priority <o:p>
</o:p></p>
<div>
<p class="MsoNormal">> system task against high priority process. It seems to be logical, but leads to<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> some really weird effects. For example, code:soft_purge() hangs (in<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> erts_code_purger, cpc_receive), thus whole code_server gen_server hangs,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> and this paralyses almost everything (a separate issue - cpc_receive has no<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> receive timeout at all, possibly stalling whole VM).<br>
><br>
> Is it designed behaviour? I have quite a straightforward solution (patch for<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> erl_process.c), but I might now understand consequences. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">><br>
> Applies to R19+ (with 'new purge strategy' enabled). Older releases (eg. R16B)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> are not affected.<br>
><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> <br>
> Regards,<br>
> <br>
> Maxim Fedorov<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Yes this is how the process priority scheme was intentionally designed (for better or for worse). 'high' and 'max' process priority work are alway selected before lower process priority work.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Changing the behaviour of system tasks so that lower priority tasks are interleaved with 'high' and/or 'max' priority work essentially introduce intentional priority inversion.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Utilization of 'high' and 'max' priority has to be done with outmost care. Using high or max priorities on processes that hogs the cpu very likely will get you into trouble. The documentation of process_flag(priority, _) is also quite clear
on this.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">This question comes up every now and then. In the past we have always rejected proposals for priory tweeks like this. I'm not claiming this priority scheme is the ultimate scheme, but this is what we have and I think we should stick with
it as it is or redesign it from scratch.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Rickard<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">-- <br>
<br>
Rickard Green, Erlang/OTP, Ericsson AB <o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>