{"id":464,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:25:59","modified_gmt":"2020-08-22T20:25:59","slug":"this-is-the-page-title-toplevel-297","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=464","title":{"rendered":"Caches"},"content":{"rendered":"\n<title>Caches<\/title>\nIf you were to implement a system using the above theoretical model then\nit would work, but not particularly efficiently.\nBoth operating system and processor designers try hard to extract more\nperformance from the system.\nApart from making the processors, memory and so on faster the best\napproach is to maintain caches of useful information and data that\nmake some operations faster.\nLinux uses a number of memory management related caches:\n<dl compact>\n<p>\n\t<dt><b>Buffer Cache<\/b><\/dt><dd>\n<p>\n\tThe buffer cache contains data buffers that are used by the\n\tblock device drivers.\n<p>\n\tThese buffers are of fixed sizes (for\n\texample 512 bytes) and contain blocks of information that have\n\teither been read from a block device or are being written to\n\tit.\n\tA block device is one that can only be accessed by reading and\n\twriting fixed sized blocks of data.\n\tAll hard disks are block devices.\n<p>\n\tThe buffer cache is indexed via the device identifier and\n\tthe desired block number and is used to quickly find a block\n\tof data.  Block devices are only ever accessed via the buffer\n\tcache.  If data can be found in the buffer cache then it does not\n\tneed to be read from the physical block device, for example a\n\thard disk, and access to it is much faster.\n<p>\n\t<dt><b>Page Cache<\/b><\/dt><dd>\n<p>\n\tThis is used to speed up access to images and\n\tdata on disk.\n<p>\n\tIt is used to cache the logical contents of a file a page at a time and\n\tis accessed via the file and offset within the file.\n\tAs pages are read into memory from disk, they are cached in the\n\tpage cache.\n<p>\n\t<dt><b>Swap Cache<\/b><\/dt><dd>\n<p>\n\tOnly modified (or <i>dirty<\/i>) pages are saved in the swap\n\tfile.\n<p>\n\tSo long as these pages are not modified after they\n\thave been written to the swap file then the next time the\n\tpage is swapped out there is no\n\tneed to write it to the swap file as the page is already in\n\tthe swap file.\n\tInstead the page can simply be discarded.\n\tIn a heavily swapping system this saves many unnecessary and\n\tcostly disk operations.\n<p>\n\t<dt><b>Hardware Caches<\/b><\/dt><dd>\n<p>\n\tOne commonly implemented hardware cache is in the processor; a cache of Page\n\tTable Entries.\n\tIn this case, the processor does not always read the page table directly\n\tbut instead caches translations for pages as it needs them.\n\tThese are the Translation Look-aside Buffers and contain cached copies of the\n\tpage table entries from one or more processes in the system.\n<p>\n\tWhen the reference to the virtual address is made, the processor will attempt\n\tto find a matching TLB entry.\n\tIf it finds one, it can directly translate the virtual address into a\n\tphysical one and perform the correct operation on the data.\n\tIf the processor cannot find a matching TLB entry then it must get the\n\toperating system to help.\n\tIt does this by signalling the operating system that\n\ta TLB miss has occurred.\n\tA system specific mechanism is used to deliver that exception to the\n\toperating system code that can fix things up.\n\tThe operating system generates a new TLB entry for the address\n\tmapping.\n\tWhen the exception has been cleared, the processor will make another attempt\n\tto translate the virtual address.   This time it will work because there\n\tis now a valid entry in the TLB for that address.\n<\/dl>\n<p>\nThe drawback of using caches, hardware or otherwise, is that in order\nto save effort Linux must use more time and space maintaining these\ncaches and, if the caches become corrupted, the system will crash.\n<p>\n","protected":false},"excerpt":{"rendered":"<p>Caches If you were to implement a system using the above theoretical model then it would work, but not particularly efficiently. Both operating system and processor designers try hard to extract more performance from the system. Apart from making the &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=464\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-464","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/464\/revisions"}],"predecessor-version":[{"id":514,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/464\/revisions\/514"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}