Virtual Memory: Address Translation

  • Virtual address bits are decided by ISA (Instruction Set Architecture), and P address bits are based on RAM available. In the cases considered here, there is 32-bit ISA and 256MB RAM.
  • Page offsets depend upon frame/page size. Here each page has a size of 4KB.

Untitled

  • This is how an address in RAM is translated.

Untitled

  • When T. address (Page) is on Disk.
  • In this case, CPU generates an exception: Page Fault
  • Hardware gives control to OS’s Page Fault Exception handler.
  • OS decides which page to move out from RAM to replace with this recently accessed one.
  • If the page is dirty, it has to be written on the disk too.[ The bit indicates that its associated block of memory has been modified and has not yet been saved to storage. ], then update page table. Now OS jumps to the same instruction what caused fault.
  • Page Faults are very expensive.

Untitled

How Virtual Memory Works?

  • Each programs has its on virtual address space and Map(Translator). Map maps to the physical address either in RAM or Disk.
  • When address is mapped in Disk, it is first loaded to RAM, also mapping table is updated and then data is loaded.
  • This Map is called Page Table and the entry in it is called Page Table Entry.
  • WHY WE CALL IT PAGE?
    • Well, if, for each virtual address an entry is used, the size of Page Table alone would be large. Also, note that for each program we have a Page Table.
    • So, each entry instead of handling each V. address, handles chunk of V. addresses(range) and maps that to chunk of P. addresses(range).
    • The point above resolves the problem of large memory usage.
    • We typically have 4kB of pages(1024 words).
    • Bigger the page size, moving from the disk would take more time. Lesser the page size, more memory is needed to store page table.
  • A V. address is divided in V. Page number and Page offset. V. Page number is mapped to P. page address and page offset just concatenates with it.Screenshot from 2016-06-22 22-13-50

Introduction: Virtual Memory

WHY VIRTUAL MEMORY?

  • Not enough RAM-> CRASH
    • MIPS provides 32 bit address space(4GB memory), suppose we have only 1GB RAM. How to access address out of 1GB range?
  • Secure address space-> CORRUPT
    • Two programs can write on same address
  • Holes in the address space-> OUT OF SPACE
    • Say there are 3 programs like-> p1 needs 1GB, p2 needs 2GB and p3 need 1GB. In out 4GB address space p1 and p2 fit in, respectively. Say p1 is terminated. We have 2 address spaces of 1GB above and below of p2.
      Although we have enough space but we cannot allocate it to p3 because of Memory Fragmentation.

HOW IT SOLVES?

  • By mapping the virtual memory space given to the program to actual memory space.
  • In this, way all the programs have different VS.

WHAT IS VIRTUAL MEMORY?

  • It is an indirection from virtual address spaces generated by program to some address from where the required data can be accessed.

AGAIN, HOW IT SOLVES OUT 3 PROBLEMS?

  • Not enough RAM-> CRASH
    • Map has the mapping to disk also, whenever some address that is accessed that’s not in RAM, Map goes to the Disk, takes that data and pages out some other data to Disk to put this new, recently accessed data into RAM.
      Along with this, Map updates it self for the address whose data has been paged out.
  • Holes in the address space-> OUT OF SPACE
    • Considering the same situation as above, both p2 and p3(as well p1) would have their Maps, now p3’s address space can be mapped to 2 chunks of 1GB.
  • Secure address space-> CORRUPT
    • If 2 programs are accessing same address to write, Map of each can prevent them to write on same address.
    • Two prevent complete isolation though, programs can have same mappings.

 

DbMS: SQL Keys

  • Super Key
  • Candidate Key
  • Primary Key
  • Natural Key/Business Key/Domain Key
  • Surrogate Key
  • Unique Key
  • Foreign Key
  • Secondary Key
  • Simple Key

Super Key: Super key is the set of attributes in a table that can identify a row uniquely.

Candidate Key: Candidate key is minimal super key. If any of the attribute, in case of two or more attributes, is removed from the candidate key then uniqueness breaks. N0 candidate key can be NULL. A table can have a multiple candidate keys.

Primary Key: It is one of the candidate keys. Primary key cannot be NULL.

Natural Key:  Natural key is a key composed of columns that actually have a logical relationship to other columns within a table. For example, in case of database of a society, Name, Address is a natural key.

Surrogate Key: Surrogate means substitute, in case natural key is not a good choice, surrogate key is used. Usually column(s) are added for uniqueness of a tuple. For example an ID is provided to every row and this ID is used as primary key. Opposite to natural key, surrogate key does not have logical relationship to other values in a tuple.

Unique Key: (Confused) It is a candidate key. Used to prevent duplicate values in a column. It can be NULL. Multiple unique keys can exist. Unique values can be deleted.

Foreign Key: In the context of relational databases, a foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table.In simpler words, the foreign key is defined in a second table, but it refers to the primary key in the first table. Foreign key enforces referential integrity:

  • Update to a table having a foreign can happen if the corresponding key exist in the other table.
  • Cascade Delete
  • Cascade Update

Secondary Key: Candidate key(s), not selected as primary key is/are secondary key.

Simple Key: Candidate key with a single attribute is a simple key.

DbMS: Joins

Joins are used to merge data based on predicate logic, of two tables that results in a temporary table;

Types:

  1. Outer Joins
    1. Left Outer Join
    2. Right Outer Join
    3. Full Outer Join
  2. Inner Join

Consider tables for examples:

Employee Location
EmpID EmpName
13 Jason
8 Alex
3 Ram
17 Babu
25 Johnson
EmpID EmpLoc
13 San Jose
8 Los Angeles
3 Pune, India
17 Chennai, India
39 Bangalore, India

Outer Join: Iterates over the all rows of both or one of the tables.

In left outer join, according to the query, it iterates over the key of left table provided in SQL query and matches the same in the right one. Tables will result in:

SQL:
select * from employee left outer join location on employee.empID = location.empID; OR
select * from employee left join location on employee.empID = location.empID;

Employee.EmpID Employee.EmpName Location.EmpID Location.EmpLoc
13 Jason 13 San Jose
8 Alex 8 Los Angeles
3 Ram 3 Pune, India
17 Babu 17 Chennai, India
25 Johnson NULL NULL

In right outer join, same happens for the right table:

SQL:
select * from employee right outer join location on employee.empID = location.empID; OR
select * from employee right join location on employee.empID = location.empID;

Employee.EmpID Employee.EmpName Location.EmpID Location.EmpLoc
13 Jason 13 San Jose
8 Alex 8 Los Angeles
3 Ram 3 Pune, India
17 Babu 17 Chennai, India
NULL NULL 39 Bangalore, India

Inner Join: Here if match happens only then join happens.

SQL:
select * from employee inner join location on employee.empID = location.empID; OR
select * from employee, location where employee.empID = location.empID;

Employee.EmpID Employee.EmpName Location.EmpID Location.EmpLoc
13 Jason 13 San Jose
8 Alex 8 Los Angeles
3 Ram 3 Pune, India
17 Babu 17 Chennai, India

 

Souirce: http://www.programmerinterview.com

Gulp

  • Task manager for web project.
  • npm install -g gulp or npm install gulp –save-dev [for devDependencies, gulp is not needed for deployment]
  • Make gulpfile.js run gulp style, gives warning according to the code.
  • To inject js and css automatically:
    • npm install wiredep –save-dev #for bower dependencies
    • npm install gulp-inject –save-dev #for our dependencies
    • Code in gulpFile.js for injecting file.
    • in HTML files put
      <!– bower: js–>
      <!– endbower –>
    • for inject put
      <!– inject: js–>
      <!– endinject –>
    • run gulp inject and HTML files would have all js files required.
    • [See memo for css/less problem in bootstrap/gulp]

//These tools are used in gulpFile.js

JS Hint:

  • For coding standards => .jshintrc
  • Configurable and open source

JSCS:

  • For coding style => .jscsrc
  • Configurable and open source

ExpressJs

use express.static to serve a folder, nodejs will check in this folder to render
    app.use(express.static(“<folderPath>”))

  • app.get(“/text”, function(request, response){..});
  • app.post(“/text”, function(request, response){…});
  • var router = require(“express”).Router();
    router.route(“/”)
    .get(function(req, res){…});
    app.use(“/text”,
    router);
    /text/ app will use router, for /text/text2/, router.route(“/text2”, …) can be used.
  • app.get(“/:id”)

Bower

  • A front-end package management tool.
  • Flat package hierarchy.
  • bower.json
  • npm install bower -g
  • bower init
  • bower install <packageName> –save
  • Make .bowerrc file, add “directory”: “<fullPathoftheFolder>”; bower install…