Aim for about 90 seconds per muscle group, which can be split into a few shorter passes. A 2019 systematic review of 22 studies in the International Journal of Sports Physical Therapy found that rolling a muscle for at least 90 seconds appeared to be the minimum dose for a short-term reduction in muscle soreness, with no upper limit identified; rolling a muscle for less than 45 seconds may not be enough.
The same review found that gains in range of motion were short-lived and inconsistent, and it found no clear performance benefit, so a few minutes on your tightest areas is enough for most people. Foam rolling is not a substitute for medical care for an injury.
Source: Hughes and Ramer, “Duration of Myofascial Rolling for Optimal Recovery, Range of Motion, and Performance: A Systematic Review of the Literature,” Int J Sports Phys Ther, 2019;14(6):845–859 (PubMed Central).
Image: Foam rolling, by Roger Mommaerts. CC BY-SA 2.0, via Wikimedia Commons.