Skip to content

Commit e5a15fc

Browse files
authored
Merge pull request #500 from lplewa/mempolicy
add mempolicy with support of interleave, bind and preferred
2 parents 5efb153 + 60e3327 commit e5a15fc

18 files changed

+340
-71
lines changed

include/umf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <umf/memory_pool.h>
1414
#include <umf/memory_provider.h>
15+
#include <umf/mempolicy.h>
1516
#include <umf/memspace.h>
16-
#include <umf/memspace_policy.h>
1717

1818
#endif /* UMF_UNIFIED_MEMORY_FRAMEWORK_H */

include/umf/mempolicy.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
#ifndef UMF_MEMPOLICY_H
11+
#define UMF_MEMPOLICY_H 1
12+
13+
#include <umf/base.h>
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
typedef struct umf_mempolicy_t *umf_mempolicy_handle_t;
20+
typedef const struct umf_mempolicy_t *umf_const_mempolicy_handle_t;
21+
22+
typedef enum umf_mempolicy_membind_t {
23+
/// Interleave memory from all memory in memspace
24+
UMF_MEMPOLICY_INTERLEAVE,
25+
/// Bind memory to namespace
26+
UMF_MEMPOLICY_BIND,
27+
/// Prefer memory from namespace but fallback to other memory if not available
28+
UMF_MEMPOLICY_PREFERRED
29+
} umf_mempolicy_membind_t;
30+
31+
///
32+
/// @brief Creates a new memory policy
33+
/// @param bind memory binding policy
34+
/// @param hPolicy [out] handle to the newly created memory policy
35+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
36+
///
37+
umf_result_t umfMempolicyCreate(umf_mempolicy_membind_t bind,
38+
umf_mempolicy_handle_t *hPolicy);
39+
40+
///
41+
/// @brief Destroys memory policy
42+
/// @param hPolicy handle to memory policy
43+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
44+
///
45+
umf_result_t umfMempolicyDestroy(umf_mempolicy_handle_t hPolicy);
46+
47+
///
48+
/// @brief Sets custom part size for interleaved memory policy - by default it's interleaved by pages
49+
/// @param hPolicy handle to memory policy
50+
/// @param partSize size of the part or zero to use default part size (page size)
51+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
52+
///
53+
umf_result_t umfMempolicySetInterleavePartSize(umf_mempolicy_handle_t hPolicy,
54+
size_t partSize);
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
59+
#endif /* UMF_MEMPOLICY_H */

include/umf/memspace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <umf/base.h>
1414
#include <umf/memory_pool.h>
1515
#include <umf/memory_provider.h>
16-
#include <umf/memspace_policy.h>
16+
#include <umf/mempolicy.h>
1717

1818
#ifdef __cplusplus
1919
extern "C" {
@@ -29,7 +29,7 @@ typedef struct umf_memspace_t *umf_memspace_handle_t;
2929
/// \return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
3030
///
3131
umf_result_t umfPoolCreateFromMemspace(umf_memspace_handle_t hMemspace,
32-
umf_memspace_policy_handle_t hPolicy,
32+
umf_const_mempolicy_handle_t hPolicy,
3333
umf_memory_pool_handle_t *hPool);
3434

3535
///
@@ -41,7 +41,7 @@ umf_result_t umfPoolCreateFromMemspace(umf_memspace_handle_t hMemspace,
4141
///
4242
umf_result_t
4343
umfMemoryProviderCreateFromMemspace(umf_memspace_handle_t hMemspace,
44-
umf_memspace_policy_handle_t hPolicy,
44+
umf_const_mempolicy_handle_t hPolicy,
4545
umf_memory_provider_handle_t *hProvider);
4646

4747
///

include/umf/memspace_policy.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

scripts/docs_config/api.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,18 @@ TODO: Add general information about memspaces.
104104
Memspace
105105
------------------------------------------
106106
.. doxygenfile:: memspace.h
107-
:sections: define enum typedef func var
107+
:sections: define enum typedef func
108+
109+
Mempolicy
110+
==========================================
111+
112+
TODO: Add general information about mempolicies.
113+
114+
Mempolicy
115+
------------------------------------------
116+
.. doxygenfile:: mempolicy.h
117+
:sections: define enum typedef func
118+
108119

109120
Inter-Process Communication
110121
==========================================
@@ -118,4 +129,4 @@ operations for this API to work. Otherwise IPC APIs return an error.
118129
IPC API
119130
------------------------------------------
120131
.. doxygenfile:: ipc.h
121-
:sections: define enum typedef func var
132+
:sections: define enum typedef func var

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(UMF_SOURCES
5858
memory_provider.c
5959
memory_provider_get_last_failed.c
6060
memory_target.c
61+
mempolicy.c
6162
memspace.c
6263
provider/provider_tracking.c
6364
critnib/critnib.c

src/libumf.def.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ EXPORTS
3333
umfMemoryProviderPurgeForce
3434
umfMemoryProviderPurgeLazy
3535
umfMemoryProviderPutIPCHandle
36+
umfMempolicyCreate;
37+
umfMempolicyDestroy;
38+
umfMempolicySetInterleavePartSize;
3639
umfMemspaceDestroy
3740
umfOpenIPCHandle
3841
umfOsMemoryProviderOps

src/libumf.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ UMF_1.0 {
2828
umfMemoryProviderPurgeForce;
2929
umfMemoryProviderPurgeLazy;
3030
umfMemoryProviderPutIPCHandle;
31+
umfMempolicyCreate;
32+
umfMempolicyDestroy;
33+
umfMempolicySetInterleavePartSize;
3134
umfMemspaceCreateFromNumaArray;
3235
umfMemspaceDestroy;
3336
umfMemspaceHighestBandwidthGet;

src/memory_target.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
extern "C" {
1717
#endif
1818

19-
#include "base_alloc.h"
20-
2119
struct umf_memory_target_ops_t;
2220
typedef struct umf_memory_target_ops_t umf_memory_target_ops_t;
2321

src/memory_target_ops.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#ifndef UMF_MEMORY_TARGET_OPS_H
1111
#define UMF_MEMORY_TARGET_OPS_H 1
1212

13-
#include <stdbool.h>
14-
1513
#include <umf/base.h>
1614
#include <umf/memspace.h>
1715

@@ -33,11 +31,11 @@ typedef struct umf_memory_target_ops_t {
3331

3432
umf_result_t (*pool_create_from_memspace)(
3533
umf_memspace_handle_t memspace, void **memoryTargets, size_t numTargets,
36-
umf_memspace_policy_handle_t policy, umf_memory_pool_handle_t *pool);
34+
umf_const_mempolicy_handle_t policy, umf_memory_pool_handle_t *pool);
3735

3836
umf_result_t (*memory_provider_create_from_memspace)(
3937
umf_memspace_handle_t memspace, void **memoryTargets, size_t numTargets,
40-
umf_memspace_policy_handle_t policy,
38+
umf_const_mempolicy_handle_t policy,
4139
umf_memory_provider_handle_t *provider);
4240

4341
umf_result_t (*get_capacity)(void *memoryTarget, size_t *capacity);

0 commit comments

Comments
 (0)