Active Topics

 


Reply
Thread Tools
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#161
Sorry for possibly lame question, but how swap fragmentation can occur o flash based disk? Doesn't hardware controller do "fragmentation" all the time no matter what, due to wear leveling? Especially, when swap is on microSD - I'm not certain if hardware wear leveling occur on eMMC, but SD cards got hardware wear leveling for sure, and as far as i know it is completely transparent for any software controller, IE. filesystem doesn't matter at all.

I would really like to read our specialist explanation on this though, cause it is highly possible that i missed something.
 
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#162
Wear leveling doesn't guarantee performance.

Flash erase blocks are some 256k - 1024k big.

On SD, MMC, eMMC and most USB flash keys, if you write 4k, the card takes an unused block, erases it, and writes that 4k to it. If you write other stuff to same block afterwards, it too gets written. If you go write somewhere else outside of that block, the card reads in the data missing from filling up 256k from the old block, marks old block unused, and writes it to new block.

Thus, if you're doing random 4k writes, the card ends up writing 256k for every request. Obviously that's 64 times slower.
 

The Following 3 Users Say Thank You to shadowjk For This Useful Post:
Posts: 284 | Thanked: 320 times | Joined on May 2010 @ Peterborough, UK
#163
Originally Posted by shadowjk View Post
I have a script which looks at the output of 'iostat -m' command. When the amount of megabytes written to a swap partition exceeds the size of the swap partition, the fragmentation effects start. I store the megabytes written in a file after reswap(swapon temp, swapoff main, swapon main, swapoff temp) and keep track of bytes written after last reswap.
Hey, is this the script you speak of? I'm a bit confused as to why it's looking at mmcblk0p2, and also the swap bits at the end are giving me a headache trying to figure out
 
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#164
oooh boy, swap scripts! here is my swapswap script.

This script simply swaps the swap from one drive to the other. That means to 'refresh' the swap you would run it twice. The script is also able to automatically figure out which partition on the sdcard is the swap. It is partially based on a script suggested by 'whitewolf' in the 'swap on sd' thread.

Code:
#!/bin/sh
#swapswap
current_swap=$( cat /proc/swaps | awk '/mmcblk/ {print $1}' | cut -d "k" -f2 ut -c1)
drivelist=$(sfdisk -lnd /dev/mmcblk1)
swapmicro=$(echo "$drivelist" -n | grep Id=82 | awk '/mmcblk1/ {print $1}')

if [ "$current_swap" = "0" ]; then
        if [ "$swapmicro" ]; then
            swapon $swapmicro
            swapoff /dev/mmcblk0p3
        fi
#echo "swap is on sd"
elif [ "$current_swap" = "1" ]; then
        swapon /dev/mmcblk0p3
        swapoff $swapmicro
#echo "swap is on emmc"
fi

ya follow?



I have the following script run at 0330 to refresh the swap space.

Code:
#!/bin/sh
#check if device is not in use, if so swapswap!
brightness=$(cat /sys/class/backlight/acx565akm/brightness)
keyboard=$(cat /sys/devices/platform/gpio-switch/slide/state)

if [ "$brightness" == "0" ]; then
        if [ "$keyboard" == "closed" ]; then
                echo "/opt/scripts/swapswap.sh" | root
                echo "/opt/scripts/swapswap.sh" | root
        fi
fi
This checks to see if the device is in use (unlikly@0330. However you never know, I like my scripts to be bullet proof). If not, then it calls swapswap twice once to move it over, once to move it back.
__________________
N900: One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.
 

The Following 7 Users Say Thank You to vi_ For This Useful Post:
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#165
Originally Posted by Tigerite View Post
Hey, is this the script you speak of? I'm a bit confused as to why it's looking at mmcblk0p2, and also the swap bits at the end are giving me a headache trying to figure out

Because that's where my swap is.

Also, maemo renames mmcblk1 to mmcblk0 and other way around, but the old name sticks in some cases like iostat, but not swpon/swapoff.


This script is most likely unusable for anyone else. I only put it up on request from someone, to show him how I did it.
 
Posts: 284 | Thanked: 320 times | Joined on May 2010 @ Peterborough, UK
#166
I wasn't meaning to be rude, simply trying to understand it and modify it for my own purposes. I didn't realise that about iostat - thanks for the pointer. I can see it swapons the "backup" swap, swapoffs the "normal" swap, updates reswap.stat (although earlier on in the script it doesn't specifically look in /root), then swapons the "normal" swap again before a final swapoff of the "backup" - but then it swapons the "backup" again, which is the bit I'm confused about?

By the way, I really appreciate the charge script found elsewhere on that same site - it's excellent! Thanks
 
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#167
I hope you're using charge21.sh which is newest right now...

I always run it out of /root, so iconsistencies in relative vs absolute paths never hit me

Additionally I have a script that I run on every boot, which among other things set reswap.stat to 0.

mmcblk0p3 is normal emmc swap. mmcblk1p3 in iostat.
mmcblk1p2 is microsd swap, mmcblk0p2 in iostat.

I leave emmc swap on, it sits at lower priority anyway, so I only have to do a swapoff if I want to remove back cover. No other particular reason. At one point I probably had a swapon binary with priority support and had emmc+usd at equal priority, but then I concluded performance was nicer when swap was dedicated to usd.

The general idea is indeed: swapon emmc, swapoff usd, swapon usd, swapoff emmc, swapon emmc.
 

The Following 4 Users Say Thank You to shadowjk For This Useful Post:
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#168
Originally Posted by shadowjk View Post
I hope you're using charge21.sh which is newest right now...

I always run it out of /root, so iconsistencies in relative vs absolute paths never hit me

Additionally I have a script that I run on every boot, which among other things set reswap.stat to 0.

mmcblk0p3 is normal emmc swap. mmcblk1p3 in iostat.
mmcblk1p2 is microsd swap, mmcblk0p2 in iostat.

I leave emmc swap on, it sits at lower priority anyway, so I only have to do a swapoff if I want to remove back cover. No other particular reason. At one point I probably had a swapon binary with priority support and had emmc+usd at equal priority, but then I concluded performance was nicer when swap was dedicated to usd.

The general idea is indeed: swapon emmc, swapoff usd, swapon usd, swapoff emmc, swapon emmc.
You have my attention. Please talk me through this charge script. What do you use it for? Do you feel bme is inadequate for your purposes?
__________________
N900: One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.

Last edited by vi_; 2011-05-19 at 21:21.
 
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#169
Originally DocScrutinizer made a small script (it didn't work) prototype for charging without bme, probably intended as a prototype proof of concept for charging during hostmode operations. This was way before hostmode became working. I took the script and modified and built upon it (maybe 3 lines remaining from the original by now).

I had obtained a Mugen power battery and wanted to charge faster than bme. However, it turned out charging at higher rates produced almost exponentially more heat. So, I added thermal throttling to the charger, and was back at same rate.

We had previously observed a somewhat non-ideal charge curve from bme, and thought running the hw charger would fix that. Turned out to be caused by non-zero resistance in the circuit board.


Probably the only benefit is that you can charge without bme, and due to lack of checks, doesn't care about whether D+/D- is shorted or not. Might have side effect of frying USB ports on PCs, but I never myself charge from PC.

I should probably put warning at the top if people have discovered its existance and randomly downloading it.
 

The Following 7 Users Say Thank You to shadowjk For This Useful Post:
Posts: 284 | Thanked: 320 times | Joined on May 2010 @ Peterborough, UK
#170
I am using the latest charge21.sh, thanks for the detailed description of what it does and why. By the way the iostat included in busybox after installing busybox-power, when using kernel-power 47 at least, doesn't switch mmcblk0 and 1 around (thus my initial confusion). It's still a useful script which I'll no doubt modify for my own purposes
 

The Following User Says Thank You to Tigerite For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 15:58.