9. (16 points) Let the range of the function $f(x)$ be $[1,2]$, and let $g(x)=f(x)+\frac{a}{f(x)}$. Find the minimum value of $p(a)=\max g(x)-\min g(x)$.
9. Let $q(t)=t+\frac{a}{t}(t>0)$. Then $q^{\prime}(t)=1-\frac{a}{t^{2}}$.

When $a<0$, $q^{\prime}(t)>0$, thus, $q(t)$ is increasing on $(0,+\infty)$.
When $a \geqslant 0$, let $1-\frac{a}{t^{2}}>0$, we get $t>\sqrt{a}$.
Thus, $q(t)$ is decreasing on $(0, \sqrt{a}]$ and increasing on $[\sqrt{a},+\infty)$.
Let $t=f(x)$. Then
$$
g(x)=f(x)+\frac{a}{f(x)}=t+\frac{a}{t}=q(t)(t \in[1,2]) \text {. }
$$

When $a<0$.
Thus, $v(a)$ is increasing on $[2,4]$.
It follows that, $p(a)$ is decreasing on $[-\infty, 2]$ and increasing on $[2,+\infty]$.
Hence, the minimum value of $p(a)$ is $p(2)=3-2 \sqrt{2}$.