惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
T
ThreatConnect
J
Java Code Geeks
博客园 - 司徒正美
A
Arctic Wolf
T
True Tiger Recordings
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
The Register - Security
The Register - Security
S
Securelist
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
I
Intezer
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
K
Kaspersky official blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
V
V2EX
小众软件
小众软件
F
Fox-IT International blog
Martin Fowler
Martin Fowler
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
F
Future of Privacy Forum
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
T
Threatpost
I
InfoQ
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Tor Project blog
G
GRAHAM CLULEY
D
DataBreaches.Net

DEV Community

Add SVGIcons MCP to Claude Code and Find SVG Icons from Your Terminal 3 CLI Tools You Can Buy with Crypto — No KYC, No Subscriptions COSS Weekly: OpenClaw competitor NanoClaw Raises $12M, Dust Raises $40M, Sonar Acquires Gitar, and more How to know if you actually need mobile proxies (without buying any) Building Cursor for Community: A Buildathon Built on Time Pressure How we built a PII masking layer for LLM APIs — local detection, reversible tokens, one line to integrate 8 Vite Config Options Every Developer Should Know (Vite 8) Feature Flags That Forgot to Leave Why Trust Infrastructure Is Becoming the Hidden Layer of Donation Platforms XyPriss: Rethinking Core Performance and Zero-Trust Architecture in Modern Backends Designing Configuration for Scalable Treasure Hunts SSH Login Delays: The 10-Second Wait That Drives Us Crazy Building Production Multi-Agent Workflows in n8n: What 50 Deployments Taught Us A 3-layer memory system that gives Claude Code persistent context across sessions. Trishul SNMP Suite 2.0.1: Better MIBs, Traps, and SNMP Labs How I built a production AI SaaS as a solo developer Auto-labelling 1.2M robotics frames with VLMs: a failover story India’s Laws Were Not Built for AI — And Courts Are Filling the Gap skill-insp: A Skill That Scores Other Skills Clprolf Minimalist Messaging in the Age of AI What's actually in a good .cursorrules file? I built 10 of them — here's what I learned Building Strong Python Basics – Loops, Functions and Logic How to Choose the Right Tech Stack for Your Project I built a free multi-tab JSON editor — here's what I learned HTTP Headers Every Developer Should Know (2026) Building Cross-Platform Digital Products: Challenges and Best Practices Data Privacy in the Age of AI: How Product Teams Can Build Trust with Users What Would WordPress Look Like If It Were Designed Today? Why Backup Success Does Not Mean Database Recoverability Local AI Office Assistant That Never Sends Your Documents to the Cloud Building TaskForge: Translating Enterprise Chaos into an Open-Source Scheduler Tesla P40 in a Homelab: 24GB of Inference on a Budget Llama 4: Meta's Latest — Scout, Maverick, and the MoE Revolution George Hotz called AI code 'slop.' He's half right. Como Construir um Fluxo de Trabalho Baseado em Engenharia de Prompt e Automação We Audited Our Agent Tool-Call Traces. Half Our Eval Data Was Garbage. The Hidden Cost of Downtime: How SRE Error Budgets Protect National Economic Infrastructure Getting started with openHUMANS can be an exciting venture for developers looking to create innovative applications in the realm of human-ce Stack Overflow: A Powerful Community for Developers and Learners From Language Models to Humanoid Minds ✨ Road to Senior #2: How Computers Think in Numbers Why LLM debugging fails on fragmented repository context How to Deploy a LangGraph Agent on AWS Bedrock AgentCore An outreach kit for solo founders whose drafts can't hallucinate Open Satchel is live Amy Kwalwasser and the Growing Importance of Quantum Risk Modeling I Built ShellReq - A Native API Client for VS Code & Terminal If Microsoft and Uber can't afford AI coding, what chance do the rest of us have? MADCAP: Building a Multi-Agent Debate CLI That Argues With Itself So You Don't Have To Why most AI fails at IDOR (and how AMAS fixes it with causal reasoning) How to Audit a Laravel Codebase You've Inherited LangGraph 워크플로우 템플릿 (v34) BugBench: a developer origin story and practical guide for VS Code / Kiro users A solution to messy token systems for Next.js A NestJS reference app that proves the nest-native stack under realistic backend pressure Observability for AI Systems: Monitoring Drift, Hallucinations, and Reliability in Production I Thought “Data Analyst” Was the Whole Game… Then I Entered the Data Avengers Office 👀 Create and configure network security groups How to analyze the cost of Kafka? How I Shipped 2,500+ Commits With AI Agents Using a 12-Phase Workflow [Boost] We built MDCMS, a Markdown-first CMS for teams using AI agents Zero Heap Allocations at 1.18 GB/s: Deep Dive into ForgeZero 4.0.x The Minimum Viable Test Suite for Working with Agents Why Perplexity Started Citing My Blog: 5 Changes That Actually Worked Sync Supabase via OAuth: No Connection String Needed I asked three AI models the same API question. Only one had it right. Implementing Saga Pattern With Lambda Durable Function Why does AI forget what you said (and how to fix it) I built a daily Wordle-style game for AI tools - Here's how Mapping Polish company structures: querying KRS direct via API Built tmpdrop — a tiny self-hosted ephemeral file drop Running Local LLM - 0$ Personal Agentic AI Assistant - Part 3 LLD Object-Oriented Design: Interfaces & Abstract Classes (Designing Contracts) The Smaller Ship: Vitalik, the Ethereum Foundation's Restructuring, and What It Leaves for Investors Looking for 4 people to build something weird with me Building a Local-Only RAG System with Ollama and TypeScript The False Positive Tax: a 1:1 TP:FP analysis of eslint-plugin-security What's new in Data Preprocessor 1.5.x — R codegen, Robust Scaler, and a deadlock post-mortem How I self-hosted my Flask app on an old laptop for almost free I built a free DSA interview prep site because I was tired of the existing options I built an AI agent that migrates Next.js Pages Router to App Router Prisma Query Logging and PostgreSQL: Where the ORM Ends and the Database Begins Prisma query logging y PostgreSQL: dónde termina el ORM y empieza la base From Browser to Server : The Journey of an HTTP Request (Demystifying the Web’s Infrastructure) Santa Augmentcode Intent Ep.6 I Benchmarked 17 ESLint Security Plugins. Only One Found Every Vulnerability. How to Build a High-Performance Image Optimization Pipeline in 5 Minutes 50 Linux Commands Every DevOps Engineer Must Know Less Toil, More Flow - Automating the Path from Request to Implementation The Code Review Checklist I Actually Use How I run a small blog on Astro 5 + Content Collections Git: Best Practices for Professionals How IBM Bob Became My Everyday Coding Companion Solana Passkey Wallet: Replacing Seed Phrases with SIMD-0075 I built a small browser puzzle game about arrows I wrapped Claude Code in a zsh function. Here's every decision I almost got wrong. Mobile Game Optimization: A Unity Developer's Checklist Git: Best Practices for Beginners
Why MLFQ Was Way Ahead of Its Time
N Satyadev · 2026-05-26 · via DEV Community

Enough with the unga bunga puny algorithms.. did you know there exists an
scheduling algorithm that literally paved way for modern technology? and no it is not yet another FCFS where people just throw jobs in array order and call it a day without even bothering to sort...
What I am referring to is MLFQ (Multi Level Feedback Queue). Now a FCFS is fine.. it's like print("hello world") of OS scheduling but clearly we don't wanna "hello" the world forever.. there are in fact unhealthy amount of reasons why MLFQ is considered one of the greatest algorithms.. it outperforms every previous algorithm to exist..

  • FCFS: just runs in arrival order
  • SRTF: very dangerous as it is prone to starvation (gfg link to starvation article)
  • RR: well... RR is just RR.. Equality is overrated in 2026 anyway, so we don't really care about it much.

These are all valid reasons but there's another massive reason that is common to all.. if you notice any algorithm before MLFQ demands a prerequisite number i.e. it's burst time... sure RR does not require it, but RR believes in equal quantum time... which honestly works but MLFQ is RR on steroids which is much better.

RR operates on a single queue. Job runs for certain quantum time then next one runs and so on until there's no active process left..

That clearly takes care of the scheduling but do you see why it is not so efficient? Imagine yourself in a supermarket, all you want are some
hot cheetos.. but grandma amy, Infront of you is buying half the store cuz she got 27 coupons. Now you gotta wait for 30 whole mins just to get your cheetos.. the point is, that is pretty inefficient. Not that it won't get the job done but why wait so long for something so insignificant? that is whole point of MLFQ..

In this blog/article/my rant from now we're gonna get into deep dive discussion on MLFQ including a working C code walk through.

Now comes the juicy part.. the actual C code on how to go about it..

IMPLEMENTATION

Stage 1: The Structure

Job Structure

struct Job {
int arrival_time;
int cpu_burst;
int start;
int end;
int turnaround;
int response;
int remaining_time;
bool inQueue;
int serial;
int alloted_time;
int alloted_left;
};

Node Structure

struct Node {
int data;
struct Node *next;
};

Stage 2: The Implementation

So, the structure we go ahead from now is list the rule and I show
how I implemented it in code

Rule 1: If a process has a higher priority (higher queue), it runs first. If the priorities are equal, the process runs in round-robin fashion.

if (head != NULL) {
currentNode = head;
activeHead = &head;
activeTail = &tail;
} else if (head2 != NULL) {
currentNode = head2;
activeHead = &head2;
activeTail = &tail2;
}

The above has some terms like activeHead and activeTail which you can ignore for now as they are a very special segment which i will discuss later but here what's important is the RULE that is applies... at present the rule says highest priority runs and lower one doesnt... here let say there are only 2 queues.. so we check if head which is the root of that queue(a linked list) is empty or not.. if it is then clearly no jobs are running on high priority so we go for second queue which is head2 in this case.. so now head2 is checked and jobs in there are ran.
But what about next part which is if same priority then jobs run in RR fashion? the next piece of code does exactly that.

(*activeHead) = currentNode->next;
currentNode->next = NULL;
(*activeTail)->next = currentNode;
(*activeTail) = currentNode;

Here activeHead indicates which head is active btw(wow! totally genius). all RR does is get the first job and attach it at the back after quantum time.. that way rotation happens and fairness is imposed.

Rule 2: If a process exhausts its allocated time slice in a higher priority queue, it is demoted to a lower priority queue.

else if (job->alloted_left <= 0) {

Now if a job has alot of processing to do it will clearly take alot of time just like grandma amy and we all hate waiting.. hence MLFQ _gracefully _handles the situation by introducing concept of alloted time as mentioned earlier.

First we check "did the job use all of it's alloted time?" if yes then it has to go to counter two which only works after counter 1(queue1) is empty hence maintaining priority.

if (currentNode == head) {
temp = head;
head = head->next;
temp->next = NULL;
if (tail2 == NULL)
head2 = tail2 = currentNode;
else {
tail2->next = temp;
tail2 = temp;
temp = NULL;
}
}

then for our code we must check whether 2nd queue is empty or it already got someone else waiting.. if it's empty we just do head2 = tail2 = currentNode; which says hey, since there's no job in this queue point the head and tail of this to currentNode which is well.. the current node. But if it is not empty then we make the poor guy to go back to waiting by appending to end which we can see with this piece of code

tail2->next = temp;
tail2 = temp;
temp = NULL;

finally after we shift lower priority queue we would again want it to get it's alloted time as punishing the job forever just because it takes alot of time isn't fair.. so we do something like job->alloted_left = job->alloted_time; which resets the alloted timer and the job again get back to action (in lower priority)

Rule 3: After a fixed reset interval, all processes are boosted back to the highest priority queue.

if (reset_timer == 0) {
clearQueue(&head, &tail, &head2, &tail2, reset);
enqueueReset(jobs, &head, &tail, len);
reset_timer = reset;
}

Reset timer is another feature which makes MLFQ OP.. it not only treats the poor(you with hot cheetos) fairly but also the wealthy(grandma amy.. technically). It introduces reset which is a timer when it resets the whole system. By reset i mean taking all the jobs back to higher priority so that all get equal chance again avoiding starvation again.

This shows a clear queue function which is an approach that i used for reset. basically this is divided in 3 parts.

if (*head2 == NULL) return;

if 2nd queue is empty.. well just return as no need to reset since whole point of reset is get all stuff from queue2 to queue1.

if (*head == NULL) {
*head = *head2;
*tail = *tail2;
}

If head itself is null then head2(head of 2nd queue) is only active.. so we just map the 1st queue to 2nd and that's.

else {
(*tail)->next = *head2;
*tail = *tail2;
}

Finally if head2 is not null and head is also not null then just make the tail(last node of 1st queue) point to head2(first node of queue2) and make the tail of Q1 same as Q2.. Viola.. Now we have a single Q1 which has all current jobs.

Now we also need to insert new jobs available as we cannot leave any job unattended hence following can be done.

What the code does here is parse the entire array containing jobs, check whether it is still in queue and has not ended yet which indicates job is not finished yet. if found we make a new node out of it.

if(!(*head)) {
*head = *tail = newNode;
} else {
(*tail)->next = newNode;
*tail = newNode;
}

Then we check if head empty? if yes then there no active jobs and this new one is the highest priority if not then we just append the new job at tail of **FIRST **Queue not 2nd because new jobs are always assigned highest priority.

Now the an interesting approach here is use of double pointers a double pointer is as name suggests pointer to a pointer.

struct Node **activeHead, **activeTail;

What this does is declare a variable that points to something that is pointing to something else.. like activeHead -> head -> Node

essentially is like a of a train. Hypothetically let say there are only 3 compartments in a train. The engine which drives everything is a actual Node. 2nd compartment is connected to engine and 3rd is connected to 2nd.. similarly head -> Node and activeHead -> head.

Now how does this help in this scenario?

MLFQ is not restricted to only 2 Queues but more than 2 which makes it even more efficient. This double pointer helps avoid a huge if else statement by using activeHead, we write the scheduling logic once. We point activeHead to whichever queue has jobs, and the code treats it the same way whether it’s Queue 1, Queue 2, or Queue 10. It’s polymorphism for C programmers.

If you see it can get pretty ugly real fast. For more Queue's the if else string gets extended further which makes the code complete trash and stinky.

Now it leads us back to the snippet shared in the very first rule. This way we set the activeHead and activeTail by checking whether head is empty or not.

Conclusion

And that pretty much wraps up my implementation of MLFQ. What initially looked like “just another scheduling algorithm” ended up being one of the most interesting systems I’ve implemented so far.
Anyways if you actually read till here, congratulations. You survived queues, starvation, double pointers and my terrible supermarket analogies.