# Read, write to USB disk cache

**URL:** <https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061>\
**Category:** Installing and Using OpenWrt\
**Created:** [July 11, 2020, 1:27pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061 "2020-07-11T13:27:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toutatis](https://forum.openwrt.org/user_avatar/forum.openwrt.org/toutatis/32/35482_2.png) [@Toutatis](https://forum.openwrt.org/u/Toutatis)\
**Post date:** [July 11, 2020, 1:27pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/1 "2020-07-11T13:27:16Z")

</div>

Hello,  
Could you tell me how to purge, clear, the USB disk read/write cache with command line on ssh session.  
Thanks

---

<div class="post-metadata">

**Author:** ![eduperez](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eduperez/32/2066_2.png) [@eduperez](https://forum.openwrt.org/u/eduperez)\
**Post date:** [July 11, 2020, 2:51pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/2 "2020-07-11T14:51:43Z")

</div>

If you are going to extract the drive, the "mount" command will not finish untill all pending writes have finished.

Otherwise, there exists the "fsync" system call, and the "sync" command.

---

<div class="post-metadata">

**Author:** ![Toutatis](https://forum.openwrt.org/user_avatar/forum.openwrt.org/toutatis/32/35482_2.png) [@Toutatis](https://forum.openwrt.org/u/Toutatis)\
**Post date:** [July 11, 2020, 3:08pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/3 "2020-07-11T15:08:33Z")

</div>

Not exactly my purpose;  
After write, I want to purge the cache to measure the read time with disk access.  
I don't think the sync/fsync will purge the RAM cache I think it will **copy** the data in the disk.

---

<div class="post-metadata">

**Author:** ![eduperez](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eduperez/32/2066_2.png) [@eduperez](https://forum.openwrt.org/u/eduperez)\
**Post date:** [July 11, 2020, 5:26pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/4 "2020-07-11T17:26:19Z")

</div>

Yes, fsync will force pending writes to the drive, but it will also retain the cache in RAM. I do not know of a specific command to delete the cache, but unmounting the drive will surely have that effect.

---

<div class="post-metadata">

**Author:** ![Toutatis](https://forum.openwrt.org/user_avatar/forum.openwrt.org/toutatis/32/35482_2.png) [@Toutatis](https://forum.openwrt.org/u/Toutatis)\
**Post date:** [July 13, 2020, 4:51pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/5 "2020-07-13T16:51:32Z")

</div>

I found it [here](http://www.queryadmin.com/980/flush-clear-cached-memory-linux-server/)  
It's working for Openwrt

Many thanks

Edit

```
free -m
              total used free shared buff/cache available
Mem: 511968 185620 28996 332 297352 285400
Swap: 0 0 0
~# sync; echo 3 > /proc/sys/vm/drop_caches
~# free -m
              total used free shared buff/cache available
Mem: 511968 182460 323880 332 5628 304768
Swap: 0 0 0

```

---

<div class="post-metadata">

**Author:** ![tmomas](https://forum.openwrt.org/letter_avatar/tmomas/32/5_5575768a8748004e209b776fc1b2916d.png) [@tmomas](https://forum.openwrt.org/u/tmomas)\
**Post date:** [July 13, 2020, 7:20pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/6 "2020-07-13T19:20:44Z")

</div>

If your problem is solved, please consider marking this topic as [Solved]. See [How to mark a topic as [Solved]](https://forum.openwrt.org/t/how-to-mark-a-topic-as-solved/40174) for a short how-to.

---

<div class="post-metadata">

**Author:** ![system](https://forum.openwrt.org/uploads/default/original/3X/7/4/740520c71f00039bbf001045c682f0ecb25e905a.png) [@system](https://forum.openwrt.org/u/system)\
**Post date:** [July 23, 2020, 7:20pm UTC](https://forum.openwrt.org/t/read-write-to-usb-disk-cache/69061/7 "2020-07-23T19:20:46Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
