enhanced accounting data collection
Subsystems (9)
cover enhanced accounting data collection
This is an effort of providing an enhanced accounting data collection.
It is intended to offer common data collection method for various accounting packages including BSD accouting, ELSA, CSA, and any other acct packages that favor a common layer of data collection, separated from data presentation layer and management of process groups layer.
This patchset consists of two parts: acct_io and acct_mm as we identified useful spots for improved data collection in the area of IO and MM.
This patchset is to replace the previously submitted CSA patchset of four. The CSA kernel module is a standalone module. The csa_eop patch was to provide a hook for end-of-process handling and that can be considered separately unless there is enough common interest.
Now that the patchset is down to IO and MM, i hope it is more appealing :)
Comments?
Best Regards,
- jay
---
Jay Lan - Linux System Software
Silicon Graphics Inc., Mountain View, CA
Re: [PATCH 2.6.9-rc2 1/2] enhanced I/O accounting data collection
1/2: acct_io
Enhanced I/O accounting data collection.
drivers/block/ll_rw_blk.c +2 -0
@@ -1741,6 +1741,7 @@ {DEFINE_WAIT (wait);struct request *rq; +unsigned long start_wait = jiffies;generic_unplug_device (q); do {
@@ -1769,6 +1770,7 @@finish_wait (&rl->wait[rw], &wait); }while (!rq); + current->bwtime += (unsigned long ) jiffies - start_wait;return rq; }
fs/read_write.c +23 -2
@@ -216,8 +216,11 @@ ret = file->f_op->read (file, buf, count, pos); else ret =do_sync_read (file, buf, count, pos); -if (ret >0 ) +if (ret >0 ) {dnotify_parent (file->f_dentry,DN_ACCESS ); + current->rchar += ret; + } + current->syscr++; } }
@@ -260,8 +263,11 @@ ret = file->f_op->write (file, buf, count, pos); else ret =do_sync_write (file, buf, count, pos); -if (ret >0 ) +if (ret >0 ) {dnotify_parent (file->f_dentry,DN_MODIFY ); + current->wchar += ret; + } + current->syscw++; } }
@@ -540,6 +546,10 @@fput_light (file, fput_needed); } +if (ret >0 ) { + current->rchar += ret; + } + current->syscr++;return ret; }
@@ -558,6 +568,10 @@fput_light (file, fput_needed); } +if (ret >0 ) { + current->wchar += ret; + } + current->syscw++;return ret; }
@@ -636,6 +650,13 @@ retval = in_file->f_op->sendfile (in_file, ppos, count, file_send_actor, out_file); +if (retval >0 ) { + current->rchar += retval; + current->wchar += retval; + } + current->syscr++; + current->syscw++; +if (*ppos > max) retval = -EOVERFLOW ;
include/linux/sched.h +3 -0
@@ -591,6 +591,9 @@struct rw_semaphore pagg_sem;#endif +/* i/o counters(bytes read/written, #syscalls, waittime */ +unsigned long rchar, wchar, syscr, syscw, bwtime; + };static inline pid_t process_group (struct task_struct *tsk)
Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
In reply to Jay Lan2/2: acct_mm
Enhanced MM accounting data collection.
fs/exec.c +4 -0
@@ -47,6 +47,7 @@#include <linux/syscalls.h> #include <linux/rmap.h> #include <linux/pagg.h> +#include <linux/csa_internal.h> #include <asm/uaccess.h> #include <asm/mmu_context.h>
@@ -1163,6 +1164,9 @@/* execve success */ security_bprm_free (&bprm); +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater ();return retval; }
include/linux/csa_internal.h new file +70 -0
70 lines not on this page · raw message
include/linux/sched.h +19 -0
@@ -249,6 +249,8 @@struct kioctx *ioctx_list;struct kioctx default_kioctx; + +unsigned long hiwater_rss, hiwater_vm; };extern int mmlist_nr;
@@ -593,6 +595,10 @@/* i/o counters(bytes read/written, #syscalls, waittime */ unsigned long rchar, wchar, syscr, syscw, bwtime; +#if defined(CONFIG_CSA ) || defined(CONFIG_CSA_MODULE ) +u64 csa_rss_mem1, csa_vm_mem1; +clock_t csa_stimexpd; +#endif };
@@ -817,6 +823,19 @@/* Remove the current tasks stale references to the old mm_struct */ extern void mm_release (struct task_struct *,struct mm_struct *); +/* Update highwater values */ +static inline void update_mem_hiwater (void ) +{ +if (current->mm) { +if (current->mm->hiwater_rss < current->mm->rss) { + current->mm->hiwater_rss = current->mm->rss; + } +if (current->mm->hiwater_vm < current->mm->total_vm) { + current->mm->hiwater_vm = current->mm->total_vm; + } + } +} +extern int copy_thread (int ,unsigned long ,unsigned long ,unsigned long ,struct task_struct *,struct pt_regs *);extern void flush_thread (void );extern void exit_thread (void );
kernel/exit.c +4 -0
@@ -25,6 +25,7 @@#include <linux/proc_fs.h> #include <linux/mempolicy.h> #include <linux/pagg.h> +#include <linux/csa_internal.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -808,6 +809,9 @@ptrace_notify ((PTRACE_EVENT_EXIT <<8 ) |SIGTRAP ); } +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater ();acct_process (code);__exit_mm (tsk);
kernel/fork.c +6 -1
@@ -39,7 +39,7 @@#include <linux/profile.h> #include <linux/rmap.h> #include <linux/pagg.h> - +#include <linux/csa_internal.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> #include <asm/uaccess.h>
@@ -607,6 +607,9 @@if (retval) goto free_pt; + mm->hiwater_rss = mm->rss; + mm->hiwater_vm = mm->total_vm; + good_mm: tsk->mm = mm; tsk->active_mm = mm;
@@ -995,6 +998,8 @@ p->utime = p->stime =0 ; p->rchar = p->wchar = p->syscr = p->syscw =0 ; p->bwtime =0 ; +/* no-op if CONFIG_CSA not set */ +csa_clear_integrals (p); p->lock_depth =-1 ;/* -1 = no lock */ p->start_time =get_jiffies_64 (); p->security =NULL ;
mm/memory.c +19 -2
@@ -44,6 +44,7 @@#include <linux/highmem.h> #include <linux/pagemap.h> #include <linux/rmap.h> +#include <linux/csa_internal.h> #include <linux/module.h> #include <linux/init.h>
@@ -605,6 +606,8 @@ tlb =tlb_gather_mmu (mm,0 );unmap_vmas (&tlb, mm, vma, address, end, &nr_accounted, details);tlb_finish_mmu (tlb, address, end); +/* no-op unless CONFIG_CSA is set */ +csa_update_integrals ();spin_unlock (&mm->page_table_lock); }
@@ -1095,9 +1098,12 @@spin_lock (&mm->page_table_lock); page_table =pte_offset_map (pmd, address);if (likely (pte_same (*page_table, pte))) { -if (PageReserved (old_page)) +if (PageReserved (old_page)) { ++mm->rss; -else +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); + }else page_remove_rmap (old_page);break_cow (vma, new_page, address, page_table);lru_cache_add_active (new_page);
@@ -1379,6 +1385,10 @@remove_exclusive_swap_page (page); mm->rss++; +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); + pte =mk_pte (page, vma->vm_page_prot);if (write_access &&can_share_swap_page (page)) { pte =maybe_mkwrite (pte_mkdirty (pte), vma);
@@ -1444,6 +1454,9 @@ goto out; } mm->rss++; +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); entry =maybe_mkwrite (pte_mkdirty (mk_pte (page, vma->vm_page_prot)), vma);
@@ -1553,6 +1566,10 @@if (pte_none (*page_table)) {if (!PageReserved (new_page)) ++mm->rss; +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); +flush_icache_page (vma, new_page); entry =mk_pte (new_page, vma->vm_page_prot);if (write_access)
mm/mmap.c +10 -0
@@ -20,6 +20,7 @@#include <linux/hugetlb.h> #include <linux/profile.h> #include <linux/module.h> +#include <linux/csa_internal.h> #include <linux/mount.h> #include <linux/mempolicy.h> #include <linux/rmap.h>
@@ -1014,6 +1015,9 @@down_write (&mm->mmap_sem); }__vm_stat_account (mm, vm_flags, file, len >>PAGE_SHIFT ); +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater ();return addr; unmap_and_free_vma:
@@ -1360,6 +1364,9 @@if (vma->vm_flags &VM_LOCKED ) vma->vm_mm->locked_vm += grow;__vm_stat_account (vma->vm_mm, vma->vm_flags, vma->vm_file, grow); +/* no-op if CONFIG_CSA_JOB_ACCT not set */ +csa_update_integrals (); +update_mem_hiwater ();anon_vma_unlock (vma);return 0 ; }
@@ -1816,6 +1823,9 @@ mm->locked_vm += len >>PAGE_SHIFT ;make_pages_present (addr, addr + len); } +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater ();return addr; }
mm/mremap.c +8 -0
@@ -16,6 +16,7 @@#include <linux/fs.h> #include <linux/highmem.h> #include <linux/security.h> +#include <linux/csa_internal.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -232,6 +233,10 @@ new_addr + new_len); } +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); +return new_addr; }
@@ -368,6 +373,9 @@make_pages_present (addr + old_len, addr + new_len); } +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); ret = addr; goto out; }
mm/rmap.c +5 -0
@@ -50,6 +50,7 @@#include <linux/swapops.h> #include <linux/slab.h> #include <linux/init.h> +#include <linux/csa_internal.h> #include <linux/rmap.h> #include <linux/rcupdate.h>
@@ -580,6 +581,8 @@ } mm->rss--; +/* no-op if CONFIG_CSA not set */ +csa_update_integrals ();page_remove_rmap (page);page_cache_release (page);
@@ -679,6 +682,8 @@page_remove_rmap (page);page_cache_release (page); +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); mm->rss--; (*mapcount)--; }
mm/swapfile.c +4 -0
@@ -24,6 +24,7 @@#include <linux/module.h> #include <linux/rmap.h> #include <linux/security.h> +#include <linux/csa_internal.h> #include <linux/backing-dev.h> #include <asm/pgtable.h>
@@ -435,6 +436,9 @@set_pte (dir,pte_mkold (mk_pte (page, vma->vm_page_prot)));page_add_anon_rmap (page, vma, address);swap_free (entry); +/* no-op if CONFIG_CSA not set */ +csa_update_integrals (); +update_mem_hiwater (); }/* vma->vm_mm->page_table_lock is held */
Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
nits:
1) I'm not sure the "no-op if CONFIG_CSA not set" comments are worthwhile - it does not seem to be a common practice to mark macros that collapse under certain CONFIG's with such comments, and some code, such as in fork.c, would become quite a bit less readable if such comments were widely used.
2) Three of the added csa_update_integrals() lines have leading spaces, instead of a tab char, such as in:
===================================================================
fs/exec.c +3 -0
@@ -1163,6 +1164,9 @@/* execve success */ security_bprm_free (&bprm); +/* no-op if CONFIG_CSA not set */ + csa_update_integrals(); <========= + update_mem_hiwater(); <=========return retval; }
3) Is it always the case that csa_update_integrals() and update_mem_hiwater() are used together? If so, perhaps they could be collapsed into one? Even the current->mm test inside them could be made one test, perhaps?
4) What kind of kernel text size expansion does this cause? There seem to be about a dozen of these calls. What are the pros and cons of inlining csa_update_integrals() and update_mem_hiwater()? Are these on hot enough kernel code paths that we should benchmark with and without these hooks enabled, both inline and out-of-line?
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.650.933.1373Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
Quoted 6 lines · Paul Jackson
nits:
3) Is it always the case that
csa_update_integrals()andupdate_mem_hiwater()are used together? If so, perhaps they could be collapsed into one? Even thecurrent->mmtest inside them could be made one test, perhaps?
This sounds like a really good idea. Maybe update_mem_hiwater should have the #ifdef CONFIG_CSA inside it. This really sounds like a good idea. Is update_mem_hiwater everywhere that csa_update_integrals needs to be? I seem to remember one or two places where that was not the case. Of course that was a few years ago and my memory is really fuzzy
Quoted 7 lines
4) What kind of kernel text size expansion does this cause? There seem to be about a dozen of these calls. What are the pros and cons of inlining
csa_update_integrals()andupdate_mem_hiwater()? Are these on hot enough kernel code paths that we should benchmark with and without these hooks enabled, both inline and out-of-line?
The size was never very noticable. It usually did not even cause overflow to the next 4k page. The csa_job module added the biggest bloat, but I have nearly always compiled that as a module.
I have benchmarked these hooks a very long time ago. The number and location has not changed appreciably.
I ran three seperate tests. The first was without any csa config'd on. The second was with csa config'd on, but no job containers and the writing of the accounting file turned off. Last was with everything. We ran 7 runs of each config on a 32 cpu system.
There was no delta between the two kernels that were not writing accounting files. Actually, the average for the with integrals was 0.3% above the without integrals, but this is well within the noise range.
Originally, there was a 5% decrease in performance with the writing of the accounting data. There was another unfortunate side effect that some of the CSA metrics became much worse. This problem was later identified and fixed. At that point, CSA logging caused a 2.7% drop in AIM7 peak with shifting the transition point (I think that was the name I remember) towards a higher number of processes. Jack said that was due to a slight serializing of process exits.
Robin
Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
Quoted 2 lines · Robin
I have benchmarked these hooks a very long time ago. The number and location has not changed appreciably.
These results seem reasonable ... thanks.
Quoted 1 line
The size was never very noticable.
But would the time cost of being out of line be noticable either? Actually, being out of line might be a tick faster, if it reduced by a cache line what was needed for a common execution path.
Quoted 4 lines
Originally, there was a 5% decrease in performance with the writing of the accounting data. There was another unfortunate side effect that some of the CSA metrics became much worse. This problem was later identified and fixed.
Is there any non-trivial risk that some other "unfortunate side affect" exists today, that we'd find on benchmarking?
I'm not sure its worth benchmarking again, but I slightly suspect it is, and if benchmarking was done, I'd do it with these calls both inline and out of line, to see what affect that had on runtime. If no affect on runtime, I'd tend toward the out of line calls - at least saving a little kernel text space.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.650.933.1373Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
Quoted 3 lines
Is there any non-trivial risk that some other "unfortunate side affect" exists today, that we'd find on benchmarking?
When I last owned csa, I was running benchmarks before each SGI release. The tests were a simple matter of grabbing belay or belay2 and running setting up an FC disk vault (one was usually attached that had 16 disks and use Jack's runit script to launch it. I would then take the output and use Jack's web page to graph and compare it to the previous.
Additionally, every time I got access to a new larger system, I would run the tests on there and check for any odd affects of CSA.
Nothing interesting ever popped up from LBS2.1.1 all the way through to LBS3.0.
Quoted 6 lines
I'm not sure its worth benchmarking again, but I slightly suspect it is, and if benchmarking was done, I'd do it with these calls both inline and out of line, to see what affect that had on runtime. If no affect on runtime, I'd tend toward the out of line calls - at least saving a little kernel text space.
AIM7 is far to big of a hammer to find this level of micro-optimization. You could probably find or write a simple microbenchmark which shows the difference that introducing the code causes, but I would doubt it would show the inline versus the callout. Either way, we have probably spent more time discussing benchmarking this than it is worth at this point of time.
I would expect the do_no_page() path will be the easiest to identify the change. I have a simple test which maps a large region and then touches a large number of pages. The whole loop is surronded by reading of the Shub RTC register. This was done to determine the effect of quicklists on page faulting. That type of microbenchmark might be your best bet at finding the problem.
Robin
Re: [Lse-tech] Re: [PATCH 2.6.9-rc2 2/2] enhanced MM accounting data collection
In reply to Paul JacksonQuoted 8 lines · Paul Jackson
nits:
1) I'm not sure the "no-op if
CONFIG_CSAnot set" comments are worthwhile - it does not seem to be a common practice to mark macros that collapse under certain CONFIG's with such comments, and some code, such as infork.c, would become quite a bit less readable if such comments were widely used.
Yeah, that makes sense. Will be fixed in next posting.
Quoted 8 lines
2) Three of the added
csa_update_integrals()lines have leading spaces, instead of a tab char, such as in:===================================================================
fs/exec.c line 1171
Quoted 8 lines
fs/exec.c +3
-0@@ -1163,6 +1164,9 @@/* execve success */ security_bprm_free (&bprm); +/* no-op if CONFIG_CSA not set */ + csa_update_integrals(); <========= + update_mem_hiwater(); <=========return retval; }
Caused by 'cut-n-paste'. Will be fixed.
Quoted 5 lines
3) Is it always the case that
csa_update_integrals()andupdate_mem_hiwater()are used together? If so, perhaps they could be collapsed into one? Even thecurrent->mmtest inside them could be made one test, perhaps?
As Robin pointed out, there are a couple of instances that are not the case. Actually there are three.
Thanks for your feedback, Paul!
- jay