1. 03 Oct, 2022 38 commits
  2. 27 Sep, 2022 2 commits
    • xu xin's avatar
      ksm: add profit monitoring documentation · 21b7bdb5
      xu xin authored
      Add the description of KSM profit and how to determine it separately in
      system-wide range and inner a single process.
      
      Link: https://lkml.kernel.org/r/20220830144003.299870-1-xu.xin16@zte.com.cnSigned-off-by: default avatarxu xin <xu.xin16@zte.com.cn>
      Reviewed-by: default avatarXiaokai Ran <ran.xiaokai@zte.com.cn>
      Reviewed-by: default avatarYang Yang <yang.yang29@zte.com.cn>
      Reviewed-by: default avatarBagas Sanjaya <bagasdotme@gmail.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Izik Eidus <izik.eidus@ravellosystems.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      21b7bdb5
    • xu xin's avatar
      ksm: count allocated ksm rmap_items for each process · cb4df4ca
      xu xin authored
      Patch series "ksm: count allocated rmap_items and update documentation",
      v5.
      
      KSM can save memory by merging identical pages, but also can consume
      additional memory, because it needs to generate rmap_items to save each
      scanned page's brief rmap information.
      
      To determine how beneficial the ksm-policy (like madvise), they are using
      brings, so we add a new interface /proc/<pid>/ksm_stat for each process
      The value "ksm_rmap_items" in it indicates the total allocated ksm
      rmap_items of this process.
      
      The detailed description can be seen in the following patches' commit
      message.
      
      
      This patch (of 2):
      
      KSM can save memory by merging identical pages, but also can consume
      additional memory, because it needs to generate rmap_items to save each
      scanned page's brief rmap information.  Some of these pages may be merged,
      but some may not be abled to be merged after being checked several times,
      which are unprofitable memory consumed.
      
      The information about whether KSM save memory or consume memory in
      system-wide range can be determined by the comprehensive calculation of
      pages_sharing, pages_shared, pages_unshared and pages_volatile.  A simple
      approximate calculation:
      
      	profit =~ pages_sharing * sizeof(page) - (all_rmap_items) *
      	         sizeof(rmap_item);
      
      where all_rmap_items equals to the sum of pages_sharing, pages_shared,
      pages_unshared and pages_volatile.
      
      But we cannot calculate this kind of ksm profit inner single-process wide
      because the information of ksm rmap_item's number of a process is lacked. 
      For user applications, if this kind of information could be obtained, it
      helps upper users know how beneficial the ksm-policy (like madvise) they
      are using brings, and then optimize their app code.  For example, one
      application madvise 1000 pages as MERGEABLE, while only a few pages are
      really merged, then it's not cost-efficient.
      
      So we add a new interface /proc/<pid>/ksm_stat for each process in which
      the value of ksm_rmap_itmes is only shown now and so more values can be
      added in future.
      
      So similarly, we can calculate the ksm profit approximately for a single
      process by:
      
      	profit =~ ksm_merging_pages * sizeof(page) - ksm_rmap_items *
      		 sizeof(rmap_item);
      
      where ksm_merging_pages is shown at /proc/<pid>/ksm_merging_pages, and
      ksm_rmap_items is shown in /proc/<pid>/ksm_stat.
      
      Link: https://lkml.kernel.org/r/20220830143731.299702-1-xu.xin16@zte.com.cn
      Link: https://lkml.kernel.org/r/20220830143838.299758-1-xu.xin16@zte.com.cnSigned-off-by: default avatarxu xin <xu.xin16@zte.com.cn>
      Reviewed-by: default avatarXiaokai Ran <ran.xiaokai@zte.com.cn>
      Reviewed-by: default avatarYang Yang <yang.yang29@zte.com.cn>
      Signed-off-by: default avatarCGEL ZTE <cgel.zte@gmail.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Bagas Sanjaya <bagasdotme@gmail.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Izik Eidus <izik.eidus@ravellosystems.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      cb4df4ca