1ba5c3796Sopenharmony_ci/*
2ba5c3796Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3ba5c3796Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4ba5c3796Sopenharmony_ci * you may not use this file except in compliance with the License.
5ba5c3796Sopenharmony_ci * You may obtain a copy of the License at
6ba5c3796Sopenharmony_ci *
7ba5c3796Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8ba5c3796Sopenharmony_ci *
9ba5c3796Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10ba5c3796Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11ba5c3796Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ba5c3796Sopenharmony_ci * See the License for the specific language governing permissions and
13ba5c3796Sopenharmony_ci * limitations under the License.
14ba5c3796Sopenharmony_ci */
15ba5c3796Sopenharmony_ci
16ba5c3796Sopenharmony_ci#ifndef OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H
17ba5c3796Sopenharmony_ci#define OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H
18ba5c3796Sopenharmony_ci
19ba5c3796Sopenharmony_ci#include <map>
20ba5c3796Sopenharmony_ci#include <string>
21ba5c3796Sopenharmony_ci#include <set>
22ba5c3796Sopenharmony_ci#include <memory>
23ba5c3796Sopenharmony_ci
24ba5c3796Sopenharmony_ci#include "libxml/parser.h"
25ba5c3796Sopenharmony_ci#include "libxml/xpath.h"
26ba5c3796Sopenharmony_ci#include "kernel_interface.h"
27ba5c3796Sopenharmony_ci#include "reclaim_strategy_constants.h"
28ba5c3796Sopenharmony_ci#include "reclaim_priority_constants.h"
29ba5c3796Sopenharmony_ci#include "memory_level_constants.h"
30ba5c3796Sopenharmony_ci
31ba5c3796Sopenharmony_cinamespace OHOS {
32ba5c3796Sopenharmony_cinamespace Memory {
33ba5c3796Sopenharmony_ciclass ZswapdParam {
34ba5c3796Sopenharmony_cipublic:
35ba5c3796Sopenharmony_ci    int GetMinScore();
36ba5c3796Sopenharmony_ci    void SetMinScore(int minScore);
37ba5c3796Sopenharmony_ci    int GetMaxScore();
38ba5c3796Sopenharmony_ci    void SetMaxScore(int maxScore);
39ba5c3796Sopenharmony_ci    unsigned int GetMem2zramRatio();
40ba5c3796Sopenharmony_ci    void SetMem2zramRatio(unsigned int mem2zramRatio);
41ba5c3796Sopenharmony_ci    unsigned int GetZram2ufsRatio();
42ba5c3796Sopenharmony_ci    void SetZram2ufsRatio(unsigned int zram2ufsRatio);
43ba5c3796Sopenharmony_ci    unsigned int GetRefaultThreshold();
44ba5c3796Sopenharmony_ci    void SetRefaultThreshold(unsigned int refaultThreshold);
45ba5c3796Sopenharmony_ci    ZswapdParam();
46ba5c3796Sopenharmony_ci    ZswapdParam(int minScore, int maxScore, unsigned int mem2zramRatio,
47ba5c3796Sopenharmony_ci                unsigned int zram2ufsRatio, unsigned int refaultThreshold);
48ba5c3796Sopenharmony_ci
49ba5c3796Sopenharmony_ciprivate:
50ba5c3796Sopenharmony_ci    int minScore_ = 0;
51ba5c3796Sopenharmony_ci    int maxScore_ = 0;
52ba5c3796Sopenharmony_ci    unsigned int mem2zramRatio_ = 0;
53ba5c3796Sopenharmony_ci    unsigned int zram2ufsRatio_ = 0;
54ba5c3796Sopenharmony_ci    unsigned int refaultThreshold_ = 0;
55ba5c3796Sopenharmony_ci};
56ba5c3796Sopenharmony_ci
57ba5c3796Sopenharmony_cistruct ZswapdParamPtrCmp {
58ba5c3796Sopenharmony_ci    bool operator()(const std::shared_ptr<ZswapdParam> p1, const std::shared_ptr<ZswapdParam> p2)
59ba5c3796Sopenharmony_ci    {
60ba5c3796Sopenharmony_ci        if (p1->GetMinScore() <= p2->GetMinScore()) {
61ba5c3796Sopenharmony_ci            return true;
62ba5c3796Sopenharmony_ci        } else {
63ba5c3796Sopenharmony_ci            return false;
64ba5c3796Sopenharmony_ci        }
65ba5c3796Sopenharmony_ci    };
66ba5c3796Sopenharmony_ci};
67ba5c3796Sopenharmony_ci
68ba5c3796Sopenharmony_ciclass ReclaimConfig {
69ba5c3796Sopenharmony_cipublic:
70ba5c3796Sopenharmony_ci    void ParseConfig(const xmlNodePtr &rootNodePtr);
71ba5c3796Sopenharmony_ci    void SetZswapdParamConfig(std::map<std::string, std::string> &param);
72ba5c3796Sopenharmony_ci    using ReclaimConfigSet = std::set<std::shared_ptr<ZswapdParam>, ZswapdParamPtrCmp>;
73ba5c3796Sopenharmony_ci    const ReclaimConfigSet& GetReclaimConfigSet();
74ba5c3796Sopenharmony_ci    void AddReclaimConfigToSet(std::shared_ptr<ZswapdParam> reclaimConfig);
75ba5c3796Sopenharmony_ci    void ClearReclaimConfigSet();
76ba5c3796Sopenharmony_ci    ReclaimConfig();
77ba5c3796Sopenharmony_ci    void CheckZswapdParam(std::shared_ptr<ZswapdParam> zswapdParam);
78ba5c3796Sopenharmony_ci    void SetDefaultConfig(int minScore, int maxScore, unsigned int mem2zramRatio,
79ba5c3796Sopenharmony_ci                          unsigned int zram2ufsRatio, unsigned int refaultThreshold);
80ba5c3796Sopenharmony_ci    void Dump(int fd);
81ba5c3796Sopenharmony_ciprivate:
82ba5c3796Sopenharmony_ci    ReclaimConfigSet reclaimConfigSet_;
83ba5c3796Sopenharmony_ci};
84ba5c3796Sopenharmony_ci} // namespace Memory
85ba5c3796Sopenharmony_ci} // namespace OHOS
86ba5c3796Sopenharmony_ci#endif // OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H