I think it is best to just implement a recursive version of getPreferredLocs in the RDD class itself, without taking memory locality into account there. There are two reasons:

1. This method is called pretty often in the scheduler, and can become a pretty serious bottleneck if we synchronized it.

2. I don't think we should use memory locality in the coalesced rdd's preferred locations, because the life span of a coalesced rdd's preferred locations is the same as the rdd itself, but the life span of the cache locations vary.