Return page_count(page) - !!page_has_private(page) == 2 discussion 

(15:34:44) vincentinsz: 287 static inline int is_page_cache_freeable(struct page *page)
288 {
289 return page_count(page) - !!page_has_private(page) == 2;
290 }

(15:35:21) vincentinsz: this function eventually returns 0 or 1, right?
(15:36:35) qunying: not understand it fully, looks strange to me
(15:38:20) qunying: as !!page_has_private(page) should return 0 or 1, and !!page_has_private(page) == 2 should always fail, then that is the result of page_count(page)
(15:40:02) vincentinsz: I thought it is like return 3 - 1 == 2? 1 : 0 ?
(15:40:45) qunying: ah right, forgot the '-'
(15:41:11) qunying: it is always return 0 or 1
(15:42:52) vincentinsz: not sure why number 2 is special in this case ==2
(15:43:13) vincentinsz: why not == 1, or == 3 ?
(15:44:00) qunying: that is beyond my understanding, you make dig into how page_count is working
(15:53:00) vincentinsz: what the !! is for, like !!func(a), always get the oposite of function retuning value?
(15:53:47) qunying: not, it normalize the return code to 0 or 1
(15:54:02) qunying: some func(a0 may return > 1 or < 0 values
(15:54:53) vincentinsz: > 1 to make it 1, < 0 to make it 0, right
(15:55:34) qunying: no. < 0 make it to 1 also
(15:55:52) qunying: in C, any none 0 value is true
(15:56:37) vincentinsz: oh, forgot that part, so < or > 1 to make it 1, 0 to make it 0
(15:57:25) qunying: ya
(15:57:35) vincentinsz: f**k :-) so < or > 0 to make it 1
(16:58:12) qunying logged out.


---


(09:31:33) vincentinsz: Hi, still to the strange !!((page)->flags & ((1 << PG_private) | (1 << PG_private_2))) statement
(09:34:25) vincentinsz: (page)->flags & ((1 << PG_private) | (1 << PG_private_2)) is to mask (page)->flags to something like 00010000, assuming the 1 bit value represents the PG_private, am I right?
(09:34:46) qunying: yes
(09:35:33) vincentinsz: then !!(0000100000) make it to vaule 1, right?
(09:35:59) qunying: yes
(09:38:03) vincentinsz: someone else had this explaintion: http://zh-kernel.org/pipermail/linux-ke ... 11228.html
(09:38:32) vincentinsz: is that the same thing as you said?
(09:39:27) qunying: ya
(09:40:13) vincentinsz: is that to say that !! will always get 1?
(09:40:36) qunying: no, it says none 0 value to 1
(09:40:49) qunying: 0 will always get 0
(09:51:05) vincentinsz: ok. Oh and the page_count(page) - !!((page)->flags & ((1 << PG_private) | (1 << PG_private_2))) == 2 meaning that if (page)->flag PG_private is set, then there should be another two bit set to 1 in (page)->flags so that this page can be freeable
(09:51:53) qunying: i see
(09:53:06) vincentinsz: the other two bit could mean a page is in user mapped address space and LRU (Least recently used) list which are most likely for page reclaim candidate

(10:03:46) vincentinsz: There are many details, I could be wrong :-), the devil is the detail
(10:04:19) qunying: ^_6
(10:48:29) vincentinsz: ok, more, page_count(page) count the reference count of page, if page flag PG_private bit flag is set, the page is pagecache page backed by inode or swap , so the pagecache itself would have 1 reference to the page, that is at least 2 ref count. Then the page has to be referenced in LRU list so it can be freed, that is 3.
(10:51:11) qunying: hmm, that is why it minors the 1 reference from private bit reference
(10:51:16) qunying: minus


[ add comment ] permalink ( 3 / 31 )
kernel virtual address to size caculation chat log 

I had an interesting chat with my friend qunying about how to caculate the hex presentation of address to a size:

(14:29:56) vincentinsz: on x86 32bit the kernel image located at physical address 1MiB, which translate to 0x00100000, but how 0x00100000 equals 1M, how to caculate it?
(14:32:00) qunying: 1024*1024 = 0x100000
(14:32:11) qunying: that is 1MiB
(14:33:56) vincentinsz: is there easy way to see 0x100000 as 1024 * 1024?
(14:34:18) qunying: just count the zeros
(14:34:36) qunying: one 0 in hex is 2^^2
(14:34:49) qunying: there is 5 zero, that is 2^^10
(14:35:00) qunying: that is 1M
(14:35:54) qunying: one 0 is 2^^4
(14:35:58) qunying: not 2,
(14:36:09) qunying: 5 zero is 2^^20
(14:37:59) vincentinsz: how do you get one 0 is 2^^4?
(14:38:27) qunying: for one number in hex represents 4 bits in binary
(14:38:55) qunying: 0x10 = 2^4, 0x100 = 2^8, etc
(14:40:01) vincentinsz: 0x10 = 1000 0000
(14:40:13) qunying: ya
(14:40:23) qunying: no
(14:40:29) qunying: 001 000
(14:40:34) qunying: 0001 0000
(14:40:47) vincentinsz: i see
(14:42:20) vincentinsz: what about some other hex address like 0xC0000000 which is about 3G, How to caculate
(14:45:10) vincentinsz: so there is 7 0s which is 2^^28?
(14:45:24) qunying: ya
(14:45:35) qunying: C is 1100
(14:46:00) qunying: so times 2^12
(14:46:35) vincentinsz: ah, so 2^^30 * 3?
(14:48:33) qunying: ya


---

[ add comment ] permalink ( 2.9 / 29 )
Learning Linux Kernel series 1 - Buffer Head 

First I read:

A nasty file corruption bug - fixed
http://lwn.net/Articles/215868/

The header for buffer head is include/linux/buffer_head.h


defines maxmum disk sectores/blocks as 8 per page, PAGE_CACHE_SIZE normally is the same size of PAGE_SIZE as 4k

#define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512)

The function definition for buffer head is fs/buffer.c
[ add comment ] permalink ( 3 / 25 )
Asterisk app_mp3 patch to play m3u playlist file 

Asterisk app_mp3.c could only play one local single mp3 file, I patched it to play m3u playlist file randomly.

http://bl0g.blogdns.com/asterisk/app_mp3.patch
[ add comment ] permalink ( 3 / 30 )
Linux file system ext4 debate 

[ add comment ] permalink ( 2.9 / 31 )

Next