Unverified Commit db19e032 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!11464 mm/ksm: fix ksm_zero_pages accounting

Merge Pull Request from: @ci-robot 
 
PR sync from: Kaixiong Yu <yukaixiong@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Z55PPDGNAZIO6A7WJYXA53JIGDY5J4AT/ 
fix the bug from mainline inclusion commits e2942062
("ksm: count all zero pages placed by KSM") and 6080d19f
("ksm: add ksm zero pages for each process")

Chengming Zhou (1):
  mm/ksm: fix ksm_zero_pages accounting

Kaixiong Yu (1):
  mm_types: Fix kabi breakage in struct mm_struct


-- 
2.25.1
 
 
 
Link:https://gitee.com/openeuler/kernel/pulls/11464

 

Reviewed-by: default avatarZhang Peng <zhangpeng362@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 40f68978 b27a936d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3292,7 +3292,7 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
	mm = get_task_mm(task);
	if (mm) {
		seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items);
		seq_printf(m, "ksm_zero_pages %lu\n", mm->ksm_zero_pages);
		seq_printf(m, "ksm_zero_pages %ld\n", mm_ksm_zero_pages(mm));
		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
		mmput(mm);
+14 −3
Original line number Diff line number Diff line
@@ -33,16 +33,27 @@ void __ksm_exit(struct mm_struct *mm);
 */
#define is_ksm_zero_pte(pte)	(is_zero_pfn(pte_pfn(pte)) && pte_dirty(pte))

extern unsigned long ksm_zero_pages;
extern atomic_long_t ksm_zero_pages;

static inline void ksm_map_zero_page(struct mm_struct *mm)
{
	atomic_long_inc(&ksm_zero_pages);
	atomic_long_inc(&mm->ksm_zero_pages);
}

static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte)
{
	if (is_ksm_zero_pte(pte)) {
		ksm_zero_pages--;
		mm->ksm_zero_pages--;
		atomic_long_dec(&ksm_zero_pages);
		atomic_long_dec(&mm->ksm_zero_pages);
	}
}

static inline long mm_ksm_zero_pages(struct mm_struct *mm)
{
	return atomic_long_read(&mm->ksm_zero_pages);
}

static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
{
	int ret;
+2 −1
Original line number Diff line number Diff line
@@ -949,7 +949,8 @@ struct mm_struct {
		 * Represent how many empty pages are merged with kernel zero
		 * pages when enabling KSM use_zero_pages.
		 */
		unsigned long ksm_zero_pages;
		KABI_REPLACE(unsigned long ksm_zero_pages,
			    atomic_long_t ksm_zero_pages)
#endif /* CONFIG_KSM */
#ifdef CONFIG_LRU_GEN
		struct {
+5 −6
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ static unsigned int zero_checksum __read_mostly;
static bool ksm_use_zero_pages __read_mostly;

/* The number of zero pages which is placed by KSM */
unsigned long ksm_zero_pages;
atomic_long_t ksm_zero_pages = ATOMIC_LONG_INIT(0);

#ifdef CONFIG_NUMA
/* Zeroed when merging across nodes is not allowed */
@@ -1246,8 +1246,7 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
		 * the dirty bit in zero page's PTE is set.
		 */
		newpte = pte_mkdirty(pte_mkspecial(pfn_pte(page_to_pfn(kpage), vma->vm_page_prot)));
		ksm_zero_pages++;
		mm->ksm_zero_pages++;
		ksm_map_zero_page(mm);
		/*
		 * We're replacing an anonymous page with a zero page, which is
		 * not anonymous. We need to do proper accounting otherwise we
@@ -3113,7 +3112,7 @@ static void wait_while_offlining(void)

long ksm_process_profit(struct mm_struct *mm)
{
	return (long)(mm->ksm_merging_pages + mm->ksm_zero_pages) * PAGE_SIZE -
	return (long)(mm->ksm_merging_pages + mm_ksm_zero_pages(mm)) * PAGE_SIZE -
		mm->ksm_rmap_items * sizeof(struct ksm_rmap_item);
}

@@ -3391,7 +3390,7 @@ KSM_ATTR_RO(pages_volatile);
static ssize_t ksm_zero_pages_show(struct kobject *kobj,
				struct kobj_attribute *attr, char *buf)
{
	return sysfs_emit(buf, "%ld\n", ksm_zero_pages);
	return sysfs_emit(buf, "%ld\n", atomic_long_read(&ksm_zero_pages));
}
KSM_ATTR_RO(ksm_zero_pages);

@@ -3400,7 +3399,7 @@ static ssize_t general_profit_show(struct kobject *kobj,
{
	long general_profit;

	general_profit = (ksm_pages_sharing + ksm_zero_pages) * PAGE_SIZE -
	general_profit = (ksm_pages_sharing + atomic_long_read(&ksm_zero_pages)) * PAGE_SIZE -
				ksm_rmap_items * sizeof(struct ksm_rmap_item);

	return sysfs_emit(buf, "%ld\n", general_profit);