Sponsored Content
Top Forums Programming Memory and cache access time discrepancy Post 302928311 by Vaibhavs1985 on Wednesday 10th of December 2014 07:05:08 PM
Old 12-10-2014
Memory and cache access time discrepancy

Code:
#include<stdio.h>
#include<stdlib.h>
#include<sys/time.h>
#include<time.h>
#include "rdtsc.h"
#define SIZE 4*64*1024

int main()
{
unsigned long long a,b;
int arr[SIZE]={0};
int i;
register int r;


a=rdtsc();
r=arr[0];
b=rdtsc();

printf("1st element Access Cycles = %llu\n",b-a);

a=rdtsc();
r=arr[1];
b=rdtsc();
printf("2nd Element Access Cycles = %llu\n",b-a);

}

In the above code I am trying to determine the number of cycles it takes to fetch the first element of an array from memory, and then the next cached element. When I execute this snippet, I am getting almost identical number of cycles for both accesses ~81 cycles. Can anybody explain me why this is happening. By all means, the first access should be very costly, but the access to next sequential element which has been brought into the cache should be much lesser.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Clearing of cache memory

Pls! will someone help me on how to clear my cache memory of my Internet browser Thanks Kayode (3 Replies)
Discussion started by: kayode
3 Replies

2. Solaris

File cache portion of memory on Solaris

I'm looking to get the file cache portion of physical (real) memory on a Solaris workstation (Similar to the Cache: line in /proc/meminfo on some Linux systems): # swap -s; swap -l; vmstat 2 2; echo "::memstat" | mdb -k total: 309376k bytes allocated + 41428k reserved = 350804k used,... (5 Replies)
Discussion started by: Devyn
5 Replies

3. UNIX for Dummies Questions & Answers

High use of cache memory

Hi, I'm running a debian lenny 1GB ram, but with a high I/O. This server has 400IOPS and 3MB/s sustain. So, I noted cached memory use 800MB, buffered memory use 50MB, and no free memory is available. Questions: What does mean such a high cached memory? Who's using this cached memory? Is... (3 Replies)
Discussion started by: iga3725
3 Replies

4. UNIX for Advanced & Expert Users

linux memory buffers & cache usage

18:45:47 # free -m total used free shared buffers cached Mem: 96679 95909 770 0 1530 19550 -/+ buffers/cache: 74828 21851 Swap: 12287 652 11635 Hi all. The below output is from a RHEL 4.5... (0 Replies)
Discussion started by: drummerrob
0 Replies

5. Red Hat

Need to release Cache memory

Right now i am using Red Hat Enterprise Linux AS release 4 and cache memory occupying around 1.5GB mentioned below, total used free shared buffers cached Mem: 2026 2021 5 0 161 1477 -/+ buffers/cache: 382 1644 ... (4 Replies)
Discussion started by: thakshina
4 Replies

6. Shell Programming and Scripting

Discrepancy in finding the top memory consuming processes

When I run 'top' command,I see the following Memory: 32G real, 12G free, 96G swap free Though it shows as 12G free,I am not able to account for processes that consume the rest 20G. In my understanding some process should be consuming atleast 15-16 G but I am not able to find them. Is... (1 Reply)
Discussion started by: prasperl
1 Replies

7. Programming

Ways to preserve a memory cache

The environment is Java/Windows. The program keeps near real-time state in memory cache, which is updated by multiple sources, size of the cache is roughly 500 MB, frequency of updates is ~ 20 per second. I am looking into different ways to keep current snapshot of the memory on the disk for a)... (9 Replies)
Discussion started by: migurus
9 Replies

8. Solaris

clear cache memory

hi all, i have noticed that my server has 64 GB RAM and i have application in this server but the server has free memory only 15% and utilized 85% however it didn't eat from swap . does any parameter can be configured in kernel to make the system clear memory from cache like linux i found... (4 Replies)
Discussion started by: maxim42
4 Replies

9. UNIX for Dummies Questions & Answers

Clearing memory cache on Linux server

i wish to clear memory cache on a production box and i was wondering what is the worst that can happen if i do? i already tested this on a backup server and everything seemed fine. but i need to know from you experts what are the worst things that can happen when i run it on a real server: ... (5 Replies)
Discussion started by: SkySmart
5 Replies

10. AIX

AIX swap space, physical memory & cache

Hi, I am new to AIX, Can someone please help me how to know the swap space, total physical memory and system cache? We are using AIX 5.3. Thanks! (3 Replies)
Discussion started by: Phaneendra G
3 Replies
CHI::Driver::Memory(3pm)				User Contributed Perl Documentation				  CHI::Driver::Memory(3pm)

NAME
CHI::Driver::Memory - In-process memory based cache VERSION
version 0.54 SYNOPSIS
use CHI; my $hash = {}; my $cache = CHI->new( driver => 'Memory', datastore => $hash ); my $cache = CHI->new( driver => 'Memory', global => 1 ); DESCRIPTION
This cache driver stores data on a per-process basis. This is the fastest of the cache implementations, but data can not be shared between processes. Data will remain in the cache until cleared, expired, or the process dies. To maintain the same semantics as other caches, references to data structures are deep-copied on set and get. Thus, modifications to the original data structure will not affect the data structure stored in the cache, and vica versa. See CHI::Driver::RawMemory for a faster memory cache that sacrifices this behavior. CONSTRUCTOR OPTIONS
When using this driver, the following options can be passed to CHI->new() in addition to the CHI. One of datastore or global must be specified, or else a warning (possibly an error eventually) will be thrown. datastore [HASHREF] A reference to a hash to be used for storage. Within the hash, each namespace is used as a key to a second-level hash. This hash may be passed to multiple CHI::Driver::Memory constructors. global [BOOL] Use a standard global datastore. Multiple caches created with this flag will see the same data. Before 0.21, this was the default behavior; now it must be specified explicitly (to avoid accidentally sharing the same datastore in unrelated code). DISCARD POLICY
For CHI/SIZE AWARENESS caches, this driver implements an 'LRU' policy, which discards the least recently used items first. This is the default policy. SEE ALSO
CHI::Driver::RawMemory, CHI AUTHOR
Jonathan Swartz <swartz@pobox.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jonathan Swartz. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-05-30 CHI::Driver::Memory(3pm)
All times are GMT -4. The time now is 11:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy