Skip to content

Commit d559db0

Browse files
hkamezawatorvalds
authored andcommitted
mm: clean up mm_counter
Presently, per-mm statistics counter is defined by macro in sched.h This patch modifies it to - defined in mm.h as inlinf functions - use array instead of macro's name creation. This patch is for reducing patch size in future patch to modify implementation of per-mm counter. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Minchan Kim <minchan.kim@gmail.com> Cc: Christoph Lameter <cl@linux-foundation.org> Cc: Lee Schermerhorn <lee.schermerhorn@hp.com> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 19b629f commit d559db0

12 files changed

Lines changed: 174 additions & 101 deletions

File tree

‎fs/proc/task_mmu.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ unsigned long task_vsize(struct mm_struct *mm)
6565
int task_statm(struct mm_struct *mm, int *shared, int *text,
6666
int *data, int *resident)
6767
{
68-
*shared = get_mm_counter(mm, file_rss);
68+
*shared = get_mm_counter(mm, MM_FILEPAGES);
6969
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
7070
>> PAGE_SHIFT;
7171
*data = mm->total_vm - mm->shared_vm;
72-
*resident = *shared + get_mm_counter(mm, anon_rss);
72+
*resident = *shared + get_mm_counter(mm, MM_ANONPAGES);
7373
return mm->total_vm;
7474
}
7575

‎include/linux/mm.h‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,110 @@ extern int mprotect_fixup(struct vm_area_struct *vma,
870870
*/
871871
int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
872872
struct page **pages);
873+
/*
874+
* per-process(per-mm_struct) statistics.
875+
*/
876+
#if USE_SPLIT_PTLOCKS
877+
/*
878+
* The mm counters are not protected by its page_table_lock,
879+
* so must be incremented atomically.
880+
*/
881+
static inline void set_mm_counter(struct mm_struct *mm, int member, long value)
882+
{
883+
atomic_long_set(&mm->rss_stat.count[member], value);
884+
}
885+
886+
static inline unsigned long get_mm_counter(struct mm_struct *mm, int member)
887+
{
888+
return (unsigned long)atomic_long_read(&mm->rss_stat.count[member]);
889+
}
890+
891+
static inline void add_mm_counter(struct mm_struct *mm, int member, long value)
892+
{
893+
atomic_long_add(value, &mm->rss_stat.count[member]);
894+
}
895+
896+
static inline void inc_mm_counter(struct mm_struct *mm, int member)
897+
{
898+
atomic_long_inc(&mm->rss_stat.count[member]);
899+
}
900+
901+
static inline void dec_mm_counter(struct mm_struct *mm, int member)
902+
{
903+
atomic_long_dec(&mm->rss_stat.count[member]);
904+
}
905+
906+
#else /* !USE_SPLIT_PTLOCKS */
907+
/*
908+
* The mm counters are protected by its page_table_lock,
909+
* so can be incremented directly.
910+
*/
911+
static inline void set_mm_counter(struct mm_struct *mm, int member, long value)
912+
{
913+
mm->rss_stat.count[member] = value;
914+
}
915+
916+
static inline unsigned long get_mm_counter(struct mm_struct *mm, int member)
917+
{
918+
return mm->rss_stat.count[member];
919+
}
920+
921+
static inline void add_mm_counter(struct mm_struct *mm, int member, long value)
922+
{
923+
mm->rss_stat.count[member] += value;
924+
}
925+
926+
static inline void inc_mm_counter(struct mm_struct *mm, int member)
927+
{
928+
mm->rss_stat.count[member]++;
929+
}
930+
931+
static inline void dec_mm_counter(struct mm_struct *mm, int member)
932+
{
933+
mm->rss_stat.count[member]--;
934+
}
935+
936+
#endif /* !USE_SPLIT_PTLOCKS */
937+
938+
static inline unsigned long get_mm_rss(struct mm_struct *mm)
939+
{
940+
return get_mm_counter(mm, MM_FILEPAGES) +
941+
get_mm_counter(mm, MM_ANONPAGES);
942+
}
943+
944+
static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
945+
{
946+
return max(mm->hiwater_rss, get_mm_rss(mm));
947+
}
948+
949+
static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
950+
{
951+
return max(mm->hiwater_vm, mm->total_vm);
952+
}
953+
954+
static inline void update_hiwater_rss(struct mm_struct *mm)
955+
{
956+
unsigned long _rss = get_mm_rss(mm);
957+
958+
if ((mm)->hiwater_rss < _rss)
959+
(mm)->hiwater_rss = _rss;
960+
}
961+
962+
static inline void update_hiwater_vm(struct mm_struct *mm)
963+
{
964+
if (mm->hiwater_vm < mm->total_vm)
965+
mm->hiwater_vm = mm->total_vm;
966+
}
967+
968+
static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
969+
struct mm_struct *mm)
970+
{
971+
unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
972+
973+
if (*maxrss < hiwater_rss)
974+
*maxrss = hiwater_rss;
975+
}
976+
873977

874978
/*
875979
* A callback you can register to apply pressure to ageable caches.

‎include/linux/mm_types.h‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ struct address_space;
2424

2525
#define USE_SPLIT_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
2626

27-
#if USE_SPLIT_PTLOCKS
28-
typedef atomic_long_t mm_counter_t;
29-
#else /* !USE_SPLIT_PTLOCKS */
30-
typedef unsigned long mm_counter_t;
31-
#endif /* !USE_SPLIT_PTLOCKS */
32-
3327
/*
3428
* Each physical page in the system has a struct page associated with
3529
* it to keep track of whatever it is we are using the page for at the
@@ -201,6 +195,22 @@ struct core_state {
201195
struct completion startup;
202196
};
203197

198+
enum {
199+
MM_FILEPAGES,
200+
MM_ANONPAGES,
201+
NR_MM_COUNTERS
202+
};
203+
204+
#if USE_SPLIT_PTLOCKS
205+
struct mm_rss_stat {
206+
atomic_long_t count[NR_MM_COUNTERS];
207+
};
208+
#else /* !USE_SPLIT_PTLOCKS */
209+
struct mm_rss_stat {
210+
unsigned long count[NR_MM_COUNTERS];
211+
};
212+
#endif /* !USE_SPLIT_PTLOCKS */
213+
204214
struct mm_struct {
205215
struct vm_area_struct * mmap; /* list of VMAs */
206216
struct rb_root mm_rb;
@@ -227,11 +237,6 @@ struct mm_struct {
227237
* by mmlist_lock
228238
*/
229239

230-
/* Special counters, in some configurations protected by the
231-
* page_table_lock, in other configurations by being atomic.
232-
*/
233-
mm_counter_t _file_rss;
234-
mm_counter_t _anon_rss;
235240

236241
unsigned long hiwater_rss; /* High-watermark of RSS usage */
237242
unsigned long hiwater_vm; /* High-water virtual memory usage */
@@ -244,6 +249,12 @@ struct mm_struct {
244249

245250
unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
246251

252+
/*
253+
* Special counters, in some configurations protected by the
254+
* page_table_lock, in other configurations by being atomic.
255+
*/
256+
struct mm_rss_stat rss_stat;
257+
247258
struct linux_binfmt *binfmt;
248259

249260
cpumask_t cpu_vm_mask;

‎include/linux/sched.h‎

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -396,60 +396,6 @@ extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
396396
static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
397397
#endif
398398

399-
#if USE_SPLIT_PTLOCKS
400-
/*
401-
* The mm counters are not protected by its page_table_lock,
402-
* so must be incremented atomically.
403-
*/
404-
#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
405-
#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
406-
#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
407-
#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
408-
#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
409-
410-
#else /* !USE_SPLIT_PTLOCKS */
411-
/*
412-
* The mm counters are protected by its page_table_lock,
413-
* so can be incremented directly.
414-
*/
415-
#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
416-
#define get_mm_counter(mm, member) ((mm)->_##member)
417-
#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
418-
#define inc_mm_counter(mm, member) (mm)->_##member++
419-
#define dec_mm_counter(mm, member) (mm)->_##member--
420-
421-
#endif /* !USE_SPLIT_PTLOCKS */
422-
423-
#define get_mm_rss(mm) \
424-
(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
425-
#define update_hiwater_rss(mm) do { \
426-
unsigned long _rss = get_mm_rss(mm); \
427-
if ((mm)->hiwater_rss < _rss) \
428-
(mm)->hiwater_rss = _rss; \
429-
} while (0)
430-
#define update_hiwater_vm(mm) do { \
431-
if ((mm)->hiwater_vm < (mm)->total_vm) \
432-
(mm)->hiwater_vm = (mm)->total_vm; \
433-
} while (0)
434-
435-
static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
436-
{
437-
return max(mm->hiwater_rss, get_mm_rss(mm));
438-
}
439-
440-
static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
441-
struct mm_struct *mm)
442-
{
443-
unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
444-
445-
if (*maxrss < hiwater_rss)
446-
*maxrss = hiwater_rss;
447-
}
448-
449-
static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
450-
{
451-
return max(mm->hiwater_vm, mm->total_vm);
452-
}
453399

454400
extern void set_dumpable(struct mm_struct *mm, int value);
455401
extern int get_dumpable(struct mm_struct *mm);

‎kernel/fork.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p)
455455
(current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
456456
mm->core_state = NULL;
457457
mm->nr_ptes = 0;
458-
set_mm_counter(mm, file_rss, 0);
459-
set_mm_counter(mm, anon_rss, 0);
458+
memset(&mm->rss_stat, 0, sizeof(mm->rss_stat));
460459
spin_lock_init(&mm->page_table_lock);
461460
mm->free_area_cache = TASK_UNMAPPED_BASE;
462461
mm->cached_hole_size = ~0UL;

‎kernel/tsacct.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/tsacct_kern.h>
2222
#include <linux/acct.h>
2323
#include <linux/jiffies.h>
24+
#include <linux/mm.h>
2425

2526
/*
2627
* fill in basic accounting fields

‎mm/filemap_xip.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ __xip_unmap (struct address_space * mapping,
194194
flush_cache_page(vma, address, pte_pfn(*pte));
195195
pteval = ptep_clear_flush_notify(vma, address, pte);
196196
page_remove_rmap(page);
197-
dec_mm_counter(mm, file_rss);
197+
dec_mm_counter(mm, MM_FILEPAGES);
198198
BUG_ON(pte_dirty(pteval));
199199
pte_unmap_unlock(pte, ptl);
200200
page_cache_release(page);

‎mm/fremap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void zap_pte(struct mm_struct *mm, struct vm_area_struct *vma,
4040
page_remove_rmap(page);
4141
page_cache_release(page);
4242
update_hiwater_rss(mm);
43-
dec_mm_counter(mm, file_rss);
43+
dec_mm_counter(mm, MM_FILEPAGES);
4444
}
4545
} else {
4646
if (!pte_file(pte))

0 commit comments

Comments
 (0)