Generally speaking, a diet that is high in fiber, with a good range of fiber sources, can help to minimize the issue of shedding, and therefore reduce the risk of ingesting fur, and of hairball formation. Fiber may not necessarily be all that your kitty needs, however, and the addition of just a teaspoon of olive oil added to their food for a few days can help to lubricate their stomachs and coat the ingested hair.
Olive oil also has a laxative effect, and so it is recommended to watch your cat for any signs of intestinal distress, if they appear to be finding the treatment difficult then discontinue and consult your vet if the hairball problem has not been resolved. Olive oil is an easier option to help your cat to pass hairballs, as it is easier on digestion than petroleum-jelly, and mixing it with their cat food makes the entire experience much easier.