[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210420222902.scz3jvcirmpnjqnr@devvm1945.atn0.facebook.com>
Date: Tue, 20 Apr 2021 15:29:02 -0700
From: Saravanan D <saravanand@...com>
To: <axboe@...nel.dk>, <linux-block@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
CC: <jkkm@...com>, <tj@...nel.org>, <kernel-team@...com>,
Calvin Owens <calvinowens@...com>
Subject: Re: [PATCH] brd: expose number of allocated pages in debugfs
On Fri, Apr 16, 2021 at 02:18:29PM -0700, Saravanan D wrote:
> From: Calvin Owens <calvinowens@...com>
>
> While the maximum size of each ramdisk is defined either
> as a module parameter, or compile time default, it's impossible
> to know how many pages have currently been allocated by each
> ram%d device, since they're allocated when used and never freed.
>
> This patch creates a new directory at this location:
>
> ยป /sys/kernel/debug/ramdisk_pages/
>
> ...which will contain a file named "ram%d" for each instantiated
> ramdisk on the system. The file is read-only, and read() will
> output the number of pages currently held by that ramdisk.
>
Justification : We lose track how much memory a ramdisk is using as
pages once used are simply recycled but never freed.
In instances where we exhaust the size of the ramdisk with a file that
exceeds it, encounter ENOSPC and delete the file for mitigation;
df would show decrease in used and increase in available blocks
but the since we have touched all pages, the memory footprint of the
ramdisk does not reflect the blocks used/available count
...
[root@...alhost ~]# mkfs.ext2 /dev/ram15
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 4096 1k blocks and 1024 inodes
[root@...alhost ~]# mount /dev/ram15 /mnt/ram15/
[root@...alhost ~]# cat
/sys/kernel/debug/ramdisk_pages/ram15
58
[root@...neltest008.06.prn3 ~]# df /dev/ram15
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram15 3963 31 3728 1% /mnt/ram15
[root@...neltest008.06.prn3 ~]# dd if=/dev/urandom of=/mnt/ram15/test2
bs=1M count=5
dd: error writing '/mnt/ram15/test2': No space left on device
4+0 records in
3+0 records out
4005888 bytes (4.0 MB, 3.8 MiB) copied, 0.0446614 s, 89.7 MB/s
[root@...neltest008.06.prn3 ~]# df /mnt/ram15/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram15 3963 3960 0 100% /mnt/ram15
[root@...neltest008.06.prn3 ~]# cat
/sys/kernel/debug/ramdisk_pages/ram15
1024
[root@...neltest008.06.prn3 ~]# rm /mnt/ram15/test2
rm: remove regular file '/mnt/ram15/test2'? y
[root@...neltest008.06.prn3 /var]# df /dev/ram15
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram15 3963 31 3728 1% /mnt/ram15
# Acutal memory footprint
[root@...neltest008.06.prn3 /var]# cat
/sys/kernel/debug/ramdisk_pages/ram15
1024
...
This debugfs counter will always reveal the accurate number of
permanently allocated pages to the ramdisk.
Powered by blists - more mailing lists