To a (projective smooth) algebraic surface $S$ over an algebraically closed field and a divisor $D$ of $S$, we can associate $n= \dim |D|$ and $g$, the genus of a generic member of $|D|$. I would like to fix $g$ and vary $S,D$ so as to make $n$ as large as possible. Is $n$ unbounded and, if not, what is the optimal bound? I am mainly interested in the case of positive characteristic but an answer over the complex numbers would be welcome too.



Maximal dimension of linear system of curves of fixed genus on a surface
$n$ is unbounded, as it is shown by the following example.


EDIT: my example did not work, as pointed out by quim in the comments.
The example he suggests however works: take $S$ the blowup of $P^2$ at a point $x$ and $D$ the strict transform of a curve of degree $d$ with a singular point of multiplicity $d-1$ at $x$. The general $D$ is smooth and $|D|$ has dimension $2d$.\
Of course, a similar construction can be used to construct examples with $g>0$.


On the other hand, if the Kodaira dimension of $S$ is $\ge 0$ and $D$ is irreducible, then $n=\dim|D|$ is bounded by $g$ by the following argument. 


Up to blowing up $S$ we may assume that the general $D$ is smooth. 
Let $m>0$ be such that $mK\_S\ge 0$. If $n>0$, then $D$ is not in the fixed part of $|mK\_S|$, hence $K\_SD\ge 0$. Hence by the adjunction formula $D|\_D$ is a divisor of $D$ of degree $\le 2g-2$ and therefore it satisfies $2\dim|D|\_D|\le \deg D$ (this is Clifford's theorem if $D$ is special and it is trivially true otherwise).  

So we have $\dim |D|\le \dim|D|\_D|+1\le D^2/2+1\le (D^2+K\_SD)/2+1=g$.


I, hence $K\_S|\_D$ is effective and $D|\_D$ is special. Then Clifford's theorem and the adjunction formula give $2(n-1)\le D^2\le D^2+K\_SD=2g-2$.


