PYNQ Image Memory settings

Custom board 7020
PYNQ 2.7

Hello all,

I would like to know how to set the swap size and what impact would introduce when sizing up and down?

Thank you

1 Like

@stf

Shane could help a bit on this topic to let us know more.
Thank you

ENJOY~

Hi Brian,

Sure, I can try. So the swap space is space reserved on disk (the SD Card) in case your system runs out of RAM. Once you run out of RAM the swap partition will be used instead. Allocating swap space means that your system will have a bit less disk space (the swap space cannot be used for anything else); however, it does mean that you have increased the amount of virtual memory for the system. One thing to remember, however, is that accessing the swap space will be incredibly slow, so if you run out of RAM and start swapping, your performance will fall off a cliff. Usually, on a 7020, the system is barely responsive, in my experience. Another thing to consider is that if you frequently access the SD card via the swap space, you might wear the SD Card out a bit faster, as you will be doing a lot of small reads/writes.

I’ve never tried to increase the swap space size before, but I believe there are a few ways to do it. You can either create a swap file (using dd) and then use the mkswap and swapon commands to set it up. Or I think you can setup a larger partition on your disk. This looks like a pretty decent tutorial on it: Adding Swap Space on Ubuntu 20.04: A Tutorial • CloudSigma

I hope that helps a bit,
Shane

2 Likes

@stf

First appreciate the deep explanations.
Meanwhile, what are the reason the default PYNQ image 2.7 or above version had default 1/2 of the main memory size of swap memory?
Is there are major reason to PYNQ system or the Ubuntu that running?
It is also good to learn more what if the main memory now changed to 512M DDR3, would the swap size become 256M?

So above from main memory aka DDR3 (if not wrongly interpreted) the swap memory should considered as main memory layer or storage layer (between)?

Also (sorry for my lack of knowledge in Linux kernel and memory design) CMA-contiguous memory access should also considered as apart of the main memory in PYNQ system. Any impact could reduce or improve the script process and the execution between the FPGA<->ARM<->User Program?

Thank Shane,

Enjoy~

1 Like

Hiya Brian,

Meanwhile, what are the reason the default PYNQ image 2.7 or above version had default 1/2 of the main memory size of swap memory?

I’m afraid I’m not sure the reason for this change. Perhaps there were some applications on some boards that would be quite memory constrained?

So above from main memory aka DDR3 (if not wrongly interpreted) the swap memory should considered as main memory layer or storage layer (between)?

Well from the CPU’s perspective this is all virtual memory. So it looks like it is all part of the same contiguous (main memory) address space. There is a layer of indirection in between to pull in pages from the swap space, things like a TLB provide this mechanism.

Also (sorry for my lack of knowledge in Linux kernel and memory design) CMA-contiguous memory access should also considered as apart of the main memory in PYNQ system. Any impact could reduce or improve the script process and the execution between the FPGA<->ARM<->User Program?

This is also linked to this virtual addressing. So from SW we access buffers to communicate with the PL through a virtual address. However, on the PL side virtual addressing doesn’t work, so the kernel portion of XRT does a translation from the virtual address to a physical address which is passed to the PL. So on the PL-side we use physical addresses, but from the User Program we use virtual addresses.

XRT “pins” these buffers in memory, also called page-locking, so that they cannot be moved and swapped out to disk in the swap space. Locking down the buffer addressing in this way means that when you access a buffer from either the User Program via a virtual address or the PL with the physical address, you are accessing some memory in DDR.

Unless you are allocated loads and loads of buffers and pinning most of the memory, you shouldn’t have to worry about increasing the swap space size. But if you have so many buffers that your applications run out of memory, it could be a consideration.

All the best,
Shane

2 Likes

@stf

Again, learn a lot from these info. Thank you Shane

Maybe simplify a bit more to clear out the info, so in these behaviors:
CMA is undergo a VIVT or PIPT or VIPT or PIVT? {P-Physical, V-Virtual, I-Index, T-Tag}

So correct me if I misunderstood:
CMA ~= TLB (behavior)
Swap memory ~= main memory (behavior)

Both of them are additional set of memory to support the inherent structure of the ARM and DDR3.

Thanks,

Enjoy~

@stf

Shane I am not sure this topic is extendable or not if a new post is preferred, feel free to move.

When I am using the PYNQ 2.7 image:

Unable to handle kernel paging request at virtual address 30313065
pgd = afc4d390
[30313065] *pgd=00000000
Internal error: Oops - BUG: 5 [#1] PREEMPT SMP ARM
Modules linked in: 8189fs(O) mac80211 libarc4 cfg80211 [last unloaded: cfg80211]
CPU: 0 PID: 833 Comm: kworker/0:2 Tainted: G O 5.4.0-xilinx #1
Hardware name: Xilinx Zynq Platform
Workqueue: events sdio_irq_work
PC is at mmc_io_rw_direct+0x8/0x10
LR is at sdio_enable_wide+0xac/0xe4
pc : [] lr : [] psr: a00f0013
sp : ee9e1d20 ip : 00000002 fp : c0b0bb84
r10: ef18caf4 r9 : 00000034 r8 : 00000000
r7 : 00000007 r6 : fffffff4 r5 : fffffff4 r4 : 30313065
r3 : 00000007 r2 : fffffff4 r1 : 00000000 r0 : 30313065
Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
Control: 18c5387d Table: 2ea0404a DAC: 00000051
Process kworker/0:2 (pid: 833, stack limit = 0x47ca5288)
Stack: (0xee9e1d20 to 0xee9e2000)

I am not sure why when running some large applications this would happen.

Your help would be grateful.

ENJOY~

Hi Brian,

This looks like the type of kernel panic that you get when trying to access a region of memory that you are not supposed to or that does not exist. Can you give me a bit more info as to what is triggering the kernel panic?

All the best,
Shane

1 Like

@stf

Once again thank you for helping out (not really SW guy).
Le me try to attach more background info:
Image version PYNQ 2.7:
Wireless CFG80211 and MAC is module and run after auto login (should be stable).
Enable wireless device to make the PYNQ able to connect via STA mode.
Run custom PL and software (large video stream).
However to reduce such addressing and possible design fault I will had remove the PL design and simply run

memtester

with the free memory size via

free

So this is what happen when the wireless USB for example is running on PYNQ.

Hope this could help to brainstorm more.

ENJOY~

@stf

Any good idea or suggestion could help to debug or resolve this issue.
Thank you

ENJOY~

Hiya Brian,

Sorry I’ve been away for the past few days which has delayed my response.

Can I just clarify a few things:

  • Is this happening when you run memtester on your device? What were your memtester arguments?
  • What is the available memory in your system? How much swap space have you allocated?

All the best,
Shane

@stf

From beginning the problem is triggered by large video stream design.
So I tried to remove unnecessary design fault by utilizing memtester as a large memory R/W engine.

The memtester argument is defined by

free -mega

Which custom board is 1GB DDR3 but there are some memory is used after boot.

Swap space is set to 0

THANKS

ENJOY~

Hiya Brian,

So my guess (I don’t know for certain) would be that you don’t have any swap space and are running out of memory and triggering a kernel panic. I think running memtester with no swap space could lead to an out-of-memory issue depending on what else is running on the system. memtester will stress the limits of the memory and if you only have 1GB and no swap space then potentially another process might start up while the test is happening and cause some issues.

I would maybe try running memtester without the free argument and instead provide an argument for an amount of memory that you’d like to test.

Sorry I can’t be more help than that.

All the best,
Shane

@stf

Thanks again for helping out more.

Shane allow me to reduce the question to a simplified question:
Swap space is a MUST in PYNQ or any ARM Ubuntu OS?
Without swap space default DDR3 is insufficient?

Thank you

ENJOY~

@stf

Sorry for open back the previous issue.
But after several production image development the swap memory not matter it is 512GB DDR nor 1GB is all set to 512GB on swap memory.
Shane I think this need to be fixed accordingly as the link you have enclose mentioned 1GB system memory should create 1GB swap space so there must be some build script setting need to modify.

It would be nice to guide a bit which script should be related to such setting.

Thank you,
ENJOY~

Heya Brian,

No worries.
I’m not sure if this helps, but I believe that this is the script where the Swap space is changed in PYNQ. PYNQ/sdbuild/packages/resizefs/resizefs.sh at de6b6fc3a803945d59f8f06523addfe0d9b60a1c · Xilinx/PYNQ · GitHub

You could try to modify that if you require a different swap space configuration.

All the best,
Shane

1 Like

Hi Shane,

Appreciate the pinpoint targeted script. I guess you can also make this parameter dynamic to the XSA ZYNQ memory size so all Image build can undergo the rules that you had mentioned in the link.
ratio of 1:1 swap memory space. =]

ENJOY~