tobert / pcstat

Page Cache stat: get page cache stats for files on Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pcstat to show the top [number] cached file in the linux os globally

silenceshell opened this issue · comments

Does anyone need this feature? Use pcstat to show the top [number] cached file in the linux os globally.

For example, I know that the os caches a lot of memories, but I donnot know which big files are being cached by the os.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        6.4G        2.3G        1.1G        6.9G        7.7G
Swap:          975M        268K        975M

I add a new param --top to pcstat, it reads the /proc/[pid]/stat files, and finds those processes who's rss is not 0, then collects all the files opened by those processes, gets stats and sort them by cached pages.

Here is an example:

$ sudo pcstat --top 3  --bname  
+-------------+----------------+------------+-----------+---------+
| Name        | Size (bytes)   | Pages      | Cached    | Percent |
|-------------+----------------+------------+-----------+---------|
| chrome      | 114911208      | 28055      | 25476     | 090.807 |
| pycharm.jar | 95177431       | 23237      | 11479     | 049.400 |
| atom        | 62641344       | 15294      | 10578     | 069.164 |
+-------------+----------------+------------+-----------+---------+

That sounds handy.

I'm happy to review & merge the code if you submit a pull request or point me at your fork :)