[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling sys_sysinfo from sched.c
// sched.c
unsigned long swpRtTimer = 0;
/*
* The end of void scheduler_tick(void)
*/
out:
rebalance_tick(cpu, rq, NOT_IDLE);
if (jiffies > swpRtTimer) {
getSwapRate();
swpsPerJff();
swpRtTimer = jiffies+HZ;
}
}
/*
* Measure how much swapping it being done. ~AMF
*/
unsigned long getSwapRate(void) {
swapRate = (swapRate + swapCount) >> 1;
printk(KERN_CRIT "Swap rate is: %u\n", swapRate);
printk(KERN_CRIT "Swap count was: %u\n", swapRate);
swapCount = 0;
return swapRate;
}
/*
* An alternative, but probably less accurate.
*/
unsigned long swpsPerJff(void) {
if (tSncLastSwp) {
unsigned long scaleSwaps = 100 / tSncLastSwp;
nr_swaps = (nr_swaps + scaleSwaps) >> 1;
}
return nr_swaps;
}
// memory.c
/*
* Time of last swap/majflt,
* Time since last swap/majflt,
* Number of swaps since last swapRate() call,
* Average number of swaps per swapRate() call,
* Average number of swaps estimated by swpsPerJff()
*/
unsigned long tLastSwp = 0;
unsigned long tSncLastSwp = 0;
unsigned long swapCount = 0;
unsigned long swapRate = 0;
unsigned long nr_swaps = 0;
/*
* It did this with the other externs so I assumed I should
* with mine as well.
*/
EXPORT_SYMBOL(tLastSwp);
EXPORT_SYMBOL(tSncLastSwp);
EXPORT_SYMBOL(swapCount);
EXPORT_SYMBOL(swapRate);
EXPORT_SYMBOL(nr_swaps);
/*
* At the end of do_swap_page:
*/
out:
if (ret == VM_FAULT_MAJOR) {
tSncLastSwp = jiffies - tLastSwp;
tLastSwp = jiffies;
swapCount++;
// printk(KERN_CRIT "Swap occured at time: %u\n", tLastSwp);
printk(KERN_CRIT "Jiffies since last swap: %u\n\n", tSncLastSwp);
}
return ret;
}
// mm.h
extern unsigned long tLastSwp;
extern unsigned long tLastSwp;
extern unsigned long tSncLastSwp;
extern unsigned long swapCount;
extern unsigned long swapRate;
extern unsigned long nr_swaps;
// sched.h after scheduler_tick is declared.
extern unsigned long getSwapRate(void);
extern unsigned long swpsPerJff(void);
So that's what I think I can use to activate/deactivate the swap token
mechanism. I'm not sure how accurate it is bit it definatly seems to notice
when there's a lot of programs opening and closing. It's hard to tell if this
is a good way of measuring the vm pressure/load or not at the moment. If
anyone knows of something that can stress test this, I could get a better
idea.
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/