Re: how to flush cache ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Fri, Jul 17, 2009 at 7:01 PM, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote:
On Fri, Jul 17, 2009 at 6:54 PM, er krishna<erkrishna@xxxxxxxxx> wrote:
> Dear All,
>
> I am facing some problem, I have to flush the buffer cache  from my driver &
> I am trying to find any api for linux kernel or any way to do it from a
> kernel module on x86 platform. Does anybody know how to do it ? Please help.
>
> I have tried following things :
>
> 1. echo 3 > /proc/sys/vm/drop_caches :
>
> It works fine, but is there any way to do this from a kernel module, I mean
> is there anyway to write into in a existing proc entry via a kernel module
> using create_proc_entry function ? Or, Can someone tell me internally how
> this configuration parameter goes to kernel & what api it calls from any
> memory driver (or like that ) ?
>
>
> 2. void flush_cache_all(void) :
>
> This api doesn't work for linux kernel on x86 architecture , because it is
> defined blak ( only { } ) .

this "cache" which u are talking about is referring to the x86 CPU
cache, or L1 cache.   ****I think*****!!!!   but buffer cache is
indepdent of architecture so it  could not be this API.   many user of
this API flush_cache_all() is found in the different architecture
specific branch:

./arch/sparc/kernel/smp_32.c:
void smp_flush_cache_all(void)
       xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
       local_flush_cache_all();

./arch/sparc/kernel/sun4m_smp.c:
       local_flush_cache_all();

./arch/sparc/kernel/sun4d_smp.c:
       local_flush_cache_all();

./arch/m32r/mm/cache.c:
void _flush_cache_all(void

Again indicating its CPU-specific characteristic.


>>>> Agreed, I have seen it in kernel source code & I know its CPU specific. But I am in search of any specific kernel API similar to that which can flush the whole cache or the cache corresponding to a particular process or page. If somebody is aware, then please let me know.


 


Userspace it is called "sync" - read about this here:

http://linux.die.net/sag/buffer-cache.html

But in kernel, there are many types of syncing API available,
depending whether your memory is anonymously mapped or not etc....eg:

buffer.c:EXPORT_SYMBOL(sync_mapping_buffers);
buffer.c:EXPORT_SYMBOL(block_sync_page);
buffer.c:EXPORT_SYMBOL(file_fsync);
buffer.c:EXPORT_SYMBOL(sync_dirty_buffer);
fs-writeback.c:EXPORT_SYMBOL_GPL(generic_sync_sb_inodes);
fs-writeback.c:EXPORT_SYMBOL(sync_inode);
fs-writeback.c:EXPORT_SYMBOL(generic_osync_inode);
sync.c:EXPORT_SYMBOL_GPL(sync_filesystem);
sync.c:EXPORT_SYMBOL(vfs_fsync);
sync.c:EXPORT_SYMBOL_GPL(do_sync_mapping_range);

If u call sys_sync(), which is kernel's implementation of the
userspace sync() call, it will be quite heavy, as it will traverse all
possible mounted filesystem to sync it.   But since for a specific
driver, u know either the specific range of memory, or specific inode,
u can pick the more specific and less performance-overhead API from
the above list.

What are the specific input parameter for syncing?


>>>>> I am not able to open your specified link due to some internet problem. I have just tried
 echo 3 > /proc/sys/vm/drop_caches and it worked for me, it flushed the whole cache and results are as per my expectation. Just asking, your specified syncing apis flush the cache or not or in what manner it can help me ?


Second, can anybody let me know how does this flow goes into kernel ( flow : echo3 > /proc/sys/vm/drop_caches ), for particular proc_dir_entry,  /proc/sys/vm/cache & the corresponding write operation does some entries in kernel so that it flush the cache.


Actually I want to trace the whole code which flush the cache by above command, so that I can use it in my driver code accordingly.




Thanks & Best Regards,
Krishna

 

>
> 3. If anybody is aware of any such other api then please help me, its very
> urgent at my end.
>
>
> Thanks & Best Regards,
> Krishna
>



--
Regards,
Peter Teoh


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux