I am trying to bound $$f(n)=\pi\left(\frac{n}{p_{\pi(\sqrt{n})}}\right) - \pi\left(\sqrt{n}\right)$$ where $\pi(x)$ is the prime counting function and $p_{\pi(\sqrt{n})}$ is the greatest prime number less than $\sqrt{n}$.
The lower bound is $0$, and the upper bound must be really small, as this difference counts only prime numbers $p_j$ greater than $\sqrt{n}$ such that $p_{\pi(\sqrt{n})}*p_j\leq n$. Indeed, the two local maximums I have found for $n=11^2-1=120$ and $n=127^2-1=16128$ are $f(n)=3$.
I conjecture that those are indeed global maximums, based on the fact that the relative difference $\frac{\left(\sqrt{p_{\pi(\sqrt{n})+1}^2-1}\right)-p_{\pi(\sqrt{n})}}{p_{\pi(\sqrt{n})}}$ is increasingly smaller as $n$ grows, but I do not know neither if I am right nor how to prove it.
Any help/hint would be welcomed.
Thanks!
EDIT
In line with @rtybase comment, Dusart [1] proved that, for every integer $n\geq 688383$, we have that $$n\left(\log n + \log\log n - 1+\frac{\log\log n -2.1}{\log n}\right)<p_n<n\left(\log n + \log\log n - 1+\frac{\log\log n -2}{\log n}\right)$$
Other hand, Dusart [2] proved that, for every integer $x\geq 2 953 652 287$, we have that $$\frac{x}{\log x}\left(1+\frac{1}{\log x}+\frac{2}{\log^2x}\right)\le\pi(x)\le\frac{x}{\log x}\left(1+\frac{1}{\log x}+\frac{2.334}{\log^2x}\right)$$
As we already know that the lower bound of $f(n)$ is 0, we will focus only in deriving the tightest upper bound possible.
Applying Dusart's bounds for $p_n$, we get that $$f(n)<\pi\left(\frac{n}{\sqrt{n}(\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}\right) - \pi\left(\sqrt{n}\right)$$
Simplifying,
$$f(n)<\pi\left(\frac{\sqrt{n}}{\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}\right) - \pi\left(\sqrt{n}\right)$$
Applying Dusart's bounds for $\pi(n)$, we get that
$$f(n)<\frac{\frac{\sqrt{n}}{\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}}{\log \frac{\sqrt{n}}{\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}}\left(1+\frac{1}{\log \frac{\sqrt{n}}{\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}}+\frac{2.334}{\log^2\frac{\sqrt{n}}{\log \sqrt{n} + \log\log \sqrt{n} - 1+\frac{\log\log \sqrt{n} -2}{\log \sqrt{n}}}}\right)-\frac{\sqrt{n}}{\log \sqrt{n}}\left(1+\frac{1}{\log \sqrt{n}}+\frac{2}{\log^2\sqrt{n}}\right)$$
We can reexpress it as
$$f(n)<\frac{\sqrt{n} \left(\frac{\log\sqrt{n}}{(1 + \log\sqrt{n}) (-2 + \log(\sqrt{n}) + \sqrt{n} \log(\log(n)))}\right)}{\log \sqrt{n} +\log\left(\frac{\log\sqrt{n}}{(1 + \log\sqrt{n}) (-2 + \log(\sqrt{n}) + \sqrt{n} \log(\log(n)))}\right)}\left(1+\frac{1}{\log \sqrt{n} +\log\left(\frac{\log\sqrt{n}}{(1 + \log\sqrt{n}) (-2 + \log(\sqrt{n}) + \sqrt{n} \log(\log(n)))}\right)}+\frac{2.334}{\log^2\sqrt{n} +\log\left(\frac{\log\sqrt{n}}{(1 + \log\sqrt{n}) (-2 + \log(\sqrt{n}) + \sqrt{n} \log(\log(n)))}\right)}\right)-\frac{\sqrt{n}}{\log \sqrt{n}}\left(1+\frac{1}{\log \sqrt{n}}+\frac{2}{\log^2\sqrt{n}}\right)$$
Can we from this point go further to obtain that $f(n)$ is less than some constanc $C$?
[1] P. Dusart, Explicit estimates of some functions over primes, Ramanujan J. 45 (2018), no. 1, 227–251.
[2] Pierre Dusart, "Estimates of Some Functions Over Primes without R.H." (2010) https://arxiv.org/abs/1002.0442