Q:

How to draw resource allocation graph in the picture?

I have found some similar solutions by tikz. Here is the link.
https://github.com/MartinThoma/LaTeX-examples/blob/master/tikz/resource-allocation-graph/resource-allocation-graph.tex
https://github.com/MartinThoma/LaTeX-examples/tree/master/tikz/resource-allocation-graph
But the graph in the book which has some variations.
It have some dots in the rectangles and some lines are from the dots not from rectangles.
So if there is some solution based on that one to meet the requirements, it is nice. Thanks.

A:

Not sure if I'm really answering your question, but here you go. The shading on the circles isn't quite right, but I think the rest is pretty close.

Code:
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{xcolor}

\definecolor{sqBlue}{RGB}{218,234,233}
\definecolor{ballBlue}{RGB}{40,156,156}

\begin{document}
\begin{tikzpicture}[x=0.6in,y=0.6in]

%% Draw the rectangles
\draw[fill = sqBlue] (-0.5,0) rectangle (0.5,1);
\node at (0,0.75) {Ra};
\draw[fill = sqBlue] (-0.5,-3.5) rectangle (0.5,-2.5);
\node at (0,-3.25) {Rb};

%% Draw the big circles
\fill[ball color = ballBlue] (1.6875,-1.25) circle[radius=0.5] node {P2};
\fill[ball color = ballBlue] (-1.6875,-1.25) circle[radius=0.5] node {P1};

%% Draw the small dots
\coordinate (a) at (-0.344,0.19);
\coordinate (b) at (-0.0625,0.19);
\coordinate (c) at (0.25,0.19);
\coordinate (d) at (-0.0625,-2.69);
\coordinate (e) at (0.22,-2.69);

\draw[fill = black] (a) circle[radius=0.075];
\draw[fill = black] (b) circle[radius=0.075];
\draw[fill = black] (c) circle[radius=0.075];
\draw[fill = black] (d) circle[radius=0.075];
\draw[fill = black] (e) circle[radius=0.075];

%% Draw the arrows
\draw[-latex', very thick] (b) to node[sloped, above, inner sep = 2pt] {\footnotesize\hspace{1em}Held by} (1.37,-0.88);
\draw[latex'-, very thick] (0.375,-2.5) to node[sloped, above, inner sep = 2pt] {\footnotesize Requests} (1.37,-1.63);
\draw[-latex', very thick] (d) to node[sloped, above, inner sep = 2pt] {\footnotesize Held by} (-1.37,-1.63);
\draw[-latex', very thick] (-1.37,-0.88) to node[sloped, above, inner sep = 2pt] {\footnotesize\hspace{-2em}Requests} (-0.19,0);

\end{tikzpicture}
\end{document}

