Linux Single file Pagecache refresh and view __linux

Source: Internet
Author: User

I. Refreshing files Pagecache

#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
int Clear_file_cache (const char *filename)
{
struct STAT st;
if (stat (filename, &st) < 0) {
fprintf (stderr, "stat LocalFile failed, path:%s\n", filename);
return-1;
}


int fd = open (filename, o_rdonly);
if (FD < 0) {
fprintf (stderr, "open LocalFile failed, path:%s\n", filename);
return-1;
}


Clear Cache by Posix_fadvise


if (Posix_fadvise (fd,0,st.st_size,posix_fadv_dontneed)!= 0) {
printf ("Cache Fadv_dontneed failed,%s\n", Strerror (errno));
}
else {
printf ("Cache fadv_dontneed done\n");
}


return 0;
}
int main (int argc, char *argv[])
{
if (ARGC < 2)
{
printf ("Please input filename\n");
return-1;
}
Clear_file_cache (argv[1]);
return 0;
}

Generate Fadvise after cross compilation, execute./fadvise file name

Two. See if the file is refreshed using Fincore

https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/

Cross-compile util-linux-2.32.tar.gz

1. Set up cross environment variables

2. Because using the libtinfo.so library, and my cross compilation chain is not, but now all with libncurses.so.5.9, so need to do a soft connection

Ln-s libncurses.so.5.9 libtinfo.so

3. Vim sys-utils/fallocate.c +354 Add semicolon

4. CC=ARM-OPENWRT-LINUX-GCC ld=arm-openwrt-linux-ld./configure--host=arm-linux--prefix=//home/happy/2disk/dirty_ Cow/util-linux-2.32/install
Make

Make install

Fincore files will be generated in the Install/bin directory

Download to the Board

Execute./fincore/lib//lib/libcurl.so.4.5.0

RES PAGES SIZE FILE

32K 8 351k/lib/libcurl.so.4.5.0

You can use one of the code to refresh the file, and then to view, but some cache is not out of the refresh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.