  For graphs $F$ and $H$, let $f_{F,H}(n)$ be the minimum possible size of a
maximum $F$-free induced subgraph in an $n$-vertex $H$-free graph. This notion
generalizes the Ramsey function and the Erd\H{o}s--Rogers function.
Establishing a container lemma for the $F$-free subgraphs, we give a general
upper bound on $f_{F,H}(n)$, assuming the existence of certain locally dense
$H$-free graphs. In particular, we prove that for every graph $F$ with
$\mathrm{ex}(m,F) = O(m^{1+\alpha})$, where $\alpha \in [0,1/2)$, we have
  \[
  f_{F, K_3}(n) = O\left(n^{\frac{1}{2-\alpha}}\left(\log n\right)^{\frac{3}{2-
  \alpha}}\right)
  \quad
  \textrm{and}
  \quad
  f_{F, K_4}(n) = O\left(n^{\frac{1}{3-2\alpha}}\left(\log
n\right)^{\frac{6}{3-2\alpha}}\right).
  \] For the cases where $F$ is a complete multipartite graph, letting $s =
\sum_{i=1}^r s_i$, we prove that
  \[
  f_{K_{s_1,\ldots,s_r}, K_{r+2}}(n) = O \left( n^{\frac{2s -3}{4s -5}} (\log
n)^{3} \right).
  \]
  We also make an observation which improves the bounds of
$\mathrm{ex}(G(n,p),C_4)$ by a polylogarithmic factor.
