In the 1800s in Rio de Janeiro, there was such a high demand from Muslim slaves in Brazil for Arabic Qur'ans that one bookseller imported over 100 Qur'ans per year to sell to the local slaves. The slaves would spend years doing extra work to pay for them.
I recognize the words, 'slave', and 'bookseller', 'pay' and 'high demand' do not seem to fuse together so easily with we are programmed to think when it comes to 'slavery'. This is because there were early generations of Muslims who were taken as slaves from Africa and had been highly educated and learned, both in terms of Deen and academia when they were free.
For later generations, it was still possible to teach what was known about Islam to those who had never been free. As the successive centuries passed from the 1500s-1900s, it became more difficult to do so, but the knowledge of Islam still persisted in some form or another among large numbers, and with this the common interest in learning and preserving what the Qur'an taught. It was still possible in some ways for many slaves to be paid for their services, not necessarily by their slave masters, but by others for additional work, which was hard and while a lot of that money tended to disappear into the pockets of their slave masters, some of it, not always very much, was allowed for slaves to keep.