Although the easiest method of experimenting with the oscillations of a mass on a spring is to hang the spring vertically, the simplest scenario for analysing these oscillations is to have the spring and mass resting on a frictionless horizontal surface. The weight of the spring then has no effect on the extension of the spring, which can be assumed to be uniform over its length.
Although the author's diagram Fig. 1.24 displays the spring vertically in the book, the extension is portrayed as being uniform over the length of the spring, with coils spaced at a constant distance apart, as in the horizontal case. The result which he obtains is only approximate for a vertical spring, as in his diagram; however, it is exact for a horizontal spring, which he does not appear to realise. (The exercise which he is solving does not state that the spring is suspended vertically, nor does it mention the weight of the load or spring, only their mass.)
At the end of the calculation on p 42 the author states :
The above calculation is not exact because we have assumed that the extension of an element of the spring is proportional to the distance from the fixed end and that the velocity $d\phi/dt$ is the same for all elements of the spring. In fact, different elements undergo different accelerations. The expression for the time period will hold if $m \ll M$, in which case the stretching force does not vary appreciably with distance along the spring and can be treated as roughly constant.
Source : Google Books preview
For a spring of finite mass $m$ which is hanging vertically and carrying load $M$, the weight supported by each section of the spring (hence the tension in each section) increases linearly from $Mg$ at the bottom to $(M+m)g$ at the top. The extension of each section increases from the bottom to the top, in proportion to the tension. The extension is not uniform along the length of the spring, as it is in the horizontal case : it increases linearly from bottom to top. The average tension is $(M+\frac12 m)g$ so the total extension is $x$ where $(M+\frac12m)g=kx$. The effective mass of the spring is different for static extension ($\frac12 m$) than it is for dynamic extension, ie oscillation ($\frac13 m$).
In fact even for the horizontal case the author's calculation of the period applies only for one possible mode in which the spring oscillates - ie all sections being in phase with each other. Other modes are possible, with phase differences between sections, and different periods for each mode.