View Single Post
Old 02-16-2016, 10:57 AM   #10
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
For our two level swap space, we want a relatively small area of RAM as the first choice swap area followed by a larger, and much slower, area in /var/local (/dev/mmcblk0p3).
This will be an enhancement over the ASUS idea of swap in RAM.

Since the Kernel used with the PW-3 does not have the brd module (ramdisk) available we will have to sneak up on this layout in a round-about way.
So round-about you would expect the memory page being written might get lost.

Update: It does, the system deadlocks.
I left the step-by-step here for a reference to one way **not** to do this.

The tmpfs filesystem is implemented in the VFS i/o cache buffers and store backed by swap.
The i/o cache buffers are dynamic in number and occupy all un-used RAM at any moment.

Learn about the temporary sub-tree of the system file tree, located in tmpfs and not subject to the mntroot ro/rw thingy:
Code:
[root@kindle root]# df /var
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    32768       444     32324   1% /var

[root@kindle root]# cd /var
[root@kindle /var]# ls
backups  cache    lib      local    lock     log      run      tmp
We need a directory there to serve as the mount point for a ext2 file system, store backed by tmpfs.
Code:
[root@kindle /var]# mkdir swp
[root@kindle /var]# mount -t tmpfs -o size=4M ext2 /var/swp
[root@kindle /var]# ls /var/swp
- - empty - -
Within that 4 Mbyte file system, make a 2 Mbyte file and lookup some of the things we can learn about it.
Code:
[root@kindle /var]# dd if=/dev/zero of=/var/swp/lvl1 bs=1024 count=2048
2048+0 records in
2048+0 records out
2097152 bytes (2.0MB) copied, 0.013983 seconds, 143.0MB/s

[root@kindle /var]# ls -l swp
-rw-rw-r--    1 root     root       2097152 Feb 16 09:56 lvl1

[root@kindle /var]# df swp
Filesystem           1K-blocks      Used Available Use% Mounted on
ext2                      4096      2056      2040  50% /var/swp

[root@kindle /var]# stat swp/lvl1
  File: swp/lvl1
  Size: 2097152         Blocks: 4112       IO Block: 4096   regular file
Device: 10h/16d Inode: 36085       Links: 1
Access: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-02-16 09:56:30.000000000
Modify: 2016-02-16 09:56:30.000000000
Change: 2016-02-16 09:56:30.000000000
This step is just to show an example that we can't use that file directly for a swap file.
Code:
[root@kindle /var]# mkswap /var/swp/lvl1
Setting up swapspace version 1, size = 2093 kB
no label, UUID=813fd1a8-8936-477d-ad00-554654df4263

[root@kindle /var]# swapon /var/swp/lvl1
[46919.620721] swapon: swapfile has holes
swapon: /var/swp/lvl1: Invalid argument
Is this idea dead at this point?
No, not if we insist.
Turn that file into a block device and format the device as swap:
Code:
[root@kindle /var]# losetup /dev/loop/8 /var/swp/lvl1

[root@kindle /var]# mkswap /dev/loop/8
Setting up swapspace version 1, size = 2093 kB
no label, UUID=c7e292e5-0188-4c08-b7de-ab984f3ec9b7
The swapon/swapoff utility provided does not accept a priority option.
But taking advantage of the fact that the system, if not told otherwise, assigns priorities in the order of assignment.
We will set our fast ram swap area to be used before our slow eMMC swap area created previously in this theard.
Code:
[root@kindle /var]# swapon /dev/loop/8
[root@kindle /var]# swapon /var/local/swap

[root@kindle /var]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/loop/8                             partition       2044    0       -1
/var/local/swap                         file            16016   0       -2
[root@kindle /var]#
Now we will just 'use' the PW-3 and see if it turns into a brick.

At first, it looked like things where working out well:
Code:
[root@kindle root]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/loop/8                             partition       2044    2044    -1
/var/local/swap                         file            16016   380     -2
But opening the third book caused the system to become non-responsive.
I.E: nothing happened when touching the touchscreen.
Serial port is still alive and well, so it looks like it is time for a:
shutdown -r now
command and a complete re-think of this two level deal.

Hmm... now this can't be good:
Code:
[root@kindle root]# shutdown -r now

[root@kindle root]# Broadcast message from root@kindle
        (/dev/ttymxc0) at 10:43 ...

The system is going down for reboot NOW!
info shutdown:begin:level=6,halt=,special=:
info shutdown:closing password dialog::

[root@kindle root]# [49680.325874] INFO: task dbus-daemon:2169 blocked for more than 120 seco.
- - - -
Well, now try turning off the swap usage and see if we can recover this device:
Code:
[root@kindle root]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/loop/8                             partition       2044    2044    -1
/var/local/swap                         file            16016   380     -2
[root@kindle root]# swapoff /var/local/swap
[root@kindle root]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/loop/8                             partition       2044    2044    -1
[root@kindle root]# swapoff /dev/loop/8
At which point now even the serial port is non-responsive.

Two more things to try:
Long press on the power button.
If that doesn't work, open the case and remove battery.
- - - - -
The power button re-boot worked.
And all of the stuff above in tmpfs went away (as intended).

Yup, this is going to take a long, long bit of thought.

Last edited by knc1; 02-16-2016 at 11:02 AM.
knc1 is offline   Reply With Quote