Liuw's Thinkpad

想要赢就先学会输,想要成功就先学会失败

Archive for the ‘linux’ tag

Can’t help writing this down: is it really so hard to find a buzheteng Linux distro?

without comments

It’s SUNDAY! Time for ranting!

It may seem weired that I rant in English — anyway I’m not a native English speaker and the best rant always comes from one’s mother tongue. BUT there is no Chinese input method on this system, so I have to writing this down in English.

You can bet I’m on Linux now, yes, you’re right. I’m playing with Fedora 16 in a live USB key. The default desktop is Gnome 3 — another disaster for a long time Gnome 2 user. It seems that the Unity-like UI is getting more and more popular. Well, I can adapt myself to new UI. However, PLEASE do better design. The new UI is driving both ordinary users and developers (who use Linux as developing platform) away IMHO.

For new users / Linux noobs: Configuration ability is very weak — look at those few icons in the control panel. What’s worse, the default style of the desktop sucks — large portion of my screen is occupied by useless window frame and menu (take firefox as an example). I wish I could tweak font size to make it not so ugly, but I just can’t find a tool to do that. This will eventually lead to comments like “Linux is ugly and difficult to use”.

For developers: How can I tweak this system? I need my menu back! Those visual effects are good, but they don’t add up productivity. Grouping appications is a good move, but the big icons scattering all over the screen makes me feel bad. Searching applications? That works on the basis that your application shows up in the groups. In a word, they are not helping at all. My observation is that few of my friend (low level) developers will use either Unity or Gnome 3.

Well, some other suggestions include switching to Arch or Gentoo. But I’m not very into those two distros. My principle is “buzheteng”. I would rather focus on my job. I’m really tired of writing configurations line by line with my bare hands. I need a out-of-the-box distro.

How about switching to other desktop environment? KDE? No, I had very bad experience long time ago which effectively shadows me nowadays. LXDE and XFCE? They are just too light-weighted, I need full featured desktop.

Linux desktop is evolving, that’s good. I’m just too out-dated to catch up with its pace. I can not appreciate the new changes due to my out-dated tastes. I’m considering buying a Macbook now, seriously.

UPDATED:
To my surprise, KDE works much better than Gnome 3 for me. The UI is smoother than I expected. But (well, there is always a “but”) the concept of “activity” is driving me mad (What? I need to switch “desktop icons” activity to view my icons? Then switch back to “desktop” activity to see my applications?). Grouping applications is one thing, grouping activities is another. I don’t like the idea of switching among different activities just to separate what you’re doing, I would rather use different workspaces to achieve the same goal.

Written by liuw

January 8th, 2012 at 4:29 pm

Posted in 戏言

Tagged with , , ,

给Linux kernel写patch有多难?

with one comment

Good question!

答案是:一点也不难。随便打开一个文件,然后找出comment里面的拼写及语法错误,再然后按照使用Git发送patch提到的方法发送出去就ok了。一般都可以被ack然后进仓库的。

这是一个很严肃的事情哦,为社区做贡献。门槛也不高,值得一试。:-)

当然,前提是要会用Git以及有一本好词典,呵呵。

Written by liuw

December 8th, 2011 at 6:39 pm

Posted in 戏言

Tagged with , , ,

带颜色的less

without comments

习惯在一些有很多输出的命令后面用管道输出到less来分页,但是分页之后就没有颜色了。

要想带上颜色,还得程序们互相配合。例如

$ ls --color=always | less -R

ls命令如果检测到输出不是一个支持颜色terminal,就不会输出颜色的转义序列;less如果不带-R,就不会解析颜色。

Written by liuw

April 1st, 2011 at 10:07 am

Posted in UNIX-like

Tagged with , , ,

PHP这货不稳定,得整整

without comments

昨天把blog迁移到VPS上来,今天nginx就不停地502 gateway error,难不成是我害了大家?

现在的PHP是用spawn-fcgi启动的php5-cgi,死的时候完全没有任何的log,这个是没办法查出来的了。

网上搜了一下,大家的结论是PHP这货不够稳定,可能服务这么多个request之后就会死掉。所以有一个workaround就是设置PHP_FCGI_MAX_REQUESTS这个环境变量,让它在一定的request之后重启。

现在已经改好了,得观察一段时间。

这blog再不写就要发霉了,写一篇凑数吧。

Written by liuw

February 24th, 2011 at 4:22 pm

Posted in UNIX-like

Tagged with , , ,

流量控制的一个小问题记录

without comments

洗澡时突然回想起自强邮件列表上一个学弟提到的问题,初步问题是如何让不同的程序走不同的网络(Web浏览器和BT),深层次的问题是如何让不同的协议走不同的网络。

我初步提出的解决办法有两个:一是设置本地代理;二是使用iptables的l7-filter。

代理的实现原理是让代理选择出口,这样只要为两个程序开两个本地代理即可。这解决的是“初步问题”。

用l7-filter是为了解决“深层次问题”。我个人没有使用过l7-filter,我的想法是,只要能把流量标记出来,那么就可以处理。然后学弟说他了解到l7-filter主要是用来做流量控制的,没有这个功能。当时也有其他事情,没有多想。

现在回想起来,做还是可以做的,虽然我没有自己做实验,但是我已经想像到整个流程是怎么样的了。也怪我原来说得不够清楚,只提到了l7-filter。其实l7-filter只是完成标记流量的功能,真正的流量整形,还是得靠tc。

好吧,那么现在我们可以把深层次的要求看作一个设置QoS的问题,那么问题就很好办了。

流程有两步:1. iptables及l7-filter为流量设置标记(–set-mark);2. tc设置QoS参数,把不允许被mark数据流流出的接口对应数据流的速率设置为0(这话挺拗口的)。

具体我就不做了。找点参考文档放下面吧。

  • http://blog.edseek.com/~jasonb/articles/traffic_shaping/scenarios.html,这里面有用tc设置速率的例子。
  • http://lartc.org/,Linux高级路由及流量控制。

Written by liuw

January 30th, 2011 at 12:12 am

Linux内核中的per_cpu变量实现

without comments

在init/main.c里面有一个setup_per_cpu_areas,会在start_kernel中调用。

这个函数的主要作用就是使用alloc_bootmem为每个CPU在内存中分配一段专属的内存,然后把使用DEFINE_PER_CPU得到的对象模板(存放在.data.percpu一节)拷贝n次(n为配置CPU的个数),再把每个CPU专属区段相对于__per_cpu_start的offset放在__per_cpu_offset数组中(该数组的下标是CPU的ID)。

每个CPU可以通过__per_cpu_start和__per_cpu_offset找到自己的专属区段。

其实挺简单的。

(完)

Written by liuw

December 27th, 2010 at 11:28 am

Posted in UNIX-like

Tagged with ,

Xen更新页表的几个入口

without comments

这屁事搞了好几天了,这里记一下。

三个入口:

  1. do_mmu_update,个是最正规的ParaVirt入口,可以更新任何一级页表。
  2. do_update_va_mapping,直接更新virtual address对应的L1页表,只能用于L1页表。
  3. writable page table,实际上这是一个Xen的特性,不是一个具体的函数,也只能用于L1页表。Xen先把L1页表unhook让guest可写,然后ptwr_emulated_update为guest模拟写操作,Xen验证写入数据的合法性后再把页表重新hook上。

这是这几天看代码的一些小总结,不能保证完全正确。以后再写代码验证。

XenoLinux内核上面的方面都有采用。比如在Dom0进程要更新页表的时候(创建也好,销毁也好),通常是用do_mmu_update,效率比较高;但是在munmap单个页面的时候,通常是使用writable page table模式。

Written by liuw

December 10th, 2010 at 4:55 pm

Posted in Tech

Tagged with , , ,

Linux内核中的通用数据结构

without comments

Linux内核中实现了一些通用的数据结构,目前我所知的有:

  1. 双向链表:include/linux/list.h
  2. 红黑树:include/linux/rbtree.h lib/rbtree.c
  3. 基数树:include/linux/radix-tree.h lib/radix-tree.c
  4. 环形链表:include/linux/circ_buf.h

Linux内核中的通用数据结构,大部分提供的是“关节”连接点(这个是我自造的词)。这样的好处是程序员还是把主要精力放在目标数据结构上,使用通用函数完成基本操作,而不是把目标数据结构嵌入到通用数据结构中。

这两天在改Xen的代码,需要树去存储和查找数据,于是把Linux里面的红黑树移植到了Xen。顺便也把相关的代码写了。内核中的数据结构为了“通用”,通常只提供最小的功能集。链表还好,因为操作比较简单,所以list.h中全部把这些功能全部都实现了。红黑树比较复杂,插入和搜索这些操作要求使用者自己实现。

(原想把Xen改的那部分放出来,但是那样不大合适。这文章一点营养都没有,不用看了。)

Author: Wei LIU
<liuw at liuw dot name>

Date: 2010-12-07 19:30:50 CST

HTML generated by org-mode 6.21b in emacs 23

Written by liuw

December 7th, 2010 at 7:33 pm

Linux内核释放页表的过程

without comments

代码版本2.6.18-xen。

Linux在进程退出的时候,会调用mmput,mmput再调用exit_mmap。

先调用unmap_vmas去回收物理页框。unmap_vmas调用unmap_page_range。

unmap_page_range使用依次释放pud,pmd和pte。

相关函数是zap_pud_range,zap_pmd_range和zap_pte_range。

在zap_pte_range中,使用vm_normal_page把page结构取回,然后使用ptep_get_and_clear_full把PTE清0。最后把page的引用计数减1。

在unmap_vmas完成之后,再调用free_pgtables。它分别free_pgd_range,free_pud_range,free_pmd_range和free_pte_range。但是free_pte_range并不实际释放物理页,物理页在前面已经释放了。

Xen在zap_pte_range里面调用xen_l1_entry_update让Xen更新实际的PTE。非XenoLinux应该是直接更新PTE。

Written by liuw

December 2nd, 2010 at 4:33 pm

Posted in UNIX-like

Tagged with , , ,

Sample Makefile for compiling LKM

without comments

obj-m := module.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

all:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Written by liuw

November 25th, 2010 at 11:21 am

Posted in UNIX-like

Tagged with , ,