Skip to content

ksm: take dirty bit as reference to avoid volatile pages scanning

Nai Xia kvm linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 10 repliesIn review
  2. v12 patches 2 repliesSuperseded

V1 log from the cover letter

Currently, ksm uses page checksum to detect volatile pages. Izik Eidus suggested that we could use pte dirty bit to optimize. This patch series adds this new logic.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2ksm: take dirty bit as reference to avoid volatile pages scanningarch/x86/mm/hugetlbpage.c include/linux/rmap.h mm/filemap_xip.c +1 more+72 -233 replies
2/2ksm: take dirty bit as reference to avoid volatile pages scanningmm/ksm.c+155 -345 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchIzik Eidus
SeriesA-b
1/2
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH 0/2 V2] ksm: take dirty bit as reference to avoid volatile pages scanning

Compared to the first version, this patch set addresses the problem of dirty bit updating of virtual machines, by adding two mmu_notifier interfaces. So it can now track the volatile working set inside KVM guest OS.

V1 log:
Currently, ksm uses page checksum to detect volatile pages. Izik Eidus suggested that we could use pte dirty bit to optimize. This patch series adds this new logic.

Preliminary benchmarks show that the scan speed is improved by up to 16 times on volatile transparent huge pages and up to 8 times on volatile regular pages.

Following is the test program to show this top speed up (you need to make ksmd takes about more than 90% of the cpu and watch the ksm/full_scans).

  #include <stdio.h>
  #include <stdlib.h>
  #include <errno.h>
  #include <string.h>
  #include <unistd.h>
  #include <sys/mman.h>
  
  #define MADV_MERGEABLE   12
  
  
  #define SIZE (2000*1024*1024)
  #define PAGE_SIZE 4096
  
  int main(int argc, char **argv)
  {
        unsigned char *p;
        int j;
        int ret;
          p = mmap(NULL, SIZE, PROT_WRITE|PROT_READ,
                   MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
        
        if (p == MAP_FAILED) {
                printf("mmap error\n");
                return 0;
        }
      
          ret = madvise(p, SIZE, MADV_MERGEABLE);
      
          if (ret==-1) {
                  printf("madvise failed \n");
                  return 0;
          }
  
        
        memset(p, 1, SIZE);
  
        while (1) {
                for (j=0; j<SIZE; j+=PAGE_SIZE) {
                        *((long*)(p+j+PAGE_SIZE-4)) = random();
                }
        }
  
        return 0;

}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>