{"id":2893,"date":"2018-11-08T02:25:08","date_gmt":"2018-11-08T02:25:08","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=2893"},"modified":"2018-11-12T00:20:08","modified_gmt":"2018-11-12T00:20:08","slug":"virtualizing-the-clock-linux-journal","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/08\/virtualizing-the-clock-linux-journal\/","title":{"rendered":"Virtualizing the Clock &#8211; Linux Journal"},"content":{"rendered":"<p>Dmitry Safonov wanted to implement a namespace for time information. The<br \/>\ntwisted and bizarre thing about virtual machines is that they get more<br \/>\nvirtual all the time. There&#8217;s always some new element of the host system<br \/>\nthat can be given its own namespace and enter the realm of the virtual<br \/>\nmachine. But as that process rolls forward, virtual systems have to share<br \/>\naspects of themselves with other virtual systems and the host system<br \/>\nitself\u2014for example, the date and time.<\/p>\n<p>Dmitry&#8217;s idea is that users should be able to set the day and time on their<br \/>\nvirtual systems, without worrying about other systems being given the same<br \/>\nday and time. This is actually useful, beyond the desire to live in the past<br \/>\nor future. Being able to set the time in a container is apparently one of<br \/>\nthe crucial elements of being able to migrate containers from one physical<br \/>\nhost to another, as Dmitry pointed out in his post.<\/p>\n<p>As he put it:<\/p>\n<blockquote><p>The kernel provides access to several clocks:<br \/>\nCLOCK_REALTIME,<br \/>\nCLOCK_MONOTONIC, CLOCK_BOOTTIME. Last two clocks are monotonous, but the<br \/>\nstart points for them are not defined and are different for each running<br \/>\nsystem. When a container is migrated from one node to another, all clocks<br \/>\nhave to be restored into consistent states; in other words, they have to<br \/>\ncontinue running from the same points where they have been dumped.<\/p><\/blockquote>\n<p>Dmitry&#8217;s patch wasn&#8217;t feature-complete. There were various questions still<br \/>\nto consider. For example, how should a virtual machine interpret the time<br \/>\nchanging on the host hardware? Should the virtual time change by the same<br \/>\noffset? Or continue unchanged? Should file creation and modification times<br \/>\nreflect the virtual machine&#8217;s time or the host machine&#8217;s time?<\/p>\n<p>Eric W. Biederman supported this project overall and liked the code in the<br \/>\npatch, but he did feel that the patch could do more. He thought it was a little<br \/>\ntoo lightweight. He wanted users to be able to set up new time namespaces at<br \/>\nthe drop of a hat, so they could test things like leap seconds before<br \/>\nthey actually occurred and see how their own projects&#8217; code worked under<br \/>\nthose various conditions.<\/p>\n<p>To do that, he felt there should be a whole &#8220;struct timekeeper&#8221; data<br \/>\nstructure for each namespace. Then pointers to those structures could be<br \/>\npassed around, and the times of virtual machines would be just as<br \/>\nmanipulable and useful as times on the host system.<\/p>\n<p>In terms of timestamps for filesystems, however, Eric felt that it might<br \/>\nbe best to limit the feature set a little bit. If users could create files<br \/>\nwith timestamps in the past, it could introduce some nasty security<br \/>\nproblems. He felt it would be sufficient simply to &#8220;do what distributed<br \/>\nfilesystems do when dealing with hosts with different clocks&#8221;.<\/p>\n<p>The two went back and forth on the technical implementation details. At one<br \/>\npoint, Eric remarked, in defense of his preference:<\/p>\n<blockquote><p>My experience with<br \/>\nnamespaces is that if we don&#8217;t get the advanced features working there is<br \/>\nlittle to no interest from the core developers of the code, and the<br \/>\nnamespaces don&#8217;t solve additional problems. Which makes the namespace a<br \/>\nhard sell. Especially when it does not solve problems the developers of the<br \/>\nsubsystem have.<\/p><\/blockquote>\n<p>At one point, Thomas Gleixner came into the conversation to remind Eric that<br \/>\nthe time code needed to stay fast. Virtualization was good, he said, but<br \/>\n&#8220;timekeeping_update() is already heavy and walking through a gazillion of<br \/>\nnamespaces will just make it horrible.&#8221;<\/p>\n<p>He reminded Eric and Dmitry that:<\/p>\n<blockquote><p>It&#8217;s not only timekeeping, i.e. reading time, this is also affecting all<br \/>\ntimers which are armed from a namespace.<\/p>\n<p>That gets really ugly because when you do settimeofday() or adjtimex() for a<br \/>\nparticular namespace, then you have to search for all armed timers of that<br \/>\nnamespace and adjust them.<\/p>\n<p>The original posix timer code had the same issue because it mapped the clock<br \/>\nrealtime timers to the timer wheel so any setting of the clock caused a full<br \/>\nwalk of all armed timers, disarming, adjusting and requeing them. That&#8217;s<br \/>\nhorrible not only performance wise, it&#8217;s also a locking nightmare of all<br \/>\nsorts.<\/p>\n<p>Add time skew via NTP\/PTP into the picture and you might have to adjust<br \/>\ntimers as well, because you need to guarantee that they are not expiring<br \/>\nearly.<\/p><\/blockquote>\n<p>So, there clearly are many nuances to consider. The discussion ended there,<br \/>\nbut this is a good example of the trouble with extending Linux to create<br \/>\nvirtual machines. It&#8217;s almost never the case that a whole feature can be<br \/>\nfully virtualized and isolated from the host system. Security concerns,<br \/>\nspeed concerns, and even code complexity and maintainability come into the<br \/>\npicture. Even really elegant solutions can be shot down by, for example, the<br \/>\npossibility of hostile users creating files with unnaturally old timestamps.<\/p>\n<p><em>Note: if you&#8217;re mentioned above and want to post a response above the comment section, send a message with your response text to ljeditor@linuxjournal.com.<\/em><\/p>\n<p><a href=\"https:\/\/www.linuxjournal.com\/content\/virtualizing-clock\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dmitry Safonov wanted to implement a namespace for time information. The twisted and bizarre thing about virtual machines is that they get more virtual all the time. There&#8217;s always some new element of the host system that can be given its own namespace and enter the realm of the virtual machine. But as that process &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/08\/virtualizing-the-clock-linux-journal\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Virtualizing the Clock &#8211; Linux Journal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2893","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=2893"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2893\/revisions"}],"predecessor-version":[{"id":3104,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2893\/revisions\/3104"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=2893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=2893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=2893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}