usemem: Add code for touch-alloc
PATCH 1/1 usemem: Add code for touch-alloc
Add code for touch-alloc.
And Change read memory to write memory to avoid use the zero-page for reads in do_anonymous_page.
Signed-off-by Hui Zhu <[email protected]>
--- usemem.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
usemem.c +22 -12
@@ -329,6 +329,18 @@ void detach(void) } } +unsigned long do_access (unsigned long *p,unsigned long idx,int read) +{ +volatile unsigned long *vp = p; + +if (read) +return vp[idx];/* read data */ +else { + vp[idx] = idx;/* write data */ +return 0 ; + } +} +unsigned long *allocate (unsigned long bytes) {unsigned long *p;
@@ -355,6 +367,14 @@ unsigned long * allocate(unsigned long bytes) p = (unsigned long *)ALIGN ((unsigned long )p, pagesize -1 ); } +if (opt_touch_alloc) { +unsigned long i; +unsigned long m = bytes /sizeof (*p); + +for (i =0 ; i < m; i +=1 ) +do_access (p, i,0 ); + } +return p; }
@@ -436,18 +456,6 @@ void shm_unlock(int seg_id)shmctl (seg_id,SHM_UNLOCK ,NULL ); } -unsigned long do_access (unsigned long *p,unsigned long idx,int read) -{ -volatile unsigned long *vp = p; - -if (read) -return vp[idx];/* read data */ -else { - vp[idx] = idx;/* write data */ -return 0 ; - } -} -#define NSEC_PER_SEC (1UL * 1000 * 1000 * 1000)long nsec_sub (long nsec1,long nsec2)
@@ -953,6 +961,8 @@ int main(int argc, char *argv[]) opt_punch_holes =1 ; }else if (strcmp (opts[opt_index].name,"init-time" ) ==0 ) { opt_init_time =1 ; + }else if (strcmp (opts[opt_index].name,"touch-alloc" ) ==0 ) { + opt_touch_alloc =1 ; }else usage (1 );break ;
Signature · 1 line
2.17.1
Wu Fengguang
AppliedApplied, thanks!
Quoted 78 lines · Hui Zhu
Add code for touch-alloc.
And Change read memory to write memory to avoid use the zero-page for reads indo_anonymous_page.Signed-off-by Hui Zhu <[email protected]>---
usemem.c| 34 ++++++++++++++++++++++------------1 file changed, 22 insertions(+), 12 deletions(-)usemem.c +22
-12@@ -329,6 +329,18 @@ void detach(void) } } +unsigned long do_access (unsigned long *p,unsigned long idx,int read) +{ +volatile unsigned long *vp = p; + +if (read) +return vp[idx];/* read data */ +else { + vp[idx] = idx;/* write data */ +return 0 ; + } +} +unsigned long *allocate (unsigned long bytes) {unsigned long *p;@@ -355,6 +367,14 @@ unsigned long * allocate(unsigned long bytes) p = (unsigned long *)ALIGN ((unsigned long )p, pagesize -1 ); } +if (opt_touch_alloc) { +unsigned long i; +unsigned long m = bytes /sizeof (*p); + +for (i =0 ; i < m; i +=1 ) +do_access (p, i,0 ); + } +return p; }@@ -436,18 +456,6 @@ void shm_unlock(int seg_id)shmctl (seg_id,SHM_UNLOCK ,NULL ); } -unsigned long do_access (unsigned long *p,unsigned long idx,int read) -{ -volatile unsigned long *vp = p; - -if (read) -return vp[idx];/* read data */ -else { - vp[idx] = idx;/* write data */ -return 0 ; - } -} -#define NSEC_PER_SEC (1UL * 1000 * 1000 * 1000)long nsec_sub (long nsec1,long nsec2)@@ -953,6 +961,8 @@ int main(int argc, char *argv[]) opt_punch_holes =1 ; }else if (strcmp (opts[opt_index].name,"init-time" ) ==0 ) { opt_init_time =1 ; + }else if (strcmp (opts[opt_index].name,"touch-alloc" ) ==0 ) { + opt_touch_alloc =1 ; }else usage (1 );break ;Signature · 1 line
2.17.1