2022-12-26 02:39:49

by Yang Yang

[permalink] [raw]
Subject: [PATCH v4 3/6] ksm: count all zero pages placed by KSM

From: xu xin <[email protected]>

As pages_sharing and pages_shared don't include the number of zero pages
merged by KSM, we cannot know how many pages are zero pages placed by KSM
when enabling use_zero_pages, which leads to KSM not being transparent with
all actual merged pages by KSM. In the early days of use_zero_pages,
zero-pages was unable to get unshared by the ways like MADV_UNMERGEABLE so
it's hard to count how many times one of those zeropages was then unmerged.

But now, unsharing KSM-placed zero page accurately has been achieved, so we
can easily count both how many times a page full of zeroes was merged with
zero-page and how many times one of those pages was then unmerged. and so,
it helps to estimate memory demands when each and every shared page could
get unshared.

So we add zero_pages_sharing under /sys/kernel/mm/ksm/ to show the number
of all zero pages placed by KSM.

Signed-off-by: xu xin <[email protected]>
Cc: Claudio Imbrenda <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Xuexin Jiang <[email protected]>
Reviewed-by: Xiaokai Ran <[email protected]>
Reviewed-by: Yang Yang <[email protected]>
---
mm/ksm.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index b7fc7d86d11a..e02cc89512cd 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -276,6 +276,9 @@ static unsigned int zero_checksum __read_mostly;
/* Whether to merge empty (zeroed) pages with actual zero pages */
static bool ksm_use_zero_pages __read_mostly;

+/* The number of zero pages placed by KSM use_zero_pages */
+static unsigned long ksm_zero_pages_sharing;
+
#ifdef CONFIG_NUMA
/* Zeroed when merging across nodes is not allowed */
static unsigned int ksm_merge_across_nodes = 1;
@@ -789,8 +792,10 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node,
*/
static inline void clean_rmap_item_zero_flag(struct ksm_rmap_item *rmap_item)
{
- if (rmap_item->address & ZERO_PAGE_FLAG)
+ if (rmap_item->address & ZERO_PAGE_FLAG) {
+ ksm_zero_pages_sharing--;
rmap_item->address &= PAGE_MASK;
+ }
}

/* Only called when rmap_item is going to be freed */
@@ -2109,8 +2114,10 @@ static int try_to_merge_with_kernel_zero_page(struct ksm_rmap_item *rmap_item,
if (vma) {
err = try_to_merge_one_page(vma, page,
ZERO_PAGE(rmap_item->address));
- if (!err)
+ if (!err) {
rmap_item->address |= ZERO_PAGE_FLAG;
+ ksm_zero_pages_sharing++;
+ }
} else {
/* If the vma is out of date, we do not need to continue. */
err = 0;
@@ -3224,6 +3231,13 @@ static ssize_t pages_volatile_show(struct kobject *kobj,
}
KSM_ATTR_RO(pages_volatile);

+ssize_t zero_pages_sharing_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%ld\n", ksm_zero_pages_sharing);
+}
+KSM_ATTR_RO(zero_pages_sharing);
+
static ssize_t stable_node_dups_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -3279,6 +3293,7 @@ static struct attribute *ksm_attrs[] = {
&pages_sharing_attr.attr,
&pages_unshared_attr.attr,
&pages_volatile_attr.attr,
+ &zero_pages_sharing_attr.attr,
&full_scans_attr.attr,
#ifdef CONFIG_NUMA
&merge_across_nodes_attr.attr,
--
2.15.2


2022-12-26 07:39:59

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 3/6] ksm: count all zero pages placed by KSM

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.2-rc1 next-20221220]
[cannot apply to shuah-kselftest/next shuah-kselftest/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/yang-yang29-zte-com-cn/ksm-abstract-the-function-try_to_get_old_rmap_item/20221226-100925
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/202212261004269680139%40zte.com.cn
patch subject: [PATCH v4 3/6] ksm: count all zero pages placed by KSM
config: x86_64-rhel-8.3-rust
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/7a5bf9867fe97f03edb941924c803327a1c2facb
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review yang-yang29-zte-com-cn/ksm-abstract-the-function-try_to_get_old_rmap_item/20221226-100925
git checkout 7a5bf9867fe97f03edb941924c803327a1c2facb
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> mm/ksm.c:3238:9: warning: no previous prototype for function 'zero_pages_sharing_show' [-Wmissing-prototypes]
ssize_t zero_pages_sharing_show(struct kobject *kobj,
^
mm/ksm.c:3238:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
ssize_t zero_pages_sharing_show(struct kobject *kobj,
^
static
1 warning generated.


vim +/zero_pages_sharing_show +3238 mm/ksm.c

3237
> 3238 ssize_t zero_pages_sharing_show(struct kobject *kobj,
3239 struct kobj_attribute *attr, char *buf)
3240 {
3241 return sysfs_emit(buf, "%ld\n", ksm_zero_pages_sharing);
3242 }
3243 KSM_ATTR_RO(zero_pages_sharing);
3244

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.70 kB)
config (170.17 kB)
Download all attachments

2022-12-26 09:39:01

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 3/6] ksm: count all zero pages placed by KSM

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.2-rc1 next-20221226]
[cannot apply to shuah-kselftest/next shuah-kselftest/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/yang-yang29-zte-com-cn/ksm-abstract-the-function-try_to_get_old_rmap_item/20221226-100925
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/202212261004269680139%40zte.com.cn
patch subject: [PATCH v4 3/6] ksm: count all zero pages placed by KSM
config: x86_64-rhel-8.3-kselftests
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/7a5bf9867fe97f03edb941924c803327a1c2facb
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review yang-yang29-zte-com-cn/ksm-abstract-the-function-try_to_get_old_rmap_item/20221226-100925
git checkout 7a5bf9867fe97f03edb941924c803327a1c2facb
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> mm/ksm.c:3238:9: warning: no previous prototype for 'zero_pages_sharing_show' [-Wmissing-prototypes]
3238 | ssize_t zero_pages_sharing_show(struct kobject *kobj,
| ^~~~~~~~~~~~~~~~~~~~~~~


vim +/zero_pages_sharing_show +3238 mm/ksm.c

3237
> 3238 ssize_t zero_pages_sharing_show(struct kobject *kobj,
3239 struct kobj_attribute *attr, char *buf)
3240 {
3241 return sysfs_emit(buf, "%ld\n", ksm_zero_pages_sharing);
3242 }
3243 KSM_ATTR_RO(zero_pages_sharing);
3244

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.21 kB)
config (174.55 kB)
Download all attachments