See my patch. (1) maxsize should be in bytes (2) bad comments style corrected
The analysis of this problem is correct, however while investigating it I discovered that we also need to round maxsize up to a full page and add one to account for a possible extra boundary crossing, so the fix applied in r256637 was different than the submitted patch.
State Changed From-To: open->closed Fixed a different way in r256637. Thanks for the patch.