Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, May 2, 2015

Process Address Space (Linux)

Process Address Space

  • Linux (and all modern OSs) virtualizes physical memory.
  • i.e. processes do not directly address physical memory.
  • Each process gets a unique virtual address space.
  • This address space is linear; addresses start at zero, and increments continously upto the max of 32-bit/64-bit integer value.
  • A part of this address space (~1GB) is reserved for the kernel. 

Memory Pages

  • The virtual address space is broken into memory pages.
  • A memory page is 4KB for 32-bit OSs and 8KB for 64-bit OSs.
  • A page is the smallest unit that the MMU (Memory Management Unit) can manage.
  • A page can be either valid or invalid.
  • A valid page is memory that has been allocated for the process; this page could be in physical memory or on disk (swap partition).
  • An invalid page is memory that has not been allocated (or freed).
  • Accessing an invalid page causes a segmentation fault.
  • Different virtual memory pages of different processes, could map to the same physical page; eg: standard C lib will have only one copy in physical memory, but will be mapped by different virtual memory pages of multiple processes.

Paging

  • A valid page, which has been swapped to disk, cannot be directly accessed; it needs to be brought to physical memory first; 
  • This task is handled automatically by the OS, and is not visible to the process. 
  • When a process tries to access a valid page which is on disk, MMU generates a page fault, which is captured by the OS kernel; kernel then page-in that page from disk to RAM, transparently.
  • When page-in is required, some existing pages (least used) might be paged-out, to make room for the new pages.

Memory Regions

  • Virtual memory pages of a process are grouped into several blocks called memory regions (or memory areas).
  • Text segment: contains the process's read only data -- program code, string literals, cont vars etc.
  • Stack: contains the process's execution stack -- local vars etc.
    • stack dynamically grows/shrinks as the stack depth increases/decreases.
    • multi-threaded processes contains one stack per thread.
  • Heap (data segment): contains the process's dynamically allocated memory.

References:

Sunday, July 6, 2008

getting ADSL USB modem working on Ubuntu Linux

Here are the steps I took to get my ADSL USB modem to work on Ubuntu.

Details:
Country = Sri Lanka (ISP = SLT; uses PPPoE)
Modem = Aztech ADSL USB Modem (DSL206U) (chipset = ADI Eagle II)
OS = Ubuntu Linux 8.04 (Hardy)

Steps:
* first have a terminal open and tail the syslog. (to see whats going on)
$ tail -f /var/log/syslog

* using synaptic package manager install br2684ctl (required since my ISP uses PPPoE)
(search for br2684)

* find and download the firmware for the modem chipset (Eagle-II in my case)
--- deprecated; use the .deb below instead ---
(firmware => ueagle-data-1.1.tar.gz)
(http://eagle-usb.org/ueagle-atm/non-free/ueagle-data-1.1.tar.gz)
* install firmware:
$ tar -xvzf ueagle-data-1.1.tar.gz
$ sudo mkdir /lib/firmware/ueagle-atm
$ cd ueagle-data-1.1/
$ sudo cp -a * /lib/firmware/ueagle-atm
--- update(17-Nov-08) ---:
Now there's a .deb which can be directly installed.
http://eagle-usb.org/ueagle-atm/non-free/ueagle-data_1.1-2_all.deb

* plug-in the modem; check if the firmware loads (in the syslog tail output).

* edit the connection file:
$ sudo gedit /etc/ppp/peers/ueagle-atm
type in the following:
user "myusername"
password "mypassword"
plugin rp-pppoe.so
nas0
noipdefault
usepeerdns
defaultroute
persist
noauth

* edit chap:
$ sudo gedit /etc/ppp/chap-secrets
add this line:
myusername * mypassword *

* edit pap:
$ sudo gedit /etc/ppp/pap-secrets
add this line (same as for chap):
myusername * mypassword *

* now create dial script to dial the modem.
$ gedit dialSLT
type in the following:
#!/bin/bash
sudo modprobe ppp_generic
sudo modprobe pppoatm
sudo modprobe br2684
sudo br2684ctl -b -c 0 -a 8.35
sleep 3
sudo ifconfig nas0 192.168.0.1 netmask 255.255.255.0 up
sleep 5
sudo pon ueagle-atm

* set exec permisions for the dial script and we're done!
$ chmod u+x dialSLT

* now to dial the modem just type:
$ ./dialSLT

// -----------------------------------------
important:
* in case the connection drops, do the following before redialing:
$ sudo poff ueagle-atm
$ sudo ifconfig nas0 down
$ sudo killall br2684ctl