4. Let $P$ be a moving point on the surface of a cube $A B C D-A_{1} B_{1} C_{1} D_{1}$ with edge length 1, such that the volume of the pyramid $P-B D D_{1} B_{1}$ is $\frac{1}{3}$. Then the length of the trajectory of point $P$ is $\qquad$
4.2.

Given $S_{\text {rectangle } B D D_{1} B_{1}}=\sqrt{2}, V_{\text {tetrahedron } P-B D D_{1} B_{1}}=\frac{1}{3}$, we know the distance $h$ from point $P$ to plane $B D D_{1} B_{1}$ is $h=\frac{\sqrt{2}}{2}$.

Since the distances from $A A_{1}$ and $C C_{1}$ to plane $B D D_{1} B_{1}$ are both $\frac{\sqrt{2}}{2}$, the trajectory of point $P$ is the edges $A A_{1}$ and $C C_{1}$. Therefore, the length of the trajectory of point $P$ is 2.