{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/10690","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/10690/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/10690/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/10690/events","html_url":"https://github.com/dotnet/coreclr/issues/10690","id":219173941,"number":10690,"title":"ProcessorCount when running with docker cpuset","user":{"login":"tmds","id":1025424,"avatar_url":"https://avatars2.githubusercontent.com/u/1025424?v=3","gravatar_id":"","url":"https://api.github.com/users/tmds","html_url":"https://github.com/tmds","followers_url":"https://api.github.com/users/tmds/followers","following_url":"https://api.github.com/users/tmds/following{/other_user}","gists_url":"https://api.github.com/users/tmds/gists{/gist_id}","starred_url":"https://api.github.com/users/tmds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmds/subscriptions","organizations_url":"https://api.github.com/users/tmds/orgs","repos_url":"https://api.github.com/users/tmds/repos","events_url":"https://api.github.com/users/tmds/events{/privacy}","received_events_url":"https://api.github.com/users/tmds/received_events","type":"User","site_admin":false},"labels":[{"id":198076301,"url":"https://api.github.com/repos/dotnet/coreclr/labels/area-PAL","name":"area-PAL","color":"d4c5f9","default":false},{"id":172143003,"url":"https://api.github.com/repos/dotnet/coreclr/labels/bug","name":"bug","color":"1d76db","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/coreclr/milestones/9","html_url":"https://github.com/dotnet/coreclr/milestone/9","labels_url":"https://api.github.com/repos/dotnet/coreclr/milestones/9/labels","id":1876930,"number":9,"title":"2.0.0","description":".NET Core 2.0 Placeholder.  No date is set. https://github.com/dotnet/core/blob/master/roadmap.md\r\n\r\nNote: Previously named as 1.2.","creator":{"login":"joshfree","id":1302850,"avatar_url":"https://avatars2.githubusercontent.com/u/1302850?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":229,"closed_issues":360,"state":"open","created_at":"2016-07-11T20:32:48Z","updated_at":"2017-04-04T09:30:03Z","due_on":"2017-05-10T07:00:00Z","closed_at":null},"comments":3,"created_at":"2017-04-04T08:22:12Z","updated_at":"2017-04-04T13:29:10Z","closed_at":null,"body":"When running in Docker on Linux, Environment.Processor returns the number of available logical processors in the host system. It doesn't take into account the limitations that were set on the container.\r\n\r\nDockerfile:\r\n```\r\nFROM microsoft/dotnet:sdk\r\nADD src ./src\r\nWORKDIR src\r\nENV LTTNG_UST_REGISTER_TIMEOUT 0\r\nRUN dotnet restore && dotnet build\r\nENTRYPOINT [\"dotnet\", \"run\"]\r\n```\r\nsrc/Program.cs:\r\n```\r\nusing System;\r\nnamespace ConsoleApplication\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            System.Console.WriteLine($\"ProcessorCount: {Environment.ProcessorCount}\");\r\n        }\r\n    }\r\n}\r\n```\r\nsrc/app.csproj:\r\n```\r\n<Project Sdk=\"Microsoft.NET.Sdk\">\r\n<PropertyGroup>\r\n<OutputType>Exe</OutputType>\r\n<TargetFramework>netcoreapp1.0</TargetFramework>\r\n</PropertyGroup>\r\n</Project>\r\n```\r\n\r\nExecuting:\r\n```\r\n$ docker build -t proccount .\r\n$ docker run proccount\r\nProcessorCount: 4\r\n$ docker run --cpuset-cpus 1 proccount\r\nProcessorCount: 4\r\n```\r\n\r\nThe latter call should return 1.\r\n\r\nMono was fixed for this issue, see bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=39279.\r\n\r\nNumber of processors is determined via sched_getaffinity: https://github.com/mono/mono/blob/17aa73d0ae216529b59d5aa3d0ee68007bb035c4/mono/utils/mono-proclib.c#L774-L780\r\n\r\nRelated issue for Android/ARM:\r\n\r\nThe mono_cpu_count function contains other special cases for PLATFORM_ANDROID, HOST_ARM and HOST_ARM64. On Android, it's preferable not to use _SC_NPROCESSORS_ONLN because the number of online processors varies for power saving. On ARM, the number of cpus returned by sched_getaffinity varies as well. Comments in the code suggests that the ARM&ANDROID cases can be handled together by reporting _SC_NPROCESSORS_CONF.\r\n\r\nComment from @akoeplinger:\r\n\r\n>  I think the pragmatic solution is the following:\r\n>  * use sched_getaffinity (+ fallback to _SC_NPROCESSORS_ONLN in case of error) on x86. This\r\n>  ensures we're inline with what OpenJDK [4] and CoreCLR [5] do\r\n>  * use _SC_NPROCESSORS_CONF exclusively on ARM (I think we could eventually even get rid of the PLATFORM_ANDROID special case)\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/291499620","html_url":"https://github.com/dotnet/coreclr/issues/10690#issuecomment-291499620","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/10690","id":291499620,"user":{"login":"tmds","id":1025424,"avatar_url":"https://avatars2.githubusercontent.com/u/1025424?v=3","gravatar_id":"","url":"https://api.github.com/users/tmds","html_url":"https://github.com/tmds","followers_url":"https://api.github.com/users/tmds/followers","following_url":"https://api.github.com/users/tmds/following{/other_user}","gists_url":"https://api.github.com/users/tmds/gists{/gist_id}","starred_url":"https://api.github.com/users/tmds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmds/subscriptions","organizations_url":"https://api.github.com/users/tmds/orgs","repos_url":"https://api.github.com/users/tmds/repos","events_url":"https://api.github.com/users/tmds/events{/privacy}","received_events_url":"https://api.github.com/users/tmds/received_events","type":"User","site_admin":false},"created_at":"2017-04-04T13:29:10Z","updated_at":"2017-04-04T13:29:10Z","body":"@janvorli Similar problem for memory, kernel APIs are not aware of the container. jdk9 has an experimental option, from https://bugs.openjdk.java.net/browse/JDK-8170888\r\n\r\n> It is proposed for this RFE that we add an experimental VM option, such as -XX:+UseCGroupMemoryLimitForHeap, to opt-in to using the value in /sys/fs/cgroup/memory/memory.limit_in_bytes as the value for phys_mem as suggested in the submission. "}}
{"actor":{"display_login":"tmds"}}