Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use Hcache to see who is occupying the system Buffer&Cache?

Shulou Source: shulou.com Published: 2022-06-02 06:45:31 09月11日 Update

1. Hcache

One of the problems that Linux users may often encounter is that most of the memory is taken up by Buffer and Cache, but sometimes we want to know what's going on in Cache without an intuitive tool. Today I'll introduce you to hcache, a gadget that can see which files are currently cached in Linux.

Hcache author: Ibrahim

A few days ago, I saw someone write a pcstat in go to check whether a file is cached (the author's purpose is to tune the database). You can also check which files are cached according to the process pid, but you cannot see which files are cache throughout the operating system. Therefore, I wrote a hcache based on pcstat and added the feature of viewing the first top files of the current operating system cache. You can download it here for trial. If you have any suggestions, you are welcome to give me feedback: hubottle@gmail.com.

Official website: https://github.com/silenceshell/hcache

II. Installation

Hcache is developed using GO and is very easy to install and works right out of the box.

$wget http://7xir15.com1.z0.glb.clouddn.com/hcache

$chmod + x hcache

$mv hcache / usr/local/bin/

one

two

three

$wget http://7xir15.com1.z0.glb.clouddn.com/hcache

$chmod + x hcache

$mv hcache / usr/local/bin/

III. Use

$free-m

Total used free shared buff/cache available

Mem: 7823 1952 174 9 5696 5518

Swap: 0 0 0

one

two

three

four

$free-m

Total used free shared buff/cache available

Mem: 7823 1952 174 9 5696 5518

Swap: 0 0 0

Check out the 3 processes that use Cache the most.

$hcache-- top 3

+-+

| | Name | Size (bytes) | Pages | Cached | Percent | |

|-- +-|

| | / usr/bin/dockerd | 33368760 | 8147 | 8147 | 100.000 | |

| | / usr/bin/docker-containerd | 7115584 | 1738 | 1738 | 100.000 | |

| | / etc/udev/hwdb.bin | 6711310 | 1639 | 1639 | 100.000 | |

+-+

one

two

three

four

five

six

seven

eight

$hcache-- top 3

+-+

| | Name | Size (bytes) | Pages | Cached | Percent | |

|-- +-|

| | / usr/bin/dockerd | 33368760 | 8147 | 8147 | 100.000 | |

| | / usr/bin/docker-containerd | 7115584 | 1738 | 1738 | 100.000 | |

| | / etc/udev/hwdb.bin | 6711310 | 1639 | 1639 | 100.000 | |

+-+

By default, the full path of the cache file is displayed, which is relatively long. You can use the-- bname option to display only the file name.

$hcache-top 3-bname

+-+

| | Name | Size (bytes) | Pages | Cached | Percent | |

| |-+-|

| | dockerd | 33368760 | 8147 | 8147 | 100.000 | |

| | docker-containerd | 7115584 | 1738 | 1738 | 100.000 | |

| | hwdb.bin | 6711310 | 1639 | 1639 | 100.000 | |

+-+

one

two

three

four

five

six

seven

eight

$hcache-top 3-bname

+-+

| | Name | Size (bytes) | Pages | Cached | Percent | |

| |-+-|

| | dockerd | 33368760 | 8147 | 8147 | 100.000 | |

| | docker-containerd | 7115584 | 1738 | 1738 | 100.000 | |

| | hwdb.bin | 6711310 | 1639 | 1639 | 100.000 | |

+-+

View the Cache usage of the specified process.

$hcache-pid 2903-bname

one

$hcache-pid 2903-bname

You can also output in a specified format, such as JSON, plain text. For more usage, please refer to hcache-h.

$hcache-h

Usage of hcache:

-bname

Convert paths to basename to narrow the output

-histo

Print a simple histogram instead of raw data

-json

Return data in JSON format

-nohdr

Omit the header from terse & text output

-pid int

Show all open maps for the given pid

-plain

Return data with no box characters

-pps

Include the per-page status in JSON output

-terse

Show terse output

-top int

Convert paths to basename to narrow the output

-unicode

Return data with unicode box characters

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

$hcache-h

Usage of hcache:

-bname

Convert paths to basename to narrow the output

-histo

Print a simple histogram instead of raw data

-json

Return data in JSON format

-nohdr

Omit the header from terse & text output

-pid int

Show all open maps for the given pid

-plain

Return data with no box characters

-pps

Include the per-page status in JSON output

-terse

Show terse output

-top int

Convert paths to basename to narrow the output

-unicode

Return data with unicode box characters

It's over.

Tags: File cache process system operating system author tool situation intuitive personal usage memory content most suggestions data database file name text method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Docker Apple Shulou Tech Info