[OpenWrt-Devel] config: extend small_flash feature

Message ID 20180530132137.9530-1-monkeh@monkeh.net
State Superseded
Headers show
Series
  • [OpenWrt-Devel] config: extend small_flash feature
Related show

Commit Message

Alex Maclean May 30, 2018, 1:21 p.m.
Extend the small_flash feature to disable swap, core dumps, and
kernel debug info, and change the squashfs block size to 1024KiB.

This saves approximately 18K in the kernel image on ath79, and 64K in
the rootfs.

Signed-off-by: Alex Maclean <monkeh@monkeh.net>
---
 config/Config-images.in | 1 +
 config/Config-kernel.in | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Martin Tippmann May 30, 2018, 5:22 p.m. | #1
On Wed, May 30, 2018 at 3:21 PM, Alex Maclean <monkeh@monkeh.net> wrote:
> change the squashfs block size to 1024KiB.

This might cause a problem with memory. You might also want to change

CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE from 3 to 1

in the kernel config.
https://cateee.net/lkddb/web-lkddb/SQUASHFS_FRAGMENT_CACHE_SIZE.html

This defines the blocks that are stored decompressed in memory, as far
as I know this memory is not easily reclaimable and you might run into
issues with a cache size of 3 and 1024kb blocks.
If someone might want to some tests on ar71xx - cat /proc/meminfo -
MemAvailable should be higher after doing something like find /usr |
xargs md5sum

Maybe I'll find the time to do some tests, but this has quite an
impact on free memory for 32mb devices.

regards
Martin
Lucian Cristian June 1, 2018, 11:34 a.m. | #2
On 30.05.2018 20:22, Martin Tippmann wrote:
> find /usr |
> xargs md5sum

I made the test on tl-wr841n-v9 with luci selected

these are the changes to squashfs

--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -149,8 +149,15 @@ menu "Target Images"
                         int "Block size (in KiB)"
                         depends on TARGET_ROOTFS_SQUASHFS
                         default 64 if LOW_MEMORY_FOOTPRINT
+                       default 1024 if (SMALL_FLASH && 
!LOW_MEMORY_FOOTPRINT)
                         default 256

+               config SQUASHFS_FRAGMENT_CACHE_SIZE
+                       int "Number of fragments cached"
+                       depends on TARGET_ROOTFS_SQUASHFS
+                       default 1 if (SMALL_FLASH && !LOW_MEMORY_FOOTPRINT)
+                       default 3
+
         menuconfig TARGET_ROOTFS_UBIFS
                 bool "ubifs"
                 default y if USES_UBIFS

the results:


after boot

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 3.0M      3.0M         0 100% /rom
tmpfs                    13.4M     76.0K     13.4M   1% /tmp
tmpfs                    13.4M     48.0K     13.4M   0% /tmp/root
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock4          320.0K    220.0K    100.0K  69% /overlay
overlayfs:/overlay      320.0K    220.0K    100.0K  69% /
root@OpenWrt:/# free

              total       used       free     shared buffers     cached
Mem:         27520      23920       3600        124 2112       5748
-/+ buffers/cache:      16060      11460
Swap:            0          0          0
root@OpenWrt:/# cat /proc/meminfo
MemTotal:          27520 kB
MemFree:            3536 kB
MemAvailable:       9064 kB
Buffers:            2112 kB
Cached:             5748 kB
SwapCached:            0 kB
Active:             5892 kB
Inactive:           3120 kB
Active(anon):       1252 kB
Inactive(anon):       24 kB
Active(file):       4640 kB
Inactive(file):     3096 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          1160 kB
Mapped:             1784 kB
Shmem:               124 kB
Slab:               8876 kB
SReclaimable:       1216 kB
SUnreclaim:         7660 kB
KernelStack:         304 kB
PageTables:          208 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       13760 kB
Committed_AS:       3916 kB
VmallocTotal:    1048372 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB


after, ran 3 times


MemTotal:          27520 kB
MemFree:            1548 kB
MemAvailable:       8880 kB
Buffers:            2112 kB
Cached:             7268 kB
SwapCached:            0 kB
Active:             9612 kB
Inactive:            832 kB
Active(anon):       1164 kB
Inactive(anon):       24 kB
Active(file):       8448 kB
Inactive(file):      808 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          1072 kB
Mapped:             1688 kB
Shmem:               124 kB
Slab:               9508 kB
SReclaimable:       1784 kB
SUnreclaim:         7724 kB
KernelStack:         288 kB
PageTables:          184 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       13760 kB
Committed_AS:       3572 kB
VmallocTotal:    1048372 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB

root@OpenWrt:/# free
              total       used       free     shared    buffers cached
Mem:         27520      25940       1580        124 2112       7268
-/+ buffers/cache:      16560      10960
Swap:            0          0          0


Regards
Alex Maclean June 1, 2018, 6:05 p.m. | #3
On 01/06/18 12:34, Lucian Cristian wrote:

> On 30.05.2018 20:22, Martin Tippmann wrote:
>> find /usr |
>> xargs md5sum
>
> I made the test on tl-wr841n-v9 with luci selected
>
> these are the changes to squashfs
>
> --- a/config/Config-images.in
> +++ b/config/Config-images.in
> @@ -149,8 +149,15 @@ menu "Target Images"
>                         int "Block size (in KiB)"
>                         depends on TARGET_ROOTFS_SQUASHFS
>                         default 64 if LOW_MEMORY_FOOTPRINT
> +                       default 1024 if (SMALL_FLASH &&
> !LOW_MEMORY_FOOTPRINT)
>                         default 256
>
> +               config SQUASHFS_FRAGMENT_CACHE_SIZE
> +                       int "Number of fragments cached"
> +                       depends on TARGET_ROOTFS_SQUASHFS
> +                       default 1 if (SMALL_FLASH &&
> !LOW_MEMORY_FOOTPRINT)
> +                       default 3
> +
>         menuconfig TARGET_ROOTFS_UBIFS
>                 bool "ubifs"
>                 default y if USES_UBIFS

This won't have actually changed the option - you should use
KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE,
and CONFIG_SQUASHFS_EMBEDDED=y is also needed in the kernel config.
I think this also therefore belongs either in Config-kernel.in or simply
in the subtarget kernel config.

I did a few tests myself:

256K and 3 fragments:
10608K used after boot, 11408K free after reading /usr
24.5 seconds from kernel start to wifi link up

1024K and 3 fragments:
14520K after boot, 15204K after reading
30 seconds to link up

1024K and 2 fragments:
13460K after boot, 14128K after reading
34.7 seconds to link up

1024K and 1 fragment:
11620K after boot, 12364K after reading
46.8 seconds to link up

Certainly quite a lot of memory impact with the larger block size, but
also a quite significant performance impact with the larger reads.

I'm leaning towards compromising on 2 fragments but I'd like input on that.
Martin Tippmann June 4, 2018, 12:12 a.m. | #4
On Fri, Jun 1, 2018 at 8:05 PM, Alex Maclean <monkeh@monkeh.net> wrote:
> On 01/06/18 12:34, Lucian Cristian wrote:
>
>> On 30.05.2018 20:22, Martin Tippmann wrote:
>>> find /usr |
>>> xargs md5sum
>>
>> I made the test on tl-wr841n-v9 with luci selected
>>
>> these are the changes to squashfs
>>
>> --- a/config/Config-images.in
>> +++ b/config/Config-images.in
>> @@ -149,8 +149,15 @@ menu "Target Images"
>>                         int "Block size (in KiB)"
>>                         depends on TARGET_ROOTFS_SQUASHFS
>>                         default 64 if LOW_MEMORY_FOOTPRINT
>> +                       default 1024 if (SMALL_FLASH &&
>> !LOW_MEMORY_FOOTPRINT)
>>                         default 256
>>
>> +               config SQUASHFS_FRAGMENT_CACHE_SIZE
>> +                       int "Number of fragments cached"
>> +                       depends on TARGET_ROOTFS_SQUASHFS
>> +                       default 1 if (SMALL_FLASH &&
>> !LOW_MEMORY_FOOTPRINT)
>> +                       default 3
>> +
>>         menuconfig TARGET_ROOTFS_UBIFS
>>                 bool "ubifs"
>>                 default y if USES_UBIFS
>
> This won't have actually changed the option - you should use
> KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE,
> and CONFIG_SQUASHFS_EMBEDDED=y is also needed in the kernel config.
> I think this also therefore belongs either in Config-kernel.in or simply
> in the subtarget kernel config.
>
> I did a few tests myself:
>
> 256K and 3 fragments:
> 10608K used after boot, 11408K free after reading /usr
> 24.5 seconds from kernel start to wifi link up
>
> 1024K and 3 fragments:
> 14520K after boot, 15204K after reading
> 30 seconds to link up
>
> 1024K and 2 fragments:
> 13460K after boot, 14128K after reading
> 34.7 seconds to link up
>
> 1024K and 1 fragment:
> 11620K after boot, 12364K after reading
> 46.8 seconds to link up
>
> Certainly quite a lot of memory impact with the larger block size, but
> also a quite significant performance impact with the larger reads.
>
> I'm leaning towards compromising on 2 fragments but I'd like input on that.

Thanks for testing! Did not expect the impact on boot-time. I'm not a
dev, 2 looks reasonable for me - maybe add the flag to make menuconfig
/ .config so that downstream can set it up - for some applications
(i.e. freifunk) boot-time does not matter but memory is always scarse.

regards
Martin

Patch

diff --git a/config/Config-images.in b/config/Config-images.in
index 90e873edb8..07ef619e70 100644
--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -149,6 +149,7 @@  menu "Target Images"
 			int "Block size (in KiB)"
 			depends on TARGET_ROOTFS_SQUASHFS
 			default 64 if LOW_MEMORY_FOOTPRINT
+			default 1024 if (SMALL_FLASH && !LOW_MEMORY_FOOTPRINT)
 			default 256
 
 	menuconfig TARGET_ROOTFS_UBIFS
diff --git a/config/Config-kernel.in b/config/Config-kernel.in
index 0cbe5e8351..8eb954e1a5 100644
--- a/config/Config-kernel.in
+++ b/config/Config-kernel.in
@@ -31,7 +31,7 @@  config KERNEL_CRASHLOG
 
 config KERNEL_SWAP
 	bool "Support for paging of anonymous memory (swap)"
-	default y
+	default y if !SMALL_FLASH
 
 config KERNEL_DEBUG_FS
 	bool "Compile the kernel with debug filesystem enabled"
@@ -112,7 +112,7 @@  config KERNEL_DEBUG_KERNEL
 
 config KERNEL_DEBUG_INFO
 	bool "Compile the kernel with debug information"
-	default y
+	default y if !SMALL_FLASH
 	select KERNEL_DEBUG_KERNEL
 	help
 	  This will compile your kernel and modules with debug information.
@@ -205,7 +205,7 @@  config KERNEL_COREDUMP
 config KERNEL_ELF_CORE
 	bool "Enable process core dump support"
 	select KERNEL_COREDUMP
-	default y
+	default y if !SMALL_FLASH
 
 config KERNEL_PROVE_LOCKING
 	bool "Enable kernel lock checking"