To optimize the key_buffer_size, you need to review the key_read statistics:
MariaDB [(none)]> SHOW STATUS LIKE “key%”;
+————————+———+
| Variable_name | Value |
+————————+———+
| Key_blocks_not_flushed | 0 |
| Key_blocks_unused | 1428301 |
| Key_blocks_used | 4187 |
| Key_blocks_warm | 0 |
| Key_read_requests | 82847 |
| Key_reads | 4187 |
| Key_write_requests | 76 |
| Key_writes | 76 |
+————————+———+
8 rows in set (0.00 sec)
Key_read_requests should be at a ratio of 100:1 or 1000:1 to key_reads.