Wednesday, June 25, 2014

One strange memory leak

I am working with some PDF processing library on a server side application. For some time now I have seen quite a huge memory leak and I started to investigate.
Apart from the obvious streams not closed I could see nothing wrong in the code.
However I decided to have a deeper look and i issued the following command

ltrace -fCS -p `pidof tomcat` 2>leak.out 1>&2

To my surprise I have seen lots of SYS_fork() in the output meaning that the library forked the entire appserver :) - WOW. It was not an disaster because fork() is COW so the memory is duplicated only when the children write something - but as this is an appserver it is kind of a heavy operation to fork it every time.

This also explained why the system seemed to leak memory. During the execution of the children processes new buffers are allocated and as the new processes have their own lifecycle it consumes quite a lot of memory.


Sunday, June 1, 2014

D-Link DNS-320 revival

I have spent quite a time to revive my DNS-320 NAS. It's flash memory died last week - some bad block in u-boot... strange that it was not detected. So. I grabbed the tools and started to work on NAS revival.
I found an USB to SERIAL adapter based on PL-2303HX chipset and I soldered a serial connector on the NAS's motherboard (much to my wife's reluctance). I have compiled a u-boot based on Jamie Lentin's instructions. Using kwuart tool I have been able to boot the NAS with the new u-boot and I could write it to the nand.
The next thing was to create a Debian filesystem based on wheezy - again it was quite ok - bootstrapped it successfully and wrote it to on of the hard drives. Then I tried to modify the nand partitioning as to be able to use the ubifs on nand. Despite my efforts I haven't been able to make it work so I booted NAS with an external USB stick holding kernel + ramdisk.
Then I had an epiphany and I realised that I could write the kernel and ramdisk directly in nand and load them directly and boot them with bootm. WORKED!!! Quickly wrote the settings in u-boot's env.
I had a fully working Debian 7 Wheezy - so I was able to install all the goodies that previously were crippled on fun-plug. Now I have transmission, lighttpd, ajenti. Decently working avahi, samba, cups and netatalk. I also got NTFS3g support and ext4 + btrfs (the original firmware had only ext3)
The nas temperature is now about 44-46 degrees - slightly higher than with original firmware although the CPU usage is lower.
DNS-320 with Debian is for sure no concurrent to Zyxel-325V2, or Synology devices, but it does quite a decent job.