Friday, February 21, 2020

Cosmology for Dummies in Animated Videos

Some interesting tidbits that I learned from my recent readings/learning in cosmology

  1. Basics of 4D Spacetime in an animation
  2. How fast are you moving?
  3. How big is the universe?
  4. Why is our visible universe 14B light-years wide while the universe started about 14M light years back?
  5. Can you travel faster than speed of light?
  6. Sunlight hitting the earth is very old - approx 170,000 years old!
  7. How many universes are there? - 0 to infinity predicted by String theory.
  8. How will the universe end? - thanks to dark energy
Basics of 4D Spacetime in an animation
1. Understanding 4d space time and the world line https://www.youtube.com/watch?v=ScdLqAA_64E
2. Lorentz transformation https://www.youtube.com/watch?v=aeCsS6PjhK8
3. Gravity and space time - how does it bend?  https://www.youtube.com/watch?v=NAXHHBUY9_E

Sunday, January 5, 2020

Linux: Why is the buddy system needed? - To prevent fragmentation

The buddy system is a mechanism for page management in Linux. It is needed to make sure that the free memory does not get fragmented and unusable. For an overview of the buddy system including a simple example of how it works, see this page [2]. From the same page, "In comparison to other simpler techniques such as dynamic allocation, the buddy memory system has little external fragmentation, and allows for compaction of memory with little overhead. The buddy method of freeing memory is fast, with the maximal number of compactions required equal to log2(highest order). Typically the buddy memory allocation system is implemented with the use of a binary tree to represent used or unused split memory blocks. The "buddy" of each block can be found with an exclusive OR of the block's address and the block's size."

An alternative to the buddy system would be to use the memory management unit (MMU) support to rewire or re-arrange blobs of free pages together to construct larger contiguous pages. However, this will not work for DMA systems which bypass the MMU. Also, modifying the virtual address on a continual basis would make the paging process slow.

Debugging on the buddy system can be done by printing the current stats. This is supported under the /proc/buddyinfo file. As described in the guide from centos.org, fragmentation issues can be debugged. A sample output from the same site is as shown below:
cat /proc/buddyinfo

Different ways to print Linux kernel symbols instead of addresses

Cheatsheet:

%pF versatile_init+0x0/0x110
%pf versatile_init
%pS versatile_init+0x0/0x110
%pSR versatile_init+0x9/0x110
(with __builtin_extract_return_addr() translation)
%ps versatile_init
%pB prev_fn_of_versatile_init+0x88/0x88

Saturday, January 4, 2020

Interesting Math Tutorials - Refreshers

Map of Mathematics

Monday, October 28, 2019

How to use IS_ERR and PTR_ERR? What do they mean?

From the kernel definition there are three macros:
  1. IS_ERR - used to check, Returns non-0 value if the ptr is an error. Otherwise 0 if it’s not an error.
  2. PTR_ERR - used to print. Current value of the pointer.
  3. IS_ERR_VALUE - is explained a little bit more detail here1.
I find this the most useful for kernel space programming. Used as follows- if ptr is the pointer you want to check then use it as follows:
if (IS_ERR(ptr))
     printk("Error here: %ld", PTR_ERR(ptr));