c++ - How much DATA section memory is loaded along with Code section in C -


i have created shared library have static const data section , code section of 4 functions.

here details of static const data section,

static const u32 t0[256] = { 256 non_zero value }; static const u32 t1[256] = {256  non_zero value }; static const u32 t2[256] = {256  non_zero value }; static const u32 t3[256] = {256  non_zero value }; static const u32 t4[256] = {256  non_zero value }; static const u32 t5[256] = {256  non_zero value }; static const u32 t6[256] = {256  non_zero value }; static const u32 t7[256] = {256  non_zero value }; static const u32 t8[256] = {256  non_zero value }; static const u32 t9[10] = {10 non_zero value }; 

different functions defined below static const section

int a(); int b();  // access different index of t0 - t3 table  void c();  void d(); 

as per understanding text/code section contain executable instruction whereas data section contain initialized static data ( simplicity in case static const)

inside c() function , different index of t0,t1,t2 , t3 accessed in random order.

intentionally, inside c(), have not accessed t0[0].

however, every time call c() function, loading t0[0] irrespective of whether t0[0] accessed or not inside c() function.

my question how adjacent memory of data section loaded along code section?

i thinking may whole 4kb page loaded, everytime c() function called, whole 4kb page loaded , therefore t0[0] loaded along it.

but, experimental result shows concept not true/correct.

let me explain elaborately below.

i have calculated distance between function c() , different static const data below

base address of c - base address of t0[0] = 3221 bytes base address of c - base address of t1[0] = 4345 bytes base address of c - base address of t2[0] = 5369 bytes base address of c - base address of t3[0] = 6393 bytes 

so, whenever c() invoked , 64bytes (i.e. t0[0] ) loaded . t0[1], t0[2],... part of t0 array belong same 4kb page c() not loaded(if whole 4kb page loaded these must loaded, experiment result shows weren't loaded). hence concept whole 4kb page memory loaded wrong.

edit 1: based on comments of @nemetroid, c() , t0[0] may belong different page. that's why adding base address of both c() , t0[0] here.

base address of t0[0]=0xb7758d40 , base address of c=0xb7758047 when t0[0] loaded. 

in other experiment, when add static const of 64byte ( static const int data=10; ) before static const u32 t0[256] = {.....}

these distances become

base address of c - base address of t0[0] =3385 bytes [ =64 + base address of c - base address of t0[0]] base address of c - base address of t1[0] = 4345+64 bytes =4409 bytes [=64 + base address of c - base address of t0[0]+1024] base address of c - base address of t2[0] = 5369+64 bytes = 5433 bytes[=64 + base address of c - base address of t0[0]+2*1024] base address of c - base address of t3[0] = 6393 +64 bytes = 6457 bytes[=64 + base address of c - base address of t0[0]+3*1024] 

edit1 :

base address of t0[0]=0xb775cd80 (just shifted 64bytes), base address of c=0xb775c047 ( in case t0[0] not loaded) 

now, although t0[0] still present in same 4kb page c()(only shifted 64bytes), not loaded whenever c() invoked. here again can't along c(), whole 4kb page loaded.

can me explain/understand why t0[0] accessed/loaded whenever c() invoked although not accessed/used inside c() ?

or link understand memory layout of program , size of memory loaded during execution of program.

i using debian os , gcc compiler.

note : calculate whether t0[0] loaded or not , before invoking c(), flushed t0[0] using clflush() instruction , after c() invoked have calculated access time using rdtsc().

edit 1: using intel core i3 machine.

size of l1=32kb, 8 way associative, cache line size=64bytes size of l2=256kb, 8 way associative, cache line size=64bytes size of l3=3mb, 12 way associative, cache line size=64bytes 

pages aligned page size. so, if have page size of 4 kb, 0xaabbc000 - 0xaabbcfff belong same page, 0xaabbd000 - 0xaabbdfff, etc.

so if c has address 0xaabbcf00 , t0 has address 0xaabbd000 difference between addresses less 4 kb, still belong different pages. however, t0[0] , t0[1] in extreme likelihood belong same page. try running objdump -h a.out.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -