CCoW: Optimizing Copy-on-Write Considering The Spatial Locality in Workloads Part 3

Apr 02, 2024

3. CCoW Design

In this section, we first introduce our motivation behind improving the copy-on-write and explain the basic concept of the coverage-based copy-on-write (CCoW). Then we explain the way CCoW captures the locality under different scenarios and the optimization to capture the locality at a low overhead.

Memory is people's ability to acquire, store, and retrieve information. People's memories will also differ in different scenarios. In this article, we will explore the relationship between memory in different scenarios.

The first is the learning scenario. Learning is an important means for humans to acquire knowledge and skills. In the learning process, memory plays a vital role. If you have a strong memory, you can master new knowledge faster and retain learned knowledge more easily. Therefore, in learning scenarios, we need to keep our thinking clear and focused, to better improve memory.

The second is the tourism scene. Traveling allows us to experience different cultures and environments, greatly enriching our horizons. During travel, we can acquire rich cultural knowledge by remembering geographical locations, people, customs, and other information. Therefore, in the travel scene, we need to observe carefully and actively experience it, to better improve our memory.

Once again, it's a work scene. At work, we need to handle a large amount of information, such as data, contacts, tasks, plans, etc. If our memory is not strong enough, it will affect our work efficiency and achievements. Therefore, in work scenarios, we need to do a good job of recording and organizing and try to narrow the span of "information connection" as much as possible. In this way, we can better improve our memory.

Finally, there are life scenes. Humans need to remember many daily things, such as addresses, phone numbers, tasks for the day, and so on. If our memory is not good enough, many problems in life will arise. Therefore, in life scenes, we need to exercise our memory ability. We can improve our memory by building associative thinking and repeating silently.

To sum up, memory in different scenarios is closely related. We can improve our memory and achieve better performance in various scenarios through deliberate practice and concentration. Let us pursue a better life and career with an optimistic attitude. It can be seen that we need to improve memory, and Cistanche deserticola can significantly improve memory, because Cistanche deserticola can also regulate the balance of neurotransmitters, such as increasing the levels of acetylcholine and growth factors. These substances are very important for memory and learning. In addition, Cistanche deserticola can also improve blood flow and promote oxygen delivery, which can ensure that the brain receives sufficient nutrients and energy, thereby improving brain vitality and endurance.

improve working memory

Click know supplements to improve memory

3.1. Motivation

As discussed earlier, the copy-on-write mechanism plays a key role in implementing virtual memory features in modern OSs. However, its advantages in terms of space have been diminishing in modern computing environments and write-intensive workloads, which are common in data centers [21,22]. 

Emerging memory technologies such as storage memory (SCM) and persistent memory enable increased data density for memory modules while lowering the cost per unit of data. 

Nowadays building a node with a huge amount of memory in the terabyte scale has become cheaper than ever. In addition, cloud service providers have reported that the nodes in data centers are suffering from low memory utilization, leaving 40–50% of memory unused [23–26]. In this situation, it becomes feasible to trade memory space for performance in performance-critical systems [27]. The advantages in terms of performance have been diminishing as well. 

The performance benefit of copy-on-write can be characterized by the frequency and performance of page fault handling. While spawning a child process, the write permission to all pages is dropped. From the perspective of correctness, this is inevitable; however, it leads to frequent page faults after the fork, in serving each write request. This storm of write page faults not only happens to child processes but also to the parent process. 

To make it worse, the page fault handling time has not improved recently but tends to be prolonged due to security reasons. In the past, the entire kernel address space was persistently mapped to a part of the user process address space. 

However, this address space layout allows malicious user processes to indirectly read the critical data in the kernel address space by exploiting the speculative execution in the processors [28,29]. 

To mitigate such critical security vulnerability, modern OSs employ kernel page table isolation (KPTI). In general, only a limited portion of the kernel address space is mapped to the process address space, and the rest of the kernel address space is dynamically mapped and unmapped during the interrupt and system call handling. This must be accompanied by TLB flushing, which can significantly degrade the system's performance. 

In this work, we aim to reduce the overhead of copy-on-write by leveraging the spatial locality of memory references. Currently, the copy-on-write takes place per page, and each time a page fault occurs, the OS should get involved. Our key idea is to reduce the frequency of OS involvement by leveraging the spatial locality of memory accesses. If a page is accessed for write, nearby pages are also likely to be accessed for write shortly. 

Thus, if we perform the copy-on-write not only for the faulty page but also for nearby pages together (i.e., pre-copy nearby pages), we can amortize the overhead for the copy-on-write during the page fault handling. We, however, should be careful, not to blindly always copy all nearby pages. 

If the copied pages are written later, the overhead incurred for the pre-copy is paid back. However, if the copied pages are not written afterward, the pre-copy only incurs extra overhead in terms of time and space. 

ways to improve your memory

Thus, it is crucial to identify the proper target pages to copy. Similar approaches have been employed to minimize the page fault handling overhead. Linux employs the so-called 'fault around' feature. While handling a page fault, Linux initiates the page fault handling for the pages that are around the faulty page [2]. This feature, however, is only applied to the read page faults for file-backed memory regions. 

Given that the proposed idea focuses on writing page faults for anonymous pages, we can argue that our approach is different from the fault-around feature. Many state-of-the-art designs [12–17] have been proposed to optimize the use of huge pages in the OS. 

These systems, in common, present a scheme to identify the best candidate pages to be converted to huge pages and to efficiently promote to (i.e., convert base pages to a huge page) or demote from (i.e., convert a huge page into base pages) huge pages. 

However, regardless of the proposed schemes, copy-on-write is performed in the base page granularity only, after breaking the huge page into base pages if necessary. Thus, their copy-on-write performance characteristics are the same as the default Linux system with the transparent huge page (THP) mechanism. In contrast, our proposed scheme is unique in that it performs copy-on-write at a different granularity according to the locality degree in memory accesses.

3.2. Identifying the Spatial Locality

To realize the proposed scheme, we should consider two challenging issues. Firstly, target pages should be identified precisely and timely, so that the benefit of the precopy is maximized while the overhead for the precopy is minimized. 

Once a page is copied by a writer, the page will not trigger any further page faults. This effectively means that the system lost the opportunity to optimize the write access. Thus, the system should be able to foresee future page usage to determine which pages should be copied and which are not. Secondly, identifying the target pages should have low overhead since OSs cannot afford time-consuming processing in the performance-critical memory management subsystem. 

As discussed in Section 2, many virtual memory features in modern OSs are based on the copy-on-write mechanism. Thus, the overhead can easily outweigh the benefit of the optimized copy-on-write if the overall implementation is not sufficiently efficient. 

To predict the future of a page, we first collect the history of forks for user processes. Specifically, the OS monitors the number of forks that each process invokes. A low count for a process implies that there is little opportunity to exploit the process, and the OS does not need to fully track the write page faults for this process. 

In contrast, when a process invokes the fork system call more than a threshold, the system can expect the optimization opportunity. This happens with Redis, which periodically invokes forks to take in-memory snapshots, or with the shell script that forks multiple command-line commands. In response, the system starts to track the page faults for the process. 

improve brain

Next, we propose a method to predict the optimization opportunity from the history, assuming that the overall behavior of applications does not change significantly. To this end, we divide the process address space into fixed-sized regions. Each region maintains a bitmap, where each bit corresponds to a page in the region. A process is spawned with all bitmaps cleared, as for newly populated virtual memory areas (VMAs). When a part or entire VMA is unmapped, the bitmaps in the corresponding address range are also released. 

The bitmap is only allocated for the parts of VMA that are populated, and one 4 KB page information is summarized into one bit. Thus, the space overhead for the bitmaps is approximately 0.003% of the populated address space. Initially, writes are processed through the copy-on-write as is. 

A write access is trapped to the page fault handler, whereby the corresponding bitmap entry is set. Over time, the bitmap effectively captures the accesses to the region, and we can quantify the degree of the coverage. The coverage of a region is calculated as the percentage of copy-on-written pages out of all pages in the region, as follows:

improve cognitive function

Suppose a system uses 4 KB pages and the address space is divided into 2 MB regions. 

Then each region has 512 4 KB pages. If 300 pages are copied on writes, the coverage of the region is 300/512 × 100 = 58.6%. The higher the coverage of a region, the more the region can benefit from the optimization opportunity of the precopy. This coverage information is carried over the fork and used as a metric to determine the benefit of copying nearby pages. 

Specifically, if a memory region has high coverage, the pages in the region are likely to be copy-on-written eventually. Thus, it would be beneficial to precopy other pages in the region while processing a write page fault for a page. Whereas, optimization opportunity in precopying pages is little if the coverage is low. Thus, only the faulty page is copy-on-written by the page fault handler. 

Henceforth, we will refer to this scheme as coverage-based copy-on-write or CCoW for the rest of the paper. Figure 1 illustrates the concept of CCoW. There are two regions, regions 0 and 1, each comprising six pages. 

The pages with green shade are populated with copy-on-write. When the process invokes the fork system call, write permission for all pages, including the green ones, to be dropped during the fork. Let us assume that the threshold for determining the high-locality region is 60%. In region 0, four pages (pages 1, 2, 3, and 4) had been copied on write before the fork, providing a coverage of 4/6 = 66%. 

Thus, this region is considered to have high spatial locality, and all pages are copied to handle the page fault for page 3, as shaded in red. Whereas, the lower region provides a coverage of 33% as two out of six pages had been copy-on-written before the fork. 

Therefore, this region has a lower coverage than the threshold, implying the low spatial locality in the region. Thus, when page 9 is accessed for write, only the faulty page is copied on write in the page fault handler, just like the normal copy-on-write procedure.

improve memory


For more information:1950477648nn@gmail.com

You Might Also Like