Dust and Stars - 1992 | Chapter 153 | Lock-Free and Boundaries | English
The time in the lower-right corner of the screen flipped to 02:17. In the server room, his was the only light left on. Lin Chen st
Chapter 153: Lock-Free and Boundaries
The time in the lower-right corner of the screen flipped to 02:17. In the server room, his was the only light left on. Lin Chen stared at the code on the feature/ssd_optimization branch, his finger hovering over the Enter key without immediately pressing the compile command.
Remove double buffering. Refactor the lock-free ring buffer. The theory was straightforward: SSDs had extremely low random-write latency, and the pre-aggregation done by double buffering had become a burden instead. He needed the parsing thread to push data directly into the queue and the consumer thread to take it out directly, with no mutex in between. But “lock-free” did not mean “unordered.” CPU out-of-order execution and cache-coherency protocols could create data tearing in gaps measured in nanoseconds. He had to insert memory barriers.
He created a new header file, ringbuf.h. He used the volatile keyword on the read and write pointers to prevent the compiler from optimizing away repeated reads. In the critical sections of push and pop, he hand-wrote __sync_synchronize() based on GCC built-ins. To account for false sharing in a multi-core environment, he added char padding[64] to the end of the read/write pointer struct, forcing alignment to a cache-line boundary. His left foot, resting on a bottle of mineral water, had long since gone numb from the cold. Condensation dripped from the bottle onto the tile floor, spreading into a small dark stain. Every half hour he shifted the position of his foot to restore circulation. The dull ache in his knees crept up the backs of his thighs like a bowstring being drawn tighter and tighter.
At 3:40 in the morning, the first version compiled successfully. He wrote a simple multithreaded stress-test script to simulate five thousand concurrent write requests. The terminal spat out: Segmentation fault. Core dumped.
Lin Chen did not get irritated. He pulled up gdb and loaded the core file. The bt command printed the call stack. The crash point was line 42 of ringbuf_pop. Pointer out of bounds. He stared at the assembly and worked backward line by line. The problem lay in the placement of the memory barrier. __sync_synchronize was a full barrier—too costly—and because it was placed after pop, the read pointer was being reused by the consumer thread before it had been updated. Old data in the cache line was mistakenly being read as new.
He removed the full barrier and switched to the lighter-weight __sync_lock_test_and_set. Before updating the read and write pointers, he inserted a read barrier; after writing the data, he inserted a write barrier. He reorganized the code logic from the ground up. He picked up the cold steamed bun on the desk and took a bite. Dry, hard crumbs fell into the gaps in the keyboard. He brushed them away with the back of his hand and kept typing.
At six in the morning, the sky outside had begun to pale. The campus broadcast started playing morning exercise music, muffled through the glass. Lin Chen pressed make. The compilation progress bar advanced steadily. No errors.
He started the stress test. Logs began streaming down the terminal. Memory usage stabilized at 52 MB. The latency curve looked like a strip of cloth ironed flat, pinned hard beneath 8 milliseconds. I/O wait time dropped close to zero. He stared at the screen, breathing lightly. Then a violent cramp shot through his left foot. The muscles spasmed uncontrollably, his toes curling tight. He sucked in a breath and jerked his hand away from the keyboard, pressing hard into his calf. Beneath his fingertips, the muscle was hard as stone. Gritting his teeth, he slowly straightened his leg and pushed upward from ankle to knee with his palm. Once, twice. The cramp gradually subsided, leaving behind a long, dull pain.
He glanced at his phone. 06:45. A little over two hours remained before the nine o’clock submission deadline. He opened the internal Git server and ran git push origin feature/ssd_optimization. The progress bar completed. He switched back to the main branch, merged the code, and tagged it v3.1-ssd-ready. The commit message was only one line: Adapted for high-concurrency random SSD I/O, removed redundant sequential-write logic, optimized memory barriers in the lock-free queue.
He sent it, leaned back in his chair, and closed his eyes. The fluorescent tubes in the server room gave off a faint hum. The air smelled of dust and old circuit boards. He felt a hollow kind of exhaustion, but his nerves were still taut. The money had not arrived yet. Wednesday’s acceptance test had not even begun. Engineer Li’s words—“If it doesn’t run, you’re out immediately”—stuck in his stomach like a thorn.
He stood up and tried to slip his left foot into his sandal. The ankle was even more swollen than yesterday, the skin an unhealthy purplish red. He gave up and stepped barefoot onto the cold tile with his left foot. At the water dispenser, he filled a cup with warm water and drank it slowly. Warmth returned to his stomach, and the stiffness in his limbs eased a little.
Back at his seat, he opened his notebook, turned to a fresh page, and wrote: SSD adaptation complete. Latency <8ms. Peak memory 52MB. Pending verification: actual IOPS and queue depth match on acceptance machine. His handwriting was steady, without cursive connections. He closed the notebook and began cleaning the desk. Empty water bottles, the wrapper from the cold steamed bun, loose sheets of draft paper—all of it went into a plastic bag. The server room had to be kept tidy. That was one of the training camp’s rules, and also a line he set for himself.
At 8:20 in the morning, he locked the server room door and headed down the corridor. His gait had fully changed by now: his right leg took the weight while the toes of his left foot barely touched the ground, as though he were stepping on cotton. Every step sent a tearing pull through the ligaments in his ankle. He moved slowly, one hand on the wall. Near the stairwell, he ran into two students on their way early to the library. They glanced at him, their eyes lingering for a second on his swollen foot, then hurried past. Lin Chen did not greet them. He was used to it.
By the time he reached the south gate, the rolling shutter of the Shaxian snack shop had only been pulled halfway up. The owner was moving gas canisters. Lin Chen went inside and ordered a bowl of wontons. He paid by scanning the code: 6 yuan. Balance: 21.3 yuan. The 810.4 yuan in online banking remained untouched. He sat on a plastic stool in the corner and waited for the wontons to arrive. Steam rose from the bowl, fogging his glasses. He took them off and wiped them with the hem of his shirt.
The wontons were very hot, the broth dotted with strips of laver and tiny dried shrimp. He ate slowly. The carbohydrates and hot soup slid down his throat, and for the first time his stomach felt solidly full. He needed that sense of solidity to carry him through the next forty-eight hours. Wednesday’s acceptance test was not the finish line, only an admission ticket. Only after getting that ticket could he even start talking about an extended internship and the remaining outsourcing payment. Xiaoman’s medicine could not be interrupted. The family ledger could not be allowed to break. He lowered his head and drank the soup until the bottom of the bowl was clean.
At exactly nine, he returned to the dorm and turned on his computer. Engineer Li’s message popped up right on time: “Code has been checked into the repository. Two o’clock this afternoon, Server Room No. 3, Area B. Bring the compiled binary and the environment configuration notes. Be there half an hour early for final integration testing.”
Lin Chen replied: “Received.”
He closed the chat window and began packaging the files. He compressed the v3.1 build output, dependency library paths, and startup scripts into a tar.gz. He checked the MD5 checksum three times. After confirming everything was correct, he copied it to a USB drive. Then he backed it up to cloud storage as well. Double insurance.
At one-thirty in the afternoon, he arrived early at Server Room No. 3 in Area B. The door was open, and someone inside was already debugging equipment. It was not Engineer Li, but a middle-aged man in a gray polo shirt, thinning on top, crouched behind a rack cabinet sorting cables. Hearing footsteps, the man looked up, glanced at Lin Chen’s foot, then at the USB drive in his hand.
“You’re Lin Chen?” the man asked, his voice flat.
“Yes.” Lin Chen nodded.
“Engineer Li got called to headquarters for a meeting. I’ll be handling the acceptance test. My name is Zhao Jianguo, architect from the technical department.” The man stood up and dusted off his hands. “The machine’s already been replaced. Get the program running first. I want to look at the logs.”
Lin Chen walked over to Machine No. 3. He inserted the USB drive, extracted the files, set the environment variables, and launched the startup script. Initialization messages appeared in the terminal. He pressed Enter.
The progress bar began to move. One second. Two seconds. Three. Then the screen flickered, and a red warning line appeared in the terminal: [WARN] I/O queue depth mismatch. Expected 64, Actual 16. Fallback to sync mode.
Lin Chen’s fingers stopped on the keyboard. Queue-depth mismatch. The SSD’s hardware queue had been limited by the BIOS or the driver to 16 rather than the 64 he had designed for. Under a low queue depth, the lock-free queue’s high-concurrency logic would trigger frequent spin-waiting and context switching. Latency would spike.
He turned to look at Zhao Jianguo. Zhao was staring at the screen, brows slightly furrowed. “What’s going on?”
“The hardware queue depth is capped,” Lin Chen said steadily. “My code was designed for 64. At 16, lock-free polling wastes CPU cycles. We need to adjust the queue consumption strategy—or switch back to double buffering.”
“The acceptance environment can’t be reconfigured.” Zhao looked at him. “You have twenty minutes. If you can’t hit the target metrics, then today counts as a failure.”
Lin Chen said nothing. He sat back down, his left foot resting lightly on the floor. His swollen ankle pressed against the cold metal chassis. He opened the terminal and pulled up performance monitoring. CPU utilization had already jumped to 45%, most of it spent idling in spin. Within twenty minutes, he had to change the lock-free queue’s polling logic into an event-driven model. Replace busy-waiting with futex, so the consumer thread would sleep when the queue was empty and wake when data was pushed.
He created a new file. His fingers dropped to the keyboard. Fast, but steady. The glow of the screen reflected on his face without a ripple. Outside the window, the early autumn sun slanted in and fell across the ventilation holes of the rack cabinet. Dust drifted slowly in the shaft of light.
He knew the real hard fight was only just beginning.
More from WayDigital
Continue through other published articles from the same publisher.
Comments
0 public responses
All visitors can read comments. Sign in to join the discussion.
Log in to comment