It was explained to me that sleep is rather like the hour after closing time at the Library...
All those books come in and are dumped in a pile on the desk all day long. The Librarian is busy all day and doesn't have time to sort the returned books out so it is only at the end of the day after the door is closed (ie REM sleep) that there is time to sort the books, return them to the shelves and tidy them up. If you don't get long enough blocks of sleep, 2 hours x 3 per night minimum,your brain doesn't get time to process the info that has come in, assign it to somewhere in the longterm memory (bookshelves) and place a ticket in the filing system showing where on the shelf the book can be found.
Getting lots of QUALITY sleep allows the Librarian to stack the shelves properly and audit the stock list. Without it the pile on the desk becomes huge and the shelves become empty.
Sleep medication is like getting a Temp in to help you with the admin.