Understanding Linux Memory Usage, Buffer Cache, and SQL Join Optimization
This article explains how to inspect and clear Linux memory buffers, interprets the fields shown by the free command, and then dives into SQL join types, performance‑impacting factors such as join_buffer_size, and practical optimization techniques like indexing and denormalization.
An interview style dialogue starts with a Linux memory‑usage question where the interviewer asks which command shows memory details; the answer is free or top . The output fields—total, used, free, buff/cache, and available—are described.
The interviewer then asks how to clear the buff/cache area, and the candidate is shown the command sync; echo 3 > /proc/sys/vm/drop_caches , explaining that it frees page cache, dentries and inodes, increasing available memory.
Switching topics, the conversation reviews SQL join concepts, listing inner, left, right, and full joins, and provides typical visual illustrations. Optimization advice includes adding indexes, reducing redundant joins, and keeping the number of table joins below five for large data sets.
The discussion highlights the importance of join_buffer_size in MySQL; a larger buffer can improve join performance. It also explains InnoDB’s storage model—16 KB pages, .ibd files per table, and the I/O cost of reading multiple files during joins.
Further, the article clarifies that Linux’s buff/cache acts as a disk cache, referencing the principle that each level of the memory hierarchy serves as a cache for the lower level, and cites CSAPP and Linux documentation.
Finally, join algorithm implementations are covered: Nested Loop Join (row‑by‑row comparison) and Block Nested Loop Join (reading blocks of rows to reduce I/O). The candidate notes that without indexes MySQL falls back to block nested loop, and suggests practical steps such as increasing join_buffer_size or moving to SSD storage to mitigate performance penalties.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.