From: Doron Roberts-Kedes <doro...@fb.com> Date: Thu, 9 Aug 2018 15:43:44 -0700
> Taking a step back, is there an existing solution for what this function > is trying to do? I was surprised to find that there did not seem to > exist a function for determining the number of scatterlist elements > required to map an skb without COW. The reason is that we usually never need to "map" an SKB on receive, and on transmit the SKB geometry is normalized by the destination device features which means no frag_list. And the other existing receive path doing SW crypto, IPSEC, always COWs the data so get the number of SG array entries needed from skb_cow_data(). Frag lists on RX should be pretty rare. They occur when GRO segmentation encouters poorly arranged incoming SKBs. For example this happens if the incoming frames use lots of tiny SKB page frags, and therefore prevent accumulation into the page frag array of the head GRO skb. So yes it can happen, and we have to account for it. So I guess you really do need to accomodate this situation. Why don't you try to rearrange your new function with some likely() and unlikely() tests so that the straight code path optimizes for the non-frag-list case? Thanks!