Archive for January, 2016

kernel: mm: debug_pagealloc

January 25, 2016

This post discusses how to enable debug_pagealloc, and how it detects single bit error and memory corruption.

reference code base
linux 4.3

how to enable debug_pagealloc

  • If CONFIG_DEBUG_PAGEALLOC is not set, then debug_pagealloc is always enabled.
  • If CONFIG_DEBUG_PAGEALLOC is set, then debug_pagealloc is disabled by default. Add debug_pagealloc=on in kernel command line could enable this feature. android: add arguments in kernel command line shows how to add arguments into kernel command line.
853         debug_pagealloc=
854                         [KNL] When CONFIG_DEBUG_PAGEALLOC is set, this
855                         parameter enables the feature at boot time. In
856                         default, it is disabled. We can avoid allocating huge
857                         chunk of memory for debug pagealloc if we don't enable
858                         it at boot time and the system will work mostly same
859                         with the kernel built without CONFIG_DEBUG_PAGEALLOC.
860                         on: enable the feature

allocate/free pages and debug_pagealloc
Allocating pages will poison pages with 0xaa, and freeing pages will unpoison pages. While unpoisoning pages, it will check if each byte of poisoned pages are 0xaa. If only one bit is incorrect, then kernel log will show “pagealloc: single bit error”. If more than one bit is incorrect, then kernel log will show “pagealloc: memory corruption”.

__alloc_pages_nodemask()
-> get_page_from_freelist()
   -> prep_new_page()
      -> kernel_map_pages()
         -> __kernel_map_pages()
For order 0 pages
__free_pages()
-> free_hot_cold_page()
   -> free_pages_prepare()

For high order pages
__free_pages()
-> __free_pages_ok()
   -> free_pages_prepare()
128 void __kernel_map_pages(struct page *page, int numpages, int enable)
129 {
130         if (!page_poisoning_enabled)
131                 return;
132 
133         if (enable)
134                 unpoison_pages(page, numpages);
135         else
136                 poison_pages(page, numpages);
137 }
138 
 32 /********** mm/debug-pagealloc.c **********/
 33 #define PAGE_POISON 0xaa

conclusion
To enable debug_pagealloc, it needs to compile kernel with CONFIG_DEBUG_PAGEALLOC=y and add debug_pagealloc=on in kernel command line. This feature poisons pages while pages are allocated and unpoison pages while pages are freed. While unpoisoning pages, if pages’ content are incorrect, then kernel log will show “pagealloc: single bit error” or “pagealloc: memory corruption”.

book review: from zero to one

January 4, 2016

This post discusses from zero to one

author
Peter Thiel

what i got and thought
The value of a successful company is from zero to one rather from one to n. From one to n is achieved by copied others which creates values in short time but will be doomed in the future. From zero to one is achieved by creating unique and irreplaceable values and could be the corner stone of your company.

The next Michael Jordan will play basketball; otherwise, he couldn’t have the opportunities to be the next Michael Jordan. However, the next Bill Gates couldn’t try creating new operating system; otherwise, he will not have a breakthrough from zero to one and will not be successful. The next Larry Page couldn’t try developing new search engine; otherwise, he will not have a singularity from zero to one and will fail. The next Steve Jobs couldn’t sell iPhone; otherwise, he will not change the behaviours of customers from zero to one and will not be a legend.

Sometimes, we need to do something which was failing in the past, because the root cause of these failures was just not done at right time. Even for many, these failure stories proved these ideas were wrong, but these ideas may be perfect now. Keep in mind that future is the time what is excluded from the past in the time space.

As an employee, we are supposed to choose a company which has monopoly in the market rather than suffers from peer competitions. A company has no monopoly advantages needs to cost down their products and is destined to give less and less to their employees.


%d bloggers like this: