mm: Introduce pagecache page access counter

Motivation
==========
To get overall statistics of page access pattern,
the ultimate method is to scan pagetable A bit.
But that's for page mapped in page table.

For unmapped pagecache page, PageReferenced bit
could be queried intervally, the precision depends
on the scan frequency. This could incur more
cpu consumption, as well as sophsicated code design.

What's real need is the page access counter,
either in hardware form or software implementation.

This patch tried to introduce the later, software
implementation of page access counter.

Howto
=====
Allocate additional space for access counter is
by no means costy and hard to maitain.
We can reuse mapcount in page structure, because
it only be valid for page mapped in page table.
For unmaped page cache, it's free!

In detail, introduce another PG_Mapped flag
to denote when mapcount is valid to show how many
times the page has been mapped in page table.
But when PG_Mapped is not set, store access
counter there.

Every buffered read/write will lookup pagecache,
so pagecache_get_page is a perfect place to add
the profile code. Moreover for fine granularity
control to the access counter, FGP_WRITE/FGP_ACCESSED
could be used to multiplex the counter useage.

e.g.
Additional code could set option to track read
access by FGP_ACCESSED, or respectively FGP_WRITE
to track write access.

Potential user
=============
a. Future in-kernel file LRU scan based implementation
   could be simplied greatly.
b. Can create user level interface to export the access
   counter.

Test
===
a. Boot/reboot ok
b. Need more sufficient test.

Signed-off-by: Fan Du <fan.du@intel.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
7 files changed