Tuesday, September 22, 2020

Fix Linux kernel booting error ( invalid magic number)

 This morning, I compiled Linux kernel and copied the kernel to /boot/vmlinz, then reboot. But I got the following error:

error: invalid magic number.
error: you need to lead the kernel first

What could go wrong? I searched online and find this article https://bbs.archlinux.org/viewtopic.php?id=178314.
It is very helpful. I run the cmd : file /boot/vmlinz and noticed that it does recognize it as a kernel.
Then I checked file size and realized that I copied the wrong file. I copied the big vmlinx instead of arch/x86/boot/bzImage file.

Then I copied the correct file and I can boot to my new kernel again. :)

Btw, I manually copied the kernel file because it is much faster.  I just need to run "make bzImage" and then copy the new kernel. Save me lots of time for compiling and building. 

Friday, September 2, 2016

READ_ONCE, memory model. atomic and volitie

atomic implementation
http://lxr.free-electrons.com/source/include/asm-generic/atomic.h#L140

http://stackoverflow.com/questions/34988277/write-once-in-linux-kernel-lists

https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4444.html

http://lwn.net/Articles/508991/

https://www.kernel.org/doc/Documentation/memory-barriers.txt

Friday, April 29, 2016

lock free programming

http://preshing.com/20120612/an-introduction-to-lock-free-programming/


Thursday, January 7, 2016

Stop using unicode double quote in Google doc


Google doc has an option to automatically convert neutral double quote (") to unicode left double quote and right double quote. This is nice when typing some article. But it becomes annoying when typing some code ( and you want to just copy that code to a python script later).

To disable that, go to tools->preferences-> use smart qutoes, and just uncheck that box.


Thursday, July 30, 2015

13. Breadth-First Search (BFS) (notes)


Youtube link: https://www.youtube.com/watch?v=s-CYnVz-uh4

Notes:

1. in BFS, need to check if a node is already seen before or not.
2. BFS can create shortest path (by using parent arrays)

Saturday, July 11, 2015

Leacture 4: heaps and heap sort


https://www.youtube.com/watch?v=B7hVxCmfPtM

Notes: any array can be views as a heap. Meaning image it as a balanced binary tree. With left(i)=2i, right(i)=2i+1, parent(i)=i/2 etc.

max heap means the heap also has a "max" property. Root is bigger than its children.

ma_heapify(A, i), bottom up, recursive. All the leap nodes trivially satisfy the requirement.

Sunday, July 5, 2015

Linux start-up process


http://www.cromwell-intl.com/unix/linux-boot.html
http://luv.asn.au/overheads/linux-startup.html
http://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html
http://www.comptechdoc.org/os/linux/startupman/linux_surcsysinit.html

Notifier chain update: API changes


http://lwn.net/Articles/171560/

9. Table Doubling, Karp-Rabin


https://www.youtube.com/watch?v=BRO7mVIFt08

Lecture Notes: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/MIT6_006F11_lec09.pdf


1. in hashing, suppose n is the number of keys and m is the number of slots in the hash table. We want m to similar size to n. But n may grow or shrink, so we need to grow and shrink table to get better performance (and rehash). When grow, double the size. When shrink, wait until n is m/4 and then decrease m by half.

Amortized cost, like paying rent $1500/month = $50/day

2. Karp-Rabin algorithm: rolling hash. Lots of common bits between two hash. Easy to append one bit and remove the first bit.

Saturday, July 4, 2015

String Matching with Finite Automata


https://www.youtube.com/watch?v=M_XpGQyyqIQ

Notes:

1. Finite automata is a state machine. It has start and end state(s). A three letter pattern has four states (s0 to s3). Matched one more letter means state changes. If not match, it will go back to one of the appropriate state. ( Instead, in naive matching, if one letter does not match, it will go back to s0).

2. Finite automata is used to parse in compiler and implement regular expression.

3. State transition table. ( column is alphabet, row is states).

4. Matching time is O(N), preprocessing time depends on implementation.

Knuth-Morris-Pratt algorithm for String Matching


https://www.youtube.com/watch?v=kBW6oPaVjq0

Need a prefix table.

The preprocessing is very similar to string matching.
One is to match pattern to itself. The other is to match pattern to text.
Time complexity: O(m) + O(n)  ( O(m) for preprocessing and O(n) for matching).

Scalability 101 and dropbox


Scalability from Harvard :

https://www.youtube.com/watch?v=-W9F__D3oY4

Notes:
1. scalability 101.
2. issues when having multiple servers, share data, etc.


Scale dropbox:

https://www.youtube.com/watch?v=PE4gwstWhmc

Notes:
1. heavy write V.S heavy read
2. no need to internet scale at beginning.