Device-to-device (D2D) communication has seen as a major technology to overcome the imminent wireless capacity crunch and to enable new application services. In this paper, we propose a social-aware approach for optimizing D2D communication by exploiting two layers: the social network and the physical wireless layers. First we formulate the physical layer D2D network according to users' encounter histories. Subsequently, we propose an approach, based on the so-called Indian Buffet Process, so as to model the distribution of contents in users' online social networks. Given the social relations collected by the Evolved Node B (eNB), we jointly optimize the traffic offloading process in D2D communication. In addition, we give the Chernoff bound and approximated cumulative distribution function (CDF) of the offloaded traffic. In the simulation, we proved the effectiveness of the bound and CDF. The numerical results based on real traces show that the proposed approach offload the traffic of eNB's successfully.