140 likes | 605 Views
Red-Black Trees Shared Memory de-duplication. Design and Analysis of Algorithms- Fall 2010 Azade Nazi Rasool Fakoor. KSM is daemon in the kernel (called ksmd ) Periodically performs page scans I dentify duplicate pages Merges duplicates to free pages for other uses .
E N D
Red-Black Trees Shared Memory de-duplication Design and Analysis of Algorithms- Fall 2010 Azade Nazi RasoolFakoor
KSM is daemon in the kernel (called ksmd) • Periodically performs page scans • Identify duplicate pages • Merges duplicates to free pages for other uses. • duplicate pages are merged • Marked read only • if one of the users of the page changes it for any reason, that user will receive his or her own copy (Copy On Write) Kernel Shared Memory
If KSM scan all pages in the system, • Wasteful of CPU and memory . • Therefore, applications can register the virtual areas that are likely to contain duplicate pages. • Volatile or non-volatile pages • KSM uses a simple 32-bit checksum. • Checksum is calculated during scan and stored with the page. • On a subsequent scan, if a newly computed checksum is different from the previously generated checksum, the page is changing so not a good candidate for merging. Kernel Shared Memory
In the current KSM, pages are managed by two red-black trees, one of which is ephemeral. • Unstable tree • Candidate pages for merging (unchanged for some time) • Not write protected • stable tree, • Stable pages and merged pages by KSM • Write protected Data structure
Search the page in stable tree • Yes: merge the page • No: Search the page in unstable tree • No: Insert in unstable tree • Yes: • merge the page • Remove from unstable tree • Insert page to stable tree Insert page
Check the memory to find the page for update • Not such a page so Insert it • Other wise search unstable tree to find “Y” • Yes: • merge the page • Remove from unstable tree • Insert page to stable tree • Find the “X” in unstable tree(Remove “X”) • Yes: Remove “X” • No: In stable tree • has two ID so transfer the page to the unstable tree • More than two so just remove ID related to “X” Update (ID,X) to (ID,Y)
Search Stable tree to find “Y” • Yes: • Add the page ID of “X” to the node • Remove the “X” • No: (“Y” doesn’t exist neither in unstable tree nor stable tree) • If “X” is in unstable tree change the content to “Y” • Else (“X” in stable tree) • has two ID so transfer both(X,Y) to the unstable tree • More than two so remove ID of “X” from the node and Insert “Y” to unstable tree Update (ID,X) to (ID,Y)
? Thanks