Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report