2013-12-29 22:13:08 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 Andrea Mazzoleni
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __RAID_MEMORY_H
|
|
|
|
|
#define __RAID_MEMORY_H
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Memory alignment provided by raid_malloc_align().
|
|
|
|
|
*
|
|
|
|
|
* It should guarantee good cache performance everywhere.
|
|
|
|
|
*/
|
|
|
|
|
#define RAID_MALLOC_ALIGN 256
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Memory displacement to avoid cache collisions on contiguous blocks,
|
2014-01-01 20:38:19 +01:00
|
|
|
* used by raid_malloc_vector().
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
|
|
|
|
* When allocating a sequence of blocks with a size of power of 2,
|
|
|
|
|
* there is the risk that the start of each block is mapped into the same
|
2014-01-02 17:51:50 +01:00
|
|
|
* cache line or prefetching prediction, resulting in collisions if you
|
|
|
|
|
* access all the blocks in parallel, from the start to the end.
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
|
|
|
|
* The selected value was choosen empirically with some speed tests
|
2014-01-01 20:38:19 +01:00
|
|
|
* with 8/12/16/20/24 data buffers of 256 KB.
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
2014-01-02 17:51:50 +01:00
|
|
|
* These are the results with no displacement:
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
2014-01-02 17:51:50 +01:00
|
|
|
* sse2
|
|
|
|
|
* par1 15368 [MB/s]
|
|
|
|
|
* par2 6814 [MB/s]
|
|
|
|
|
* parz 3033 [MB/s]
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
2014-01-02 17:51:50 +01:00
|
|
|
* These are the results with displacement resulting in improvments
|
|
|
|
|
* in the order of 20% or more:
|
|
|
|
|
*
|
|
|
|
|
* sse2
|
|
|
|
|
* par1 21936 [MB/s]
|
|
|
|
|
* par2 11902 [MB/s]
|
|
|
|
|
* parz 5838 [MB/s]
|
2013-12-29 22:13:08 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#define RAID_MALLOC_DISPLACEMENT (7*256)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Aligned malloc.
|
|
|
|
|
*/
|
|
|
|
|
void *raid_malloc_align(size_t size, void **freeptr);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Aligned vector allocation.
|
2014-01-03 10:36:21 +01:00
|
|
|
* Returns a vector of @n pointers, each one pointing to a block of
|
|
|
|
|
* the specified @size.
|
|
|
|
|
* The first @nd elements are reversed in order.
|
2013-12-29 22:13:08 +01:00
|
|
|
*/
|
2014-01-02 17:51:50 +01:00
|
|
|
void **raid_malloc_vector(int nd, int n, size_t size, void **freeptr);
|
2013-12-29 22:13:08 +01:00
|
|
|
|
|
|
|
|
/**
|
2014-01-02 17:51:50 +01:00
|
|
|
* Fills the memory vector with random data.
|
2013-12-29 22:13:08 +01:00
|
|
|
*/
|
2014-01-02 17:51:50 +01:00
|
|
|
void raid_mrand_vector(int n, size_t size, void **vv);
|
2013-12-29 22:13:08 +01:00
|
|
|
|
|
|
|
|
/**
|
2014-01-02 17:51:50 +01:00
|
|
|
* Tests the memory vector for RAM problems.
|
|
|
|
|
* If a problem is found, it crashes.
|
2013-12-29 22:13:08 +01:00
|
|
|
*/
|
2014-01-02 17:51:50 +01:00
|
|
|
int raid_mtest_vector(int n, size_t size, void **vv);
|
2013-12-29 22:13:08 +01:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|