Monday, June 30, 2008

Memory management - low allocator base - binary buddy.

As I intended to memory managers implementing, I decide to write here about several techniques about this.
I don't interested on allocators in uspace now. I want to describe some tips and tricks on memory management while you haven't anything - just raw gdt/tss/ so on and raw addresses.
On low level of memory management and allocation system we're need to have a simple and fast memory allocator, it must avoid external fragmentation as strong as it possible.
There are one good allocator that doesn't sick with big external fragmentation - buddy system. You can find many it's types, but I'd like binary type - it's a very simple in calculation (that really needs).
Some words about buddy system... Buddy system is a such system that based on buddy relations for splitting memory areas. This system has several limitation - you must know deep of separation, I mean how much blocks maximally can contents buddy itself, and overally it can maps fixed memory area size (but it can be depends on implementation). The goal of this technique is to find free block aligned to requested size, when you are looking for some block size - you will separate block with bigger size and so on, while you didn't finf more situable block size. Look for illustrations: 
buddy system explanation
Fig. 1

The first bar shows clean buddy system without any allocated block (4096 bytes). When we're requesting to allocate block with size 512 byte we're separate zone to two blocks, and one of this zone separate we're separate too and use one of them - like it shown on the second bar. If we're request to allocate three more 512-sized block we will got the picture displayed on third bar.
It's a good and relativetly fast methodics, but has many restrictions - for example assume that your buddy system has 16byte-sized minimal blocks - and you request 10 bytes - so, you will get a wasted space - and so on - it's an inernal fragmentation. Be sure - you can align block sizes to other numbers , like you want and depend on your target, but anyway it will not safe to use buddy for all allocations.
Another point is a free/busy/separated blocks list storing - on low level you cannot use binary trees in case that they need to have some memory allocation technique already, usually for this used simple pointers lists, but it's a worse practice.
On the next post about memory management I will describe my solution of this problem with some useful code snippets.

Friday, June 27, 2008

Protest award domain name nativization from ICANN

So, there are bad news, no ICANN supports 'internalization' of domain names, now it's a possible to register a domain with your native language.
Due to many reasons - I decide to apply a protest for it - it's nothing, but maybe you will be participate on this.
And so on - I'll not post anything on languages differs from english, no jabber/blog/boards/sms/emails messages on non english from tomorrow !
I don't want to make a freedom to spooffing and idiotic things.

Participate if it possible.

I can feel your skeptics looks, yes - I'm just man and I don't have a voice in ICANN, but assume if there are many people like me? You know - world is small ;) And there are just time need ... and this protest will be effective. But anyway, if you will do nothing with it, in future with idiotic domains you will told yourself - "fuck'em up, I don't participate in protest, maybe my voice can be useful at there times ... shit shit shit" - feeling difference - take a voice, participate in this protest, control your life!

If you will participate, please comment here - thank you!

Tuesday, June 24, 2008

MuiString higher memory management

I've made some researching and emulation (not so serios, but representative) about memory management in microkernel OS.
Many kernels does memory management fully in kernel space, others separate it and offer non-trivial API for doing this in userspace.
We're have many restrictions - security and performance. If you will targeting to one of this properties you will loose on other. If you want to have a very strong and secure mechanism you will make a many context switching within kernel and user spaces - it will slow down your system perfomance, if you will don't care about security you will make it faster ...
I decide to make a basics virtual memory manager operations within kernel space, and offer simple API (just 4 calls) - address_space_get(), address_space_set(), address_space_alloc(), address_space_release(). And ... bind page fault exception to userspace area virtual mm server.
In this scheme microkernel just mark/unmark address space, it doesn't makes a check (and it will works fast) , and microkernel doesn't care about page fault exception - it's a server headache.
The security implemented on userspace - with ACL server that cannot be exchanged - like other varios servers (you must load its via multiboot modules way), all requests to ACL cached to the IPC cache server (it cannot be exchanged too) to avoid premiary access violation checks and grow up speed of requests. On the figure below I've tried to show it graphically (I like this, but I don't like to make a graphics ...):
Figure. 1

User task just trying to take some virtual memory and extend it's address space - it's a deal of libs to make all job with calling of vmm server. Vmm server asks about access rights/limits/etc ... on ACL server, if all granted - vmm will allocate space for user task, if will be need - it will calls MuiString microkernel via simple API.

This structure allows to make secure and fast (compairing with some highly secured or highly fast microkernel systems) - it's a good design for implementing different models of memory allocations (real-time, preemption, so on ...)

Monday, June 23, 2008

Emacs #1 - saving your state after exit , and tabbar use

Often you need to restore your emacs session, but it's not a good way to load all buffer per start, just keep it.
Also, there are useful addition to emacs called tabbar.el it can keeps your buffers without its creating.
I don't want to write where you can find this file - if you are using debian you can find it out in emacs-goodies-el package.
So, the first step is to enable tabbar mode by default:

(tabbar-mode t)

After this I recommend to bind a keys for switch between tabs:

(global-set-key [(control shift w)] 'tabbar-forward)
(global-set-key [(control shift q)] 'tabbar-backward)
(global-set-key [(control shift e)] 'tabbar-forward-group)
(global-set-key [(control shift d)] 'tabbar-backward-group)

You can use your own key bindings depending on your choice and feel.
The second step is to use a desktop addition (that comes with emacs22):

(when (fboundp 'desktop-load-default)
(lambda (symbol)
(add-to-list 'desktop-globals-to-save symbol))
'((buffer-name-history . 100)
(dired-regexp-history . 20)
(extended-command-history . 100)
(file-name-history . 500)
(grep-history . 50)
(minibuffer-history . 100)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
(search-ring . 20)
(shell-command-history . 50)))
;;; (desktop-read)

(add-to-list 'desktop-locals-to-save 'buffer-file-coding-system)
(add-to-list 'desktop-locals-to-save 'tab-width)

(setq-default desktop-missing-file-warning nil)
(setq-default desktop-path (quote ("~")))
(setq-default desktop-save t)
(setq-default desktop-save-mode t)

(setq-default save-place t)

And this all, this code snippets from my ~/.emacs file.

Using Gnome ?! really with modifications ...

I'm using Gnome 2.xx in case of some features that I need.
The first, if you know, network-manager knows about many specifics of many Wi-Fi modules tricks, for example for my RaLink card (that cannot be changed in my notebook) - it's needed to be downed and after this up with new network settings. So, I'm using many wireless networks (office, pubs, train stations, passenger terminals, ...) - but other network managers can't operates with my card, doing many stuff manually isn't sounds good for me - I'm lazy...
If you are using Gnome you know the base minus of it - it's a default window manager - metacity, this wm cannot remember anything about windows position, size and other varios attributes.
Also, on other side there are tiled window managers, but its takes many time to make a sense on configs and features.
The better way is to use my old friend - Window Maker wm, there are simple setting up, and it has many look and features that can be offered in tiled managers.
It can be looks like on my screenshot - Free Image Hosting at


So, but Gnome feature - changing window manager is deprecated and all settings made over a gconf was failed. Solution was found - I've create ~/.gnomerc file and add the following line -
export WINDOW_MANAGER=wmaker
This line helps for it.
Also you can change some things like abort nautilus loading etc ... It will safe your memory and will turn off features for idiots.

Friday, June 20, 2008

AMD64 #1 - Long Mode

Backing to old days the first tree of microkernel was targeted to the x86 (32bit), going deeper the parent of all post projects (ilix) was targeted to embedded hardware i.e. arm and one internal architecture that was 24 bit.
Nowadays we're have a public accessible and cheep 64bit long architecture, x86 continuing but with 64bit long extension, but on real - it's looks different.
allows many good extended features compairing with basic x86 32bit long structure. To use AMD64 features on full filled hand we're must operate in long mode (amd64 specific mode).
On truth, long mode is a mixed mode i.e. it operates on 64-bit mode and compatibility mode at one time. It has self minuses - it's a flat memory model. But it has 64-bit addressing and we're don't need for tricks with extension from intel to use more than 4Gb address space addressing, that relatively ugly and looks like an ugly hack.
Like a microkernel developer and low developer at one time - the first problem is initialization.
I've read AMD64 documentation directly from AMD, but there are no anything to really help with it, not at all, but if you want to make a sense quickly it's not usable.
I've designed a trick with it, saying simply it consist from following steps :
32bit code:
  • - initialize stack pointer (regarding your boot method and loader, I'm using grub and multiboot)
  • - init bootstrap GDT
  • - jump to 'meet point' within existing GDT
  • - save parameters from grub (will be need on if you using grub)
  • - we're falled on 32bit protected mode (legacy mode on AMD64)
  • - check for varios CPU features (it must be made if you want to made all like it must be in good kernels)
  • - check for AMD64 long mode support is a really needed (you should do it, otherwise you can except some bug - I don't know why - check it if I correct)
  • - all is ok, - enabling 64bit page translations (regarding to documentation set - cr4.pae=1)
  • - setup pages tables
  • - enable long mode (via EFER reg - setting LME to 1)
  • - enable paging in long mode (it will activate long mode and we're falling to compatibility mode)
  • - just jump to your 64bit code
64bit code:
  • - do your stuff, have a lot of fun ... ;)
I'm sure that there are direct long mode switching, but for me it was more quickly to make it like I've describe.

Tuesday, June 17, 2008

MuiString introduction

Ok, I've told many information about Jari and so on ... But it was just a buzz words.
Now I want to present MuiString (mstring) microkernel project.
What is done?
- base structure
- low level stuff
How much time it will takes ? How long will I told about it without microkernel on legs ? Hm, so I think that this times ends in case of microkernel progress.

I promise to write more technical things here and ... look for links below -
MuiString homepage -
MuiString wiki -
I have a memory manager and core of scheduler in my sandbox, it's under testing and preparing to be committed to the general CVS repository.
Look for my messages here soon.


Wednesday, June 04, 2008

Web fun - redleaf

How I wrote before - I opened a new project just for fun - and now it has releases and it's working -
But there are no time for prolongate any active development - I've spent less than 10 hours for this, and in future this will so.
If you want to take my flash point on this project - contact me, I'll be glad for it.
Anyway, this project will be like my testing platform - and some kinds of tasks will be implemented within this and tested.

Decomposing big project, separating is better

You can find more information on the link in the post title.
Overally, following to the general idea - "separate all works and job to smaller ones" I decide to run microkernel separatly - like independed project.
This intended to be more effective, for example - currently I have EZA layer working for 60% (not so stable) and this was made after reorganization of the microkernel structure - and this just for less then 10 hours of normal works on the problem.
MString (MuiString) - is a name for Jari microkernel - and it's a new tag on this blog ;)
Now I'm thinking on diferent than C/Cext language for server space - it's a big flame, but I'm thinking that fully functional languages or partly functional is better than typical imperativies ones. Anyway, microkernel must be implemented on plain C - it's more comfortable language.