Motr  M0
process_attr.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include <unistd.h> /* daemon */
24 
25 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_M0D
26 #include "lib/trace.h"
27 
28 #include <sys/resource.h>
29 #include "lib/bitmap.h"
30 #include "motr/process_attr.h"
31 #include "module/instance.h" /* m0 */
32 
38 static int reqh_memlimit_set(uint resource, uint64_t limit)
39 {
40  int rc;
41  struct rlimit rl;
42 
43  M0_ENTRY();
44 
45  rc = -getrlimit(resource, &rl);
46  if (rc !=0)
47  return M0_ERR(rc);
48  rl.rlim_cur = limit;
49  rc = -setrlimit(resource, &rl);
50 
51  return M0_RC(rc);
52 }
53 
55 {
56  int rc;
57  struct m0_proc_attr *proc_attr = &instance->i_proc_attr;
58 
59  M0_ENTRY();
60 
62  reqh_memlimit_set(RLIMIT_AS, proc_attr->pca_memlimit_as) : 0;
63  rc = rc == 0 &&
65  reqh_memlimit_set(RLIMIT_RSS, proc_attr->pca_memlimit_rss) : rc;
66  rc = rc == 0 &&
68  reqh_memlimit_set(RLIMIT_STACK, proc_attr->pca_memlimit_stack) : rc;
69  rc = rc == 0 &&
71  reqh_memlimit_set(RLIMIT_MEMLOCK, proc_attr->pca_memlimit_memlock) :
72  rc;
73  return M0_RC(rc);
74 }
75 
77 #undef M0_TRACE_SUBSYSTEM
78 
79 /*
80  * Local variables:
81  * c-indentation-style: "K&R"
82  * c-basic-offset: 8
83  * tab-width: 8
84  * fill-column: 80
85  * scroll-step: 1
86  * End:
87  */
uint64_t pca_memlimit_memlock
Definition: process_attr.h:59
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
return M0_ERR(-EOPNOTSUPP)
int m0_cs_memory_limits_setup(struct m0 *instance)
Definition: process_attr.c:54
Definition: instance.h:80
uint64_t pca_memlimit_rss
Definition: process_attr.h:57
static struct m0 instance
Definition: main.c:78
struct m0_proc_attr i_proc_attr
Definition: instance.h:143
uint64_t pca_memlimit_stack
Definition: process_attr.h:58
int32_t rc
Definition: trigger_fop.h:47
static int reqh_memlimit_set(uint resource, uint64_t limit)
Definition: process_attr.c:38
uint64_t pca_memlimit_as
Definition: process_attr.h:56