To understand what we're getting at, consider a small example (for readability, we will not show essential validity checks. Also, as this is a tiny code snippet, we haven't provided it as a kernel module in the book's code base):
struct mysmallctx {
int tx, rx;
char passwd[8], config[4];
} *ctx;
pr_info("sizeof struct mysmallctx = %zd bytes\n", sizeof(struct mysmallctx));
ctx = kzalloc(sizeof(struct mysmallctx), GFP_KERNEL);
pr_info("(context structure allocated and initialized to zero)\n"
"*actual* size allocated = %zu bytes\n", ksize(ctx));
The resulting output on my x86_64 Ubuntu guest system is as follows:
$ dmesg
[...]
sizeof struct mysmallctx = 20 bytes
(context structure allocated and initialized to zero)
*actual* size allocated = 32 bytes
So, we attempted to allocate 20 bytes with kzalloc(), but actually obtained 32 bytes (thus incurring a wastage of 12 bytes...