Solve a problem involving finding the maximum subarray sum and explain your approach.
Implement max_subarray_sum(nums), where nums is a non-empty list of integers. Return the largest possible sum of any contiguous, non-empty subarray.
The result must be correct when all values are negative, and the algorithm should run in linear time with constant extra space.
def max_subarray_sum(nums):