Different websites say different things about defragmenting Kindles, the ones I found are all several years old, and some say defragmenting is a poor idea compared to re-indexing.
How can you defragment a Paperwhite? Or is it a bad idea?
To defragment a filesystem you need a software that does that.
All you have to do to defragment the memory of your Kindle Paperwhite is to connect it to a PC/Mac and run a defragmentation utility on that drive.
Edit: Being a flash drive though, as @Daniel suggests, it's actually not a good idea to defragment it, because there will not be any real benefit in terms of performance and actually doing it many times will shorten the life of the memory of your device.
There is always something to learn out there!
Do not defragment any flash devices (in contrast to classic hard drives)
The original purpose of defragmentation was to reorganize data on a hard drive to shorten future paths of a read-head and therefore extending the lifespan of that drive.
In contrast flash devices do not gain any speed disadvantages of fragmented files. But flash memory wores out with each single write operation. This leads to the conclusion that regular defragmentation even harms your flash device (such as the built in storage of a kindle device or any SSD for example)
The only possible advantage of defragmentation could be a higher chance for data recovery following a hardware crash. But I doubt you want to shorten the lifespan of your kindle for recovery reasons.