Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4294621f authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds
Browse files

[PATCH] mm: rss = file_rss + anon_rss



I was lazy when we added anon_rss, and chose to change as few places as
possible.  So currently each anonymous page has to be counted twice, in rss
and in anon_rss.  Which won't be so good if those are atomic counts in some
configurations.

Change that around: keep file_rss and anon_rss separately, and add them
together (with get_mm_rss macro) when the total is needed - reading two
atomics is much cheaper than updating two atomics.  And update anon_rss
upfront, typically in memory.c, not tucked away in page_add_anon_rmap.

Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 404351e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -330,7 +330,7 @@ void install_arg_page(struct vm_area_struct *vma,
		pte_unmap(pte);
		goto out;
	}
	inc_mm_counter(mm, rss);
	inc_mm_counter(mm, anon_rss);
	lru_cache_add_active(page);
	set_pte_at(mm, address, pte, pte_mkdirty(pte_mkwrite(mk_pte(
					page, vma->vm_page_prot))));
+1 −1
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
		jiffies_to_clock_t(it_real_value),
		start_time,
		vsize,
		mm ? get_mm_counter(mm, rss) : 0, /* you might want to shift this left 3 */
		mm ? get_mm_rss(mm) : 0,
	        rsslim,
		mm ? mm->start_code : 0,
		mm ? mm->end_code : 0,
+3 −5
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ char *task_mem(struct mm_struct *mm, char *buffer)
		"VmPTE:\t%8lu kB\n",
		(mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
		mm->locked_vm << (PAGE_SHIFT-10),
		get_mm_counter(mm, rss) << (PAGE_SHIFT-10),
		get_mm_rss(mm) << (PAGE_SHIFT-10),
		data << (PAGE_SHIFT-10),
		mm->stack_vm << (PAGE_SHIFT-10), text, lib,
		(PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
@@ -44,13 +44,11 @@ unsigned long task_vsize(struct mm_struct *mm)
int task_statm(struct mm_struct *mm, int *shared, int *text,
	       int *data, int *resident)
{
	int rss = get_mm_counter(mm, rss);

	*shared = rss - get_mm_counter(mm, anon_rss);
	*shared = get_mm_counter(mm, file_rss);
	*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
								>> PAGE_SHIFT;
	*data = mm->total_vm - mm->shared_vm;
	*resident = rss;
	*resident = *shared + get_mm_counter(mm, anon_rss);
	return mm->total_vm;
}

+3 −1
Original line number Diff line number Diff line
@@ -254,6 +254,8 @@ extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
#define inc_mm_counter(mm, member) (mm)->_##member++
#define dec_mm_counter(mm, member) (mm)->_##member--
#define get_mm_rss(mm) ((mm)->_file_rss + (mm)->_anon_rss)

typedef unsigned long mm_counter_t;

struct mm_struct {
@@ -286,7 +288,7 @@ struct mm_struct {
	unsigned long exec_vm, stack_vm, reserved_vm, def_flags, nr_ptes;

	/* Special counters protected by the page_table_lock */
	mm_counter_t _rss;
	mm_counter_t _file_rss;
	mm_counter_t _anon_rss;

	unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
+1 −1
Original line number Diff line number Diff line
@@ -553,7 +553,7 @@ void acct_update_integrals(struct task_struct *tsk)
		if (delta == 0)
			return;
		tsk->acct_stimexpd = tsk->stime;
		tsk->acct_rss_mem1 += delta * get_mm_counter(tsk->mm, rss);
		tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm);
		tsk->acct_vm_mem1 += delta * tsk->mm->total_vm;
	}
}
Loading