swap file..using zram // media memory

User avatar
meveric
Posts: 10453
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2
Has thanked: 16 times
Been thanked: 127 times
Contact:

Re: swap file..using zram // media memory

Unread post by meveric » Thu Apr 18, 2019 3:43 pm

above you always used "zramctl" which in fact is NOT part of zram-config but part of the util-linux package.

If you would actually use zram-config, zram is started via /etc/systemd/system/multi-user.target.wants/zram-config.service (and automatically started during system boot).
and normal systemctl start and stop procedures
Which starts and stops zram using the script I mentioned:

Code: Select all

[Unit]
Description=Initializes zram swaping

[Service]
ExecStart=/usr/bin/init-zram-swapping
ExecStop=/usr/bin/end-zram-swapping
Type=oneshot
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
Instead you're using zramctl to manually start and stop everything.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Sun Apr 21, 2019 6:28 am

I just tried Balbes150's Armbian Bionic on the N2.
https://forum.armbian.com/topic/7930-ar ... x-ver-555/
There 1024MiB zram is activated by default.
I've added a 4GB swap file to test. I made one of my heaviest renders even heavier... This was on an sd-card, so not pratical.
Screenshot_2019-04-20_21-01-42.png
Screenshot_2019-04-20_21-01-42.png (243.13 KiB) Viewed 2487 times
This is how it should work on Ubuntu Mate/Stretch.
What is different on Armbian vs Odroid's Ubuntu and Meveric's Stretch? I also tried Meveric's Stretch and it was the same as Ubuntu.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 10:55 am

The kernel configuration will be quiet different on armbian and optimised for zram (probably diff compression too), can you confirm the kernel version with a "uname -a"?

On Odroid's Ubuntu / Maveric's stretch did you try maveric's suggestion above by using systemd to start the service correctly instead of zramctl which might not setup the configuration optimally?

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Sun Apr 21, 2019 11:32 am

brad wrote:
Sun Apr 21, 2019 10:55 am
The kernel configuration will be quiet different on armbian and optimised for zram (probably diff compression too), can you confirm the kernel version with a "uname -a"?
Linux odroid 5.1.0-rc1-odroid-n2 #5.78 SMP PREEMPT Thu Apr 11 16:18:36 MSK 2019 aarch64 aarch64 aarch64 GNU/Linux

The image does have it's problems. The small cores run at 1.2Ghz and the big ones at 1Ghz. You can't control them with cpufrequtils. Can't check temperature.
It performs at almost half the speed as it should perform.
Meveric just told me he's got his own script for zram on Stretch. I had used another one. I'll try it now and see how it does.
But again since swap files have the same behaviour as zram I don't think it's a zram configuration issue.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 11:40 am

Yes 5.1-rc1 kernel is only very minimal at this stage, the cpu freq issues in 5.1-rc should be much improved in upcoming releases once Odroid N2 support hits properly and bugs are ironed out.

I think the zram issues will be related to to the 4.9 kernel configuration but at the moment I am unsure what it might be as I have no need for zram. I would would rather just use a swap file if extra ram is required for your program, I don't like the idea of a performance hit with zram compression and we have 4Gb physical to play with and some reasonable fast disk for swap.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Sun Apr 21, 2019 12:06 pm

brad wrote:
Sun Apr 21, 2019 11:40 am
I think the zram issues will be related to to the 4.9 kernel configuration but at the moment I am unsure what it might be as I have no need for zram. I would would rather just use a swap file if extra ram is required for your program, I don't like the idea of a performance hit with zram compression and we have 4Gb physical to play with and some reasonable fast disk for swap.
A swap file also doesn't work. It is the same problem as with zram.
And the performance of a swap file is a lot worse than zram. Zram is still on the ram, but compressed. A swap file is on a drive. So when it needs to use the swap file everything will slow down to the speed of that drive. For an sd-card this isn't useable.
Zram uses a bit of the cpu. But with multicore cpu's this is no issue.
I also think it's a kernel issue. I tried again with Meveric's Stretch and his zram-odroid script. No difference as expected. I changed swappiness, did nothing.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 2:55 pm

BadPritt wrote:
Sun Apr 21, 2019 12:06 pm
brad wrote:
Sun Apr 21, 2019 11:40 am
I think the zram issues will be related to to the 4.9 kernel configuration but at the moment I am unsure what it might be as I have no need for zram. I would would rather just use a swap file if extra ram is required for your program, I don't like the idea of a performance hit with zram compression and we have 4Gb physical to play with and some reasonable fast disk for swap.
A swap file also doesn't work. It is the same problem as with zram.
And the performance of a swap file is a lot worse than zram. Zram is still on the ram, but compressed. A swap file is on a drive. So when it needs to use the swap file everything will slow down to the speed of that drive. For an sd-card this isn't useable.
Zram uses a bit of the cpu. But with multicore cpu's this is no issue.
I also think it's a kernel issue. I tried again with Meveric's Stretch and his zram-odroid script. No difference as expected. I changed swappiness, did nothing.
I see I just took a look back through your comments in this thread. In 4.9 kernel I suspect there is a limit inside the kernel which will cause the the max virtual memory size to be limited for any particular process to say 3-4Gb. Next time i'm using and compiling 4.9 kernel I will take a look at the configuration and see if this can be expanded out to an arbitrary large value. This setting is often kept in amlogic BSP kernels to allow support of 32 bit runtime processes in their proprietary code such as the video decoder. 5.1-rc will not have this legacy limit imposed on it.

Edit: it may be a simple as enabling huge pages, I'm burning an image now and downloading kernel source to find out as it intrigues me
These users thanked the author brad for the post:
mad_ady (Sun Apr 21, 2019 3:22 pm)

User avatar
mad_ady
Posts: 6558
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 169 times
Been thanked: 128 times
Contact:

Re: swap file..using zram // media memory

Unread post by mad_ady » Sun Apr 21, 2019 3:22 pm

I never thought 64bit processes could be limited to 32bit address space size...

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 3:52 pm

mad_ady wrote:
Sun Apr 21, 2019 3:22 pm
I never thought 64bit processes could be limited to 32bit address space size...
Indeed it can be limited, a 32 bit process can normally only only reference 2Gb ram but can be expended to 4Gb. As a result linux must only provide up to 4Gb virtual address space to be able to support 32 bit processes which inherently limits 64 bit processes as well. I have just booted 4.9 and can confirm its only a 4Gb max virtual memory address size....

Code: Select all

[    0.000000@0] Memory: 3280232K/3891200K available (11580K kernel code, 1622K rwdata, 5156K rodata, 4672K init, 1382K bss, 103064K
 reserved, 507904K cma-reserved)                                                                                                    
[    0.000000@0] Virtual kernel memory layout:                                                                                      
[    0.000000@0]     modules : 0xffffff8000000000 - 0xffffff8008000000   (   128 MB)                                                
[    0.000000@0]     vmalloc : 0xffffff8008000000 - 0xffffffbebfff0000   (   250 GB)                                                
[    0.000000@0]       .text : 0xffffff8009080000 - 0xffffff8009bd0000   ( 11584 KB)                                                
[    0.000000@0]     .rodata : 0xffffff8009bd0000 - 0xffffff800a0e0000   (  5184 KB)                                                
[    0.000000@0]       .init : 0xffffff800a0e0000 - 0xffffff800a570000   (  4672 KB)                                                
[    0.000000@0]       .data : 0xffffff800a570000 - 0xffffff800a705a00   (  1623 KB)                                                
[    0.000000@0]        .bss : 0xffffff800a705a00 - 0xffffff800a85f57c   (  1383 KB)                                                
[    0.000000@0]     fixed   : 0xffffffbefe7fd000 - 0xffffffbefec00000   (  4108 KB)                                                
[    0.000000@0]     PCI I/O : 0xffffffbefee00000 - 0xffffffbeffe00000   (    16 MB)                                                
[    0.000000@0]     vmemmap : 0xffffffbf00000000 - 0xffffffc000000000   (     4 GB maximum)                                        
[    0.000000@0]               0xffffffbf00000000 - 0xffffffbf03b60000   (    59 MB actual)                                         
[    0.000000@0]     memory  : 0xffffffc000000000 - 0xffffffc0ed800000   (  3800 MB)                                                
[    0.000000@0] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=6, Nodes=1           
Ill download kernel source and see if it can find a way to expand this out but it will break any of the 32 bit amlogic processes (hopefully nothing too important)

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 5:41 pm

No luck on first attempt, attempted increasing page size from 4K to 16K but needed to disable Mali to get kernel to compile. Installed it but it gets stuck booting kernel from uboot and not really sure why, I also upgraded (apt-get update && apt-upgrade && apt-get dist-upgrade) and it did a boot.ini update so maybe this is the cause of the boot failure.

crashoverride
Posts: 4521
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 67 times
Contact:

Re: swap file..using zram // media memory

Unread post by crashoverride » Sun Apr 21, 2019 5:48 pm

The virtual memory under AArch64 is documented here:
https://www.kernel.org/doc/Documentatio ... memory.txt

The kernel is configured with 4K pages, 39 virtual address bits, and 3 page table levels:
https://github.com/hardkernel/linux/blo ... onfig#L390
https://github.com/hardkernel/linux/blo ... onfig#L395
https://github.com/hardkernel/linux/blo ... config#L37

This results in 512GB for kernel and 512GB for user space (1TB total):

Code: Select all

AArch64 Linux memory layout with 4KB pages + 3 levels:

Start			End			Size		Use
-----------------------------------------------------------------------
0000000000000000	0000007fffffffff	 512GB		user
ffffff8000000000	ffffffffffffffff	 512GB		kernel
A 32bit (AArch32) process running on a 64bit (AArch64) kernel uses the exact same MMU tables. This means that a 32bit process also has 512GB of virtual address space but can only address/alloc 4GB from it. This is in contrast to pure 32bit systems where there was a 3GB user space and 1GB kernel.

If the program being tested is allocated less than 512GB and sufficient physical + swap memory is available, the issue may lie elsewhere such a the 'cgroup' memory policy applied to it.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 6:14 pm

crashoverride wrote:
Sun Apr 21, 2019 5:48 pm
The virtual memory under AArch64 is documented here:
https://www.kernel.org/doc/Documentatio ... memory.txt

The kernel is configured with 4K pages, 39 virtual address bits, and 3 page table levels:
https://github.com/hardkernel/linux/blo ... onfig#L390
https://github.com/hardkernel/linux/blo ... onfig#L395
https://github.com/hardkernel/linux/blo ... config#L37

This results in 512GB for kernel and 512GB for user space (1TB total):

Code: Select all

AArch64 Linux memory layout with 4KB pages + 3 levels:

Start			End			Size		Use
-----------------------------------------------------------------------
0000000000000000	0000007fffffffff	 512GB		user
ffffff8000000000	ffffffffffffffff	 512GB		kernel
A 32bit (AArch32) process running on a 64bit (AArch64) kernel uses the exact same MMU tables. This means that a 32bit process also has 512GB of virtual address space but can only address/alloc 4GB from it. This is in contrast to pure 32bit systems where there was a 3GB user space and 1GB kernel.

If the program being tested is allocated less than 512GB and sufficient physical + swap memory is available, the issue may lie elsewhere such a the 'cgroup' memory policy applied to it.
Yes I was just going through this doco myself. I had the same issue on C2 some years back adding ZFS support (ZFS was based on bsd which has very large limitations even on 32 bit modes and even if its not using it ZFS wanted to allocate it). The limitations are not cgroups as virtual memory addressing is configured before this in boot. I was going to try to enable huge pages to see if this helps to increase the address size.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Sun Apr 21, 2019 9:35 pm

Ok some more investigation leads me to my initial conclusion.

- From a standard odroidn2_defconfig, enabling just CONFIG_ARM64_VA_BITS=42 leads to a max 2Gb Virtual address size (which works well with 32 bit apps such as mali kernel driver but less that the original 4Gb max)
- Enabling CONFIG_ARM64_64K_PAGES=y sets up a 128Gb max pagesize (Ideal) but mali fails to compile (with page size errors listed below) and the kernel has a lot of failures during runtime in all areas (see log attached)

As mentioned by crashoverride with 39 bit address size and 4k pages there is 512Gb available memory to be allocated but this is total system allocation for either userspace or kernel space. The page layout limits a max of 4Gb addressable area for each of these shared memory segments (These fit into the available system addressable area). So I can have a shared memory segment with 1 or more processes attached with a limit of 4Gb.

The Aarch32 compatibility mode is (was) forcibly enabled in 4.9 bsp kernel and appears to be due to the use of the amlogic proprietary drivers which require 39 bit virtual address layout and 4k pages in its current form.

This leaves some possible paths to try to move forward to support larger Virtual address ranges. Maybe there is a more simple solution but I don't believe so? I would not really call my self an expert.

- Hardkernrel / amlogic release 64 bit versions of the proprietary code / blobs to overcome these 32 bit limitations
- Replace the 32 bit variants with upstream versions / developments throughout the kernel
- Remove the 32 bit kernel variants
- Compile the 32 bit kernel variants with 64K or 16K aligned segments (for CONFIG_ARM64_16K_PAGES / CONFIG_ARM64_16K_PAGES) if possible to support larger pagesizes. Not sure this will be helpful for any userspace blobs such as the mali 32 bit drivers, the 64 bit would need to be used.
- More effort in supporting upstream Linux for users wanting to use larger virtual memory ranges.

Here is the memory layout with 42 bit / 64k pages

Code: Select all

 535680K reserved, 524288K cma-reserved)                                                                                    
[    0.000000@0] Virtual kernel memory layout:                                                                              
[    0.000000@0]     modules : 0xffff000000000000 - 0xffff000008000000   (   128 MB)                                        
[    0.000000@0]     vmalloc : 0xffff000008000000 - 0xffff7bdfffff0000   (126847 GB)                                        
[    0.000000@0]       .text : 0xffff000009080000 - 0xffff000009c00000   ( 11776 KB)                                        
[    0.000000@0]     .rodata : 0xffff000009c00000 - 0xffff00000a130000   (  5312 KB)                                        
[    0.000000@0]       .init : 0xffff00000a130000 - 0xffff00000a5e0000   (  4800 KB)                                        
[    0.000000@0]       .data : 0xffff00000a5e0000 - 0xffff00000a7b0200   (  1857 KB)                                        
[    0.000000@0]        .bss : 0xffff00000a7b0200 - 0xffff00000a9763bc   (  1817 KB)                                        
[    0.000000@0]     fixed   : 0xffff7fdffe7d0000 - 0xffff7fdffec00000   (  4288 KB)                                        
[    0.000000@0]     PCI I/O : 0xffff7fdffee00000 - 0xffff7fdfffe00000   (    16 MB)                                        
[    0.000000@0]     vmemmap : 0xffff7fe000000000 - 0xffff800000000000   (   128 GB maximum)                                
[    0.000000@0]               0xffff7fe000000000 - 0xffff7fe0003b6000   (     3 MB actual)                                 
[    0.000000@0]     memory  : 0xffff800000000000 - 0xffff8000ed800000   (  3800 MB)                                                           
Here is the compile time error from mali driver

Code: Select all

drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1917:2: error: duplicate case value
  case PFN_DOWN(BASEP_MEM_WRITE_ALLOC_PAGES_HANDLE):
  ^~~~
drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1916:2: note: previously used here
  case PFN_DOWN(BASEP_MEM_INVALID_HANDLE):
  ^~~~
drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1921:2: error: duplicate case value
  case PFN_DOWN(BASE_MEM_TRACE_BUFFER_HANDLE):
  ^~~~
drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1916:2: note: previously used here
  case PFN_DOWN(BASEP_MEM_INVALID_HANDLE):
  ^~~~
drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1929:2: error: duplicate case value
  case PFN_DOWN(BASE_MEM_MMU_DUMP_HANDLE):
  ^~~~
drivers/gpu/arm/midgard/mali_kbase_mem_linux.c:1916:2: note: previously used here
  case PFN_DOWN(BASEP_MEM_INVALID_HANDLE):
  ^~~~
Attached is the boot logs with lots of failures relating to memory

The meson secure monitor fails first so I guess this would be the first thing to investigate
Attachments
capture.txt
(334.7 KiB) Downloaded 16 times

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Sun Apr 21, 2019 10:29 pm

Great work Brad. So the simple answer is, it's complicated.
It sounds a logical explenation that a memory size limit is set, and this stops things working.
If so, then it's 3GB. My system uses about 700MB, and then the project loads everything unti it's using 3GB.

If you have an idea of what to test. Let me know.
For people who want to use this for productivity tasks it is important this works.

I do remember this was working on the Odroid C2. But there it was only 1.7GB + 850MB zram. So it will not have gone over 3GB.
Thanks, cheers.

crashoverride
Posts: 4521
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 67 times
Contact:

Re: swap file..using zram // media memory

Unread post by crashoverride » Sun Apr 21, 2019 11:08 pm

brad wrote:
Sun Apr 21, 2019 9:35 pm
As mentioned by crashoverride with 39 bit address size and 4k pages there is 512Gb available memory to be allocated but this is total system allocation for either userspace or kernel space. The page layout limits a max of 4Gb addressable area for each of these shared memory segments (These fit into the available system addressable area). So I can have a shared memory segment with 1 or more processes attached with a limit of 4Gb.
This is inaccurate. Each process has 1TB of virtual address space: 512GB for the process and 512GB for the kernel. There is no 4GB limit anywhere in AArch64. I am guessing this is assumed due to the 'vmemmap' output in the log. This value actually represent a sparse mapping scheme implemented by Linux to avoid allocating page entries for each possible addressable page.
http://mytechkorner.blogspot.com/2010/12/sparsemem.html
Sparsemem is a framework to be used in certain architecture systems, in which the entire memory is spanned out in different memory banks across the address space of the processor. The problem in such cases is, if we dont deal with it differently, it means making page struct for all the pages across the entire address space, even if it contains huge no. of invalid pages which cannot be used. Thus wasting a lot of memory for bookkeeping invalid memory.
1) Virtual mem_map -- This implementation is specifically for 64-bit architectures. In this case, mem_map is mapped into a virtually contiguous area and only the active sections are physically mapped. This allows virt_to_page, page_addresses and others to become simple shift/add operations. No page-fileds, no table lookups, nothing related to memory is required.
The virtual mapping must be big enough to allow a struct page to be allocated and mapped for all valid physical pages.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Sun Apr 21, 2019 11:39 pm

I'm now not at my N2. Is it possibly a permission problem? Maybe the user doesn't have the right permission to write to swap/zram.
I'll try tonight with root permissions.

User avatar
mad_ady
Posts: 6558
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 169 times
Been thanked: 128 times
Contact:

Re: swap file..using zram // media memory

Unread post by mad_ady » Sun Apr 21, 2019 11:49 pm

No - you need cgroups to limit memory/swap usage for a process/user, and by default no such policies are configured.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Mon Apr 22, 2019 12:15 am

@crashoverride im no expert in the matter but the vemmap in bsp kernel (and all aarch64 kernels ive seen) always aligns to the max virtual memory space that can be used for a shared memory allocated to a process. In the case of amlogic bsp it is very small even back on the C2 in 3.14. Regardless of its definition or detail in the document you linked its value will directly impact the amount of ram that can be allocated a processes shared memory. The only way i know to increase it is to increase the page size or page levels and this breaks the amlogic bsp components of the kernel as they are aligned to 4k segments. In mainline (C2 or N2) for aarch64 the size is much larger and allows large shared ranges to be preallocated even if not actually used.

Maybe this is a bug or limitation brought across from the android port process but either way a fact. I looked at the amlogic cma driver and this appears to a possible issue, it seems to simplify linuxs page table allications far to much and i guess its to make amligics non standard code work.

Mainline is much more standardised and features just work as documentented in most cases. Im in the process of testing / configuring mainline uboot on N2 and i am currently having issues with page size and allocations as to my interest in this issue. The amlogic trusted firmware there actually looks to be written very well and well documented so it makes life easy. Mainline linux development is weĺl advanced for N2 now with the only major task the video decoder left so i think efforts are better spent there.

crashoverride
Posts: 4521
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 67 times
Contact:

Re: swap file..using zram // media memory

Unread post by crashoverride » Mon Apr 22, 2019 1:29 am

The 'vmemmap' does not hold any process memory. It is a subdivision of the kernel address range that holds an array of 'struct page'.
https://elixir.bootlin.com/linux/v4.9.1 ... mory.h#L55

Code: Select all

*
 * VMEMMAP_SIZE - allows the whole linear region to be covered by
 *                a struct page array
 */
#define VMEMMAP_SIZE (UL(1) << (VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT))
https://elixir.bootlin.com/linux/v4.9.1 ... ypes.h#L45

Code: Select all

/*
 * Each physical page in the system has a struct page associated with
 * it to keep track of whatever it is we are using the page for at the
 * moment. Note that we have no way to track which tasks are using
 * a page, though if it is a pagecache page, rmap structures can tell us
 * who is mapping it.
 *
 * The objects in struct page are organized in double word blocks in
 * order to allows us to use atomic double word operations on portions
 * of struct page. That is currently only used by slub but the arrangement
 * allows the use of atomic double word operations on the flags/mapping
 * and lru list pointers also.
 */
struct page {
https://elixir.bootlin.com/linux/v4.9.1 ... nit.c#L453

Code: Select all

#ifdef CONFIG_SPARSEMEM_VMEMMAP
	pr_notice("    vmemmap : 0x%16lx - 0x%16lx   (%6ld GB maximum)\n",
		MLG(VMEMMAP_START, VMEMMAP_START + VMEMMAP_SIZE));
	pr_notice("              0x%16lx - 0x%16lx   (%6ld MB actual)\n",
		MLM((unsigned long)phys_to_page(memblock_start_of_DRAM()),
		    (unsigned long)virt_to_page(high_memory)));
#endif
The variables used in the vmemmap size calc are as follows:

https://github.com/hardkernel/linux/blo ... onfig#L395

Code: Select all

CONFIG_ARM64_VA_BITS=39
https://github.com/hardkernel/linux/blo ... config#L10

Code: Select all

CONFIG_ARM64_PAGE_SHIFT=12
The size of 'struct page' is defaulted to 6:
https://elixir.bootlin.com/linux/v4.9.1 ... mory.h#L49

Code: Select all

/*
 * Log2 of the upper bound of the size of a struct page. Used for sizing
 * the vmemmap region only, does not affect actual memory footprint.
 * We don't use sizeof(struct page) directly since taking its size here
 * requires its definition to be available at this point in the inclusion
 * chain, and it may not be a power of 2 in the first place.
 */
#define STRUCT_PAGE_MAX_SHIFT	6
There are 39bits to a virtual address. Of those, 12 define a page (4K). This means there are 2^27 (39bits - 12bits) possible page table entries. Each page table entries is 2^6 in size. This means you need 2^32 (27bits - 1bit + 6bits) (4GB) of memory to hold page table entries for each possible address (39 bits, 12bit pages). It is entirely co-incidence that this number happens to be 4GB and has nothing to do with 4GB limits imposed by 32bit systems. If the 'sizeof(struct page)' had been larger or smaller, the amount of memory required to hold vmemmap would not be 4GB.
These users thanked the author crashoverride for the post (total 2):
ASword (Tue Apr 23, 2019 12:47 am) • brad (Tue Apr 23, 2019 2:14 pm)

crashoverride
Posts: 4521
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 67 times
Contact:

Re: swap file..using zram // media memory

Unread post by crashoverride » Mon Apr 22, 2019 1:40 am

brad wrote:
Mon Apr 22, 2019 12:15 am
In mainline (C2 or N2) for aarch64 the size is much larger
Mainline defines a 48bit virtual address instead of 39:
https://github.com/torvalds/linux/blob/ ... config#L90

Code: Select all

CONFIG_ARM64_VA_BITS_48=y
This larger address space requires more (2^9) [48bits - 39bits] page table entries to hold it in its entirety.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Mon Apr 22, 2019 7:36 am

@crashoverride Thanks, I guess it is just a coincidence in more than 1 way.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 1:49 am

I've tried the whole day getting zram to work but I haven't gotten any further.
I've manually enabled zram, and tried changing as many parameters as possible. Nothing made a change. The moment it starts using zram it crashes the application.

I'm now 99.999% convinced this has nothing to do with zram settings.
Here how I set up zram.

Code: Select all

#install zram kernel module
sudo apt install linux-image-extra-virtual

#Load 6 zram modules. One for each CPU
modprobe zram num_devices=6

#Select compression algorithm
echo lzo > /sys/black/zram0/comp_algorithm

#Set zram size
echo 1800M > /sys/block/zram0/disksize

#Set memory limit(disable)
echo 0 > /sys/block/zram0/mem_limit

#Activate zram
mkswap /dev/zram0
swapon /dev/zram0 
I'm also looking into the build options. I can't find a clue of something that could be changed.
Is there any other kernel available for testing?
Anyone else more idea's?

User avatar
mad_ady
Posts: 6558
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 169 times
Been thanked: 128 times
Contact:

Re: swap file..using zram // media memory

Unread post by mad_ady » Tue Apr 23, 2019 2:26 am

@BadPritt: running two independent rendering processes at the same time should saturate both ram and zram.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 4:06 am

mad_ady wrote:
Tue Apr 23, 2019 2:26 am
@BadPritt: running two independent rendering processes at the same time should saturate both ram and zram.
This shuts down the render task that makes it go over the memory. The 2nd render task keeps running. This with Stretch.
With Ubuntu it sometimes locked the desktop and made me log in again, and all running applications were terminated.

I've just heard there's good progress in the development of Armbian for the N2. I guess I'll have to wait for that for zram/swap.

I'll advice people to use Stretch for now in my review video, and I'll warn people they can't use zram/swap yet.
I've encountered too many issue's with Ubuntu Mate. (automount, stabillity issue's, USB devices stop working/wifi stops working, problems with keyboard layout, ...)

Meveric's Stretch doesn't seem to have any of those things. Only the swap/zram is an issue there.

There's also an issue with both Stretch/Ubuntu Mate when the governor is ondemand. It's +10% slower than performance governor.

User avatar
meveric
Posts: 10453
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2
Has thanked: 16 times
Been thanked: 127 times
Contact:

Re: swap file..using zram // media memory

Unread post by meveric » Tue Apr 23, 2019 7:22 am

BadPritt wrote:
Tue Apr 23, 2019 4:06 am
There's also an issue with both Stretch/Ubuntu Mate when the governor is ondemand. It's +10% slower than performance governor.
Sadly this is expected, other boards act similarly. I once experimented with "ondemand" for the gaming image, but it turns out the time it took to clock up from ondemand to highest speed, always caused lags in games, and often the system was unable to catch up completely.

I'd suggest using ondemand only on systems where performance is not vital. Like a server image that is doing mostly nothing.
These users thanked the author meveric for the post:
BadPritt (Wed Apr 24, 2019 3:01 am)
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Tue Apr 23, 2019 10:05 am

First of all thanks to @crashoverride for setting me straight about my misunderstanding, I was looking into things far too much and missing the obvious. :cry:

I went back and looked at the actual problem at hand which is the lowmemroykiller being invoked when we have spare swap which can be utilised and found this discussion - https://answers.launchpad.net/ubuntu/+question/236764

Setting the following lowmemorykiller options (as root) resolves the issue by practically disabling the lowmemorykiller (we can still rely on the OOM killer I believe if we completely run out of memory to kill off processes)

Code: Select all

echo '9999' > /sys/module/lowmemorykiller/parameters/adj
echo '1' > /sys/module/lowmemorykiller/parameters/minfree
From my testing this results in being able to utilise swap space more aggressively when physical ram is exhausted.

As a test with 12G swap file allocated and using the following stress command I am able to consume ~ 8Gb of swap (+ ~ 4GB physcial)

Code: Select all

 stress -m 1 --vm-bytes 12G
Here is the resulting top output during the test

Code: Select all

top - 01:10:36 up 41 min,  2 users,  load average: 3.58, 3.18, 2.38
Tasks: 138 total,   1 running, 137 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  6.2 sy,  0.0 ni, 81.5 id, 12.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  3801684 total,    16720 free,  3769516 used,    15448 buff/cache
KiB Swap: 12582908 total,  3569808 free,  9013100 used.    11192 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1836 root      -2 -15       0      0      0 S  19.1  0.0   3:54.40 mmcqd/1
 2393 odroid    20   0 12.002g 3.436g     20 D   9.6 94.8   0:49.69 stress
 1737 root     -51   0       0      0      0 S   5.6  0.0   1:01.42 irq/49-mes+
 1364 root      15  -5       0      0      0 S   5.2  0.0   2:41.16 kswapd0
 2398 odroid    20   0    6052    696     72 R   1.9  0.0   0:00.44 top
@BadPritt can you test to see if this overcomes the issue with swap / zram configured in your setup?
These users thanked the author brad for the post (total 3):
BadPritt (Tue Apr 23, 2019 11:06 am) • mad_ady (Tue Apr 23, 2019 1:26 pm) • phaseshifter (Wed Apr 24, 2019 4:24 am)

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 11:17 am

brad wrote:
Tue Apr 23, 2019 10:05 am
@BadPritt can you test to see if this overcomes the issue with swap / zram configured in your setup?
Thank you Brad. Looks very promissing. I will try that tomorrow.
I had been concentrating at the wrong thing today. But at least I've learned a lot.
When this works I can truly advertise it being great for productivity use.
I'll use my 128GB eMMC for a large swap, + 1.8GB zram. Then it can handle really heavy tasks, and only time is a limitting factor then. I almost gave up for now.
Gretings.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 11:30 am

You can also test yourself with this file.

Just install blender (sudo apt install blender)
Open the file and press render. The settings have been maximised for a lot memory use. Within a few seconds it should go over 3.7GB. I don't think this project can be finished by the n2, don't know how much memory it needs.
Greetings
Attachments
Armbian Under construction 279blend.7z
(405.27 KiB) Downloaded 19 times

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 10:35 pm

brad wrote:
Tue Apr 23, 2019 10:05 am
Setting the following lowmemorykiller options (as root) resolves the issue by practically disabling the lowmemorykiller (we can still rely on the OOM killer I believe if we completely run out of memory to kill off processes)

Code: Select all

echo '9999' > /sys/module/lowmemorykiller/parameters/adj
echo '1' > /sys/module/lowmemorykiller/parameters/minfree
From my testing this results in being able to utilise swap space more aggressively when physical ram is exhausted.


@BadPritt can you test to see if this overcomes the issue with swap / zram configured in your setup?
Wow Brad. You are the man. It works. I didn't put my hopes too high, but when I saw it going over the ram and completely filling the zram was such a magic moment.
it works.png
it works.png (625.74 KiB) Viewed 2173 times
I'm so happy this works. I'll install Stretch tonight on my 128GB eMMC and make a huge swap file + zram. I'll see how far it can be pushed.

@phaseshifter

Code: Select all

#firstly install the package...after the inital setup explained below you have to reboot and then it`s done..and then it is configured on every reboot..

sudo apt install zram-config

#Go to super user mode
su
#type root password

#to make it load at boot up i did this...
#edit the /etc/rc.local file and put these lines into the file at the top of the file..you can choose your swap size i chose 1/2 a gig...
#if you wish to change ram size at any time... simply edit the /etc/rc.local and change it to the value that you require..then reboot..

nano /etc/rc.local
#add. Change 512M to the size you want. Useally this is half of the available ram, so 1800M for the N2
zramctl --find --size 512M

mkswap /dev/zram0

swapon /dev/zram0

#Set the lowmemorykiller options so zram will be used when needed 

echo '9999' > /sys/module/lowmemorykiller/parameters/adj
echo '1' > /sys/module/lowmemorykiller/parameters/minfree



#to turn it off if you dont need it for the session...

swapoff /dev/zram0

zramctl --reset /dev/zram0
I'll try it tonight on Ubuntu Mate.

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Tue Apr 23, 2019 10:56 pm

Only problem I now know of (in Stretch+Ubuntu) is the unstable usb. Certainly when you plug many devices into it(ssd thru usb3, keyboard dongle, mouse dongle, a usb2 hub with wifi dongle and sd-card readers, ...)
Many times my mouse just lags or stops working. My wifi dongle stops working a lot, I've got to replug it then. (wifi also doesn't work well when plugged directly into the N2, is there any interference by the board? that's why it ain't got wifi? Rock64 has this too. Always need to use a hub or long usb cable)
It doesn't seem a voltage problem, I've got a constant 5.05V on my USB ports, even when I plug in my ssd. Do I need to make a new thear for this? Or has anyone already got a sollution for this?

I'll start the preparating for making my review video. Now I've got a very good and stable OS with Stretch. And I now know what and how things are working with the N2.
That's why I always wait before I know enough. If I would have made it last week it would not have been a good reveiw....

Thank you all. Amazing job done for it being this new. I'm truly impressed by it.
Greetings. NicoD

crashoverride
Posts: 4521
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 67 times
Contact:

Re: swap file..using zram // media memory

Unread post by crashoverride » Wed Apr 24, 2019 12:10 am

The module seems to be inherited from Android:
https://github.com/hardkernel/linux/blo ... rykiller.c

The resolution is likely to disable the module in the kernel config:
https://github.com/hardkernel/linux/blo ... ig#L34-L42

Code: Select all

config ANDROID_LOW_MEMORY_KILLER
	bool "Android Low Memory Killer"
	---help---
	  Registers processes to be killed when low memory conditions, this is useful
	  as there is no particular swap space on android.

	  The registered process will kill according to the priorities in android init
	  scripts (/init.rc), and it defines priority values with minimum free memory size
          for each priority.
[edit]
odroidn2_defconfig
https://github.com/hardkernel/linux/blo ... 4853-L4854

Code: Select all

CONFIG_ANDROID_LOW_MEMORY_KILLER=y
CONFIG_ANDROID_LOW_MEMORY_KILLER_AUTODETECT_OOM_ADJ_VALUES=y
These users thanked the author crashoverride for the post (total 4):
mad_ady (Wed Apr 24, 2019 2:12 am) • tobetter (Wed Apr 24, 2019 2:19 am) • xabolcs (Wed Apr 24, 2019 2:40 am) • BadPritt (Wed Apr 24, 2019 3:01 am)

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Wed Apr 24, 2019 2:11 am

crashoverride wrote:
Wed Apr 24, 2019 12:10 am
The module seems to be inherited from Android:
https://github.com/hardkernel/linux/blo ... rykiller.c
Not a pretty sight to see that in the Linux kernel.

I also found this

Code: Select all

CONFIG_ANDROID=y                                                                       Line 5361
CONFIG_ANDROID_BINDER_IPC=y                                                             Line 5362
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"               Line 5363
Android is rarely a good base for a Linux kernel. The needs are very different for both.
I expect there's going to be more issue's because of this.
I know it's a lot less work to get it started, but it's more work afterwards to clean it up.

At least this is solved now. I'll start a new thread for the USB issue.
Cheers.
These users thanked the author BadPritt for the post (total 2):
tobetter (Wed Apr 24, 2019 2:19 am) • phaseshifter (Wed Apr 24, 2019 4:23 am)

User avatar
tobetter
Posts: 3908
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 38 times
Been thanked: 155 times
Contact:

Re: swap file..using zram // media memory

Unread post by tobetter » Wed Apr 24, 2019 2:19 am

Thank you,
the kernel configs should be removed in the Ubuntu branch. Sorry about not manage them all yet but some of them should be kept for a while due to compile errors... :oops:
As you guys already know that the features are not intended to be enabled for Ubuntu, but the source tree is actually from Android BSP.
These users thanked the author tobetter for the post (total 2):
BadPritt (Wed Apr 24, 2019 3:01 am) • mad_ady (Wed Apr 24, 2019 2:27 pm)

BadPritt
Posts: 159
Joined: Wed Jan 17, 2018 4:08 am
languages_spoken: english dutch french spanish german
ODROIDs: Odroid C2
Odroid XU4Q
Has thanked: 17 times
Been thanked: 17 times
Contact:

Re: swap file..using zram // media memory

Unread post by BadPritt » Wed Apr 24, 2019 6:16 am

58441412_2628564997160896_4245576069744164864_o.jpg
58441412_2628564997160896_4245576069744164864_o.jpg (250.88 KiB) Viewed 2101 times
Now that's more like it. It's an overkill render. But it works great.
I've installed Stretch on eMMC. Installed zram-odroid, added those lines to /etc/rc.local. Created a swap file of 8GB.
And it runs great. I'm even able to use it for surfing and other tasks while it's full power rendering.

I'll let it finish, I've also overclocked it. No better test to see if it's stable than a very long blender render.
Thank you all. Now it's the beast I dreamed of.
These users thanked the author BadPritt for the post:
xabolcs (Wed Apr 24, 2019 8:22 am)

phaseshifter
Posts: 3473
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 37 times
Been thanked: 42 times
Contact:

Re: swap file..using zram // media memory

Unread post by phaseshifter » Wed Apr 24, 2019 10:09 am

i have one question is the ordering correct as per here

posting.php?mode=reply&f=177&t=34540#pr253376

or if the two extra lines of code to be placed in the rc.local file are correct or should it be like this..below

viewtopic.php?f=177&t=34540#p252303

so my question as i have to edit the post i made correct..so if h-k see`s it as a valid wiki entry ..for other users to benefit from...????

i guess bottom line it will be edit`ed by h-k and made correct either way ...if a wiki entry is not formed then...it would be a shame to be just lost in the pages of the sub forum...phase....
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Wed Apr 24, 2019 11:46 am

phaseshifter wrote:
Wed Apr 24, 2019 10:09 am
i have one question is the ordering correct as per here

posting.php?mode=reply&f=177&t=34540#pr253376

or if the two extra lines of code to be placed in the rc.local file are correct or should it be like this..below

viewtopic.php?f=177&t=34540#p252303

so my question as i have to edit the post i made correct..so if h-k see`s it as a valid wiki entry ..for other users to benefit from...????

i guess bottom line it will be edit`ed by h-k and made correct either way ...if a wiki entry is not formed then...it would be a shame to be just lost in the pages of the sub forum...phase....
The ordering should not make any difference, the lowmemorykiller can be disabled at run time before or after the swap / zram is enabled but I think it should be only considered as a workaround for the time being.

As per @crashoverride I also think the lowmemorykiller needs to be disabled completely from the kernel config at compile time and I can test this later today. I am not sure if this will cause compile errors as per @tobetter comments either but will check. I will also check that with the Android lowmemorykill killer disabled that the Linux Out of Memory (OOM) Killer still functions as expected when RAM is exhausted. (We would rather kill off high memory consumers rather than crash the entire system)

Once this testing is completed we can request hardkernel make the appropriate changes to the kernel to disable the lowmemorykiller permanently for future releases. The workaround should then be removed as it will cause errors running in lc.local as the control files will no longer exist which might cause confusion for users.
These users thanked the author brad for the post:
phaseshifter (Wed Apr 24, 2019 12:27 pm)

User avatar
tobetter
Posts: 3908
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 38 times
Been thanked: 155 times
Contact:

Re: swap file..using zram // media memory

Unread post by tobetter » Wed Apr 24, 2019 12:05 pm

brad wrote:
Wed Apr 24, 2019 11:46 am
phaseshifter wrote:
Wed Apr 24, 2019 10:09 am
i have one question is the ordering correct as per here

posting.php?mode=reply&f=177&t=34540#pr253376

or if the two extra lines of code to be placed in the rc.local file are correct or should it be like this..below

viewtopic.php?f=177&t=34540#p252303

so my question as i have to edit the post i made correct..so if h-k see`s it as a valid wiki entry ..for other users to benefit from...????

i guess bottom line it will be edit`ed by h-k and made correct either way ...if a wiki entry is not formed then...it would be a shame to be just lost in the pages of the sub forum...phase....
The ordering should not make any difference, the lowmemorykiller can be disabled at run time before or after the swap / zram is enabled but I think it should be only considered as a workaround for the time being.

As per @crashoverride I also think the lowmemorykiller needs to be disabled completely from the kernel config at compile time and I can test this later today. I am not sure if this will cause compile errors as per @tobetter comments either but will check. I will also check that with the Android lowmemorykill killer disabled that the Linux Out of Memory (OOM) Killer still functions as expected when RAM is exhausted. (We would rather kill off high memory consumers rather than crash the entire system)

Once this testing is completed we can request hardkernel make the appropriate changes to the kernel to disable the lowmemorykiller permanently for future releases. The workaround should then be removed as it will cause errors running in lc.local as the control files will no longer exist which might cause confusion for users.
This change does not make compile error...disabling CONFIG_ANDROID leads the errors regarding the functions of ion driver.

Code: Select all

diff --git a/arch/arm64/configs/odroidn2_defconfig b/arch/arm64/configs/odroidn2_defconfig
index fa4fb18529b3..8f2d2897b70d 100644
--- a/arch/arm64/configs/odroidn2_defconfig
+++ b/arch/arm64/configs/odroidn2_defconfig
@@ -1595,7 +1595,7 @@ CONFIG_AMLOGIC_VOUT2_SERVE=y
 # Amlogic OSD Module
 #
 CONFIG_AMLOGIC_MEDIA_FB=y
-CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE=y
+# CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE is not set
 CONFIG_AMLOGIC_MEDIA_FB_OSD_VSYNC_RDMA=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_ENABLE=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_CURSOR=y
@@ -4848,10 +4848,9 @@ CONFIG_LIRC_ODROID=m
 #
 # Android
 #
-CONFIG_ASHMEM=y
+# CONFIG_ASHMEM is not set
 # CONFIG_ANDROID_LOGGER is not set
-CONFIG_ANDROID_LOW_MEMORY_KILLER=y
-CONFIG_ANDROID_LOW_MEMORY_KILLER_AUTODETECT_OOM_ADJ_VALUES=y
+# CONFIG_ANDROID_LOW_MEMORY_KILLER is not set
 CONFIG_ION=y
 # CONFIG_ION_TEST is not set
 # CONFIG_ION_DUMMY is not set
@@ -5333,9 +5332,7 @@ CONFIG_ARM_PMU=y
 # Android
 #
 CONFIG_ANDROID=y
-CONFIG_ANDROID_BINDER_IPC=y
-CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"
-# CONFIG_ANDROID_BINDER_IPC_SELFTEST is not set
+# CONFIG_ANDROID_BINDER_IPC is not set
 # CONFIG_LIBNVDIMM is not set
 CONFIG_NVMEM=y
 # CONFIG_STM is not set
These users thanked the author tobetter for the post:
brad (Wed Apr 24, 2019 6:13 pm)

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Wed Apr 24, 2019 6:12 pm

tobetter wrote:
Wed Apr 24, 2019 12:05 pm

Code: Select all

diff --git a/arch/arm64/configs/odroidn2_defconfig b/arch/arm64/configs/odroidn2_defconfig
index fa4fb18529b3..8f2d2897b70d 100644
--- a/arch/arm64/configs/odroidn2_defconfig
+++ b/arch/arm64/configs/odroidn2_defconfig
@@ -1595,7 +1595,7 @@ CONFIG_AMLOGIC_VOUT2_SERVE=y
 # Amlogic OSD Module
 #
 CONFIG_AMLOGIC_MEDIA_FB=y
-CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE=y
+# CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE is not set
 CONFIG_AMLOGIC_MEDIA_FB_OSD_VSYNC_RDMA=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_ENABLE=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_CURSOR=y
@@ -4848,10 +4848,9 @@ CONFIG_LIRC_ODROID=m
 #
 # Android
 #
-CONFIG_ASHMEM=y
+# CONFIG_ASHMEM is not set
 # CONFIG_ANDROID_LOGGER is not set
-CONFIG_ANDROID_LOW_MEMORY_KILLER=y
-CONFIG_ANDROID_LOW_MEMORY_KILLER_AUTODETECT_OOM_ADJ_VALUES=y
+# CONFIG_ANDROID_LOW_MEMORY_KILLER is not set
 CONFIG_ION=y
 # CONFIG_ION_TEST is not set
 # CONFIG_ION_DUMMY is not set
@@ -5333,9 +5332,7 @@ CONFIG_ARM_PMU=y
 # Android
 #
 CONFIG_ANDROID=y
-CONFIG_ANDROID_BINDER_IPC=y
-CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"
-# CONFIG_ANDROID_BINDER_IPC_SELFTEST is not set
+# CONFIG_ANDROID_BINDER_IPC is not set
 # CONFIG_LIBNVDIMM is not set
 CONFIG_NVMEM=y
 # CONFIG_STM is not set
Just to confirm I have tested the config patch and everything seems to be in order. Swap can be consumed and the Linux OOM killer is working correctly when an out of memory condition exists to kill off large consumers rather than just the currently allocating process :)
These users thanked the author brad for the post (total 2):
tobetter (Wed Apr 24, 2019 6:23 pm) • mad_ady (Wed Apr 24, 2019 7:10 pm)

User avatar
tobetter
Posts: 3908
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 38 times
Been thanked: 155 times
Contact:

Re: swap file..using zram // media memory

Unread post by tobetter » Wed Apr 24, 2019 6:23 pm

brad wrote:
Wed Apr 24, 2019 6:12 pm
tobetter wrote:
Wed Apr 24, 2019 12:05 pm

Code: Select all

diff --git a/arch/arm64/configs/odroidn2_defconfig b/arch/arm64/configs/odroidn2_defconfig
index fa4fb18529b3..8f2d2897b70d 100644
--- a/arch/arm64/configs/odroidn2_defconfig
+++ b/arch/arm64/configs/odroidn2_defconfig
@@ -1595,7 +1595,7 @@ CONFIG_AMLOGIC_VOUT2_SERVE=y
 # Amlogic OSD Module
 #
 CONFIG_AMLOGIC_MEDIA_FB=y
-CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE=y
+# CONFIG_AMLOGIC_MEDIA_FB_OSD_SYNC_FENCE is not set
 CONFIG_AMLOGIC_MEDIA_FB_OSD_VSYNC_RDMA=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_ENABLE=y
 CONFIG_AMLOGIC_MEDIA_FB_OSD2_CURSOR=y
@@ -4848,10 +4848,9 @@ CONFIG_LIRC_ODROID=m
 #
 # Android
 #
-CONFIG_ASHMEM=y
+# CONFIG_ASHMEM is not set
 # CONFIG_ANDROID_LOGGER is not set
-CONFIG_ANDROID_LOW_MEMORY_KILLER=y
-CONFIG_ANDROID_LOW_MEMORY_KILLER_AUTODETECT_OOM_ADJ_VALUES=y
+# CONFIG_ANDROID_LOW_MEMORY_KILLER is not set
 CONFIG_ION=y
 # CONFIG_ION_TEST is not set
 # CONFIG_ION_DUMMY is not set
@@ -5333,9 +5332,7 @@ CONFIG_ARM_PMU=y
 # Android
 #
 CONFIG_ANDROID=y
-CONFIG_ANDROID_BINDER_IPC=y
-CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"
-# CONFIG_ANDROID_BINDER_IPC_SELFTEST is not set
+# CONFIG_ANDROID_BINDER_IPC is not set
 # CONFIG_LIBNVDIMM is not set
 CONFIG_NVMEM=y
 # CONFIG_STM is not set
Just to confirm I have tested the config patch and everything seems to be in order. Swap can be consumed and the Linux OOM killer is working correctly when an out of memory condition exists to kill off large consumers rather than just the currently allocating process :)
Cool, thanks for testing...will do another test and merge the patch soon.

phaseshifter
Posts: 3473
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 37 times
Been thanked: 42 times
Contact:

Re: swap file..using zram // media memory

Unread post by phaseshifter » Fri May 03, 2019 8:56 pm

can any body tell me the status of this z-ram project is it all fixed ..and ready to work given if the latest kernel is updated..????
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

brad
Posts: 965
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 H2 (64 bit ftw)
Location: Australia
Has thanked: 16 times
Been thanked: 32 times
Contact:

Re: swap file..using zram // media memory

Unread post by brad » Fri May 03, 2019 9:32 pm

phaseshifter wrote:
Fri May 03, 2019 8:56 pm
can any body tell me the status of this z-ram project is it all fixed ..and ready to work given if the latest kernel is updated..????
Yes it should be in >=4.9.169 now

phaseshifter
Posts: 3473
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 37 times
Been thanked: 42 times
Contact:

Re: swap file..using zram // media memory

Unread post by phaseshifter » Mon May 06, 2019 1:18 am

well can any body tell me if there will be a wiki entry of the z-am..??..i am shure users would value from the knowing..
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

phaseshifter
Posts: 3473
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 37 times
Been thanked: 42 times
Contact:

Re: swap file..using zram // media memory

Unread post by phaseshifter » Mon May 13, 2019 4:26 pm

i know that there have been kernel adjustments allowing for the implementation of virtual memory but yet this thread and my wiki guide i feel will be lost in the "vault" so to speak

ok so i am wondering if any thought had been given weather or not to implement this into a future image as an entry level of say 1 or 2 gigs of standard swap memory or whatever is decided..

thus a wiki entry made with a guide on how to adjust the swap file size

and or just a complete wiki entry made allowing users the option to install it themselves .

thank-you ...phase.......

@odroid
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

phaseshifter
Posts: 3473
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 37 times
Been thanked: 42 times
Contact:

Re: swap file..using zram // media memory

Unread post by phaseshifter » Wed Jun 19, 2019 2:49 pm

to see swap mem code this

Code: Select all

free -t
but yet there is no dedicated partition when viewing the drive in gparted...
it does not show as a partition nor does it show that it is there...in used size...
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 2 guests