bareon-allocator/doc/source/architecture.rst

10 KiB
Raw Blame History

Architecture

Problem description

User may have a variety of bare-metal node configuration, with different amount of disks, types of disks and their sizes, there should be a way to store best practises on what is the best way to do partitioning, so they can be applied for the most configuration cases without asking the end user to manually adjust the configuration of partitioning, with posibility to do that, if user wants to.

History

First (and second) attempts to solve the problem has begun during development of Fuel project, special module VolumeManager was created to solve the problem, it consumes hardware information and partitioning schema, as result it generates sizes of spaces which should be allocated on the disks.

Current solution has plenty of problems, it's hard and expensive to solve this problem in terms of old VolumeManager, because trivial algorithms and schema format don't allow us to extend it easily, handle all of the cases combined is not a trivial task to do if we try to solve the problem using brute-force.

List of terms

  • Disk - a place where space can be allocated
  • Space - an entity which can be allocated on several disks at once, a good example of a space is a logical volume for lvm, another one is partition
  • Dynamic schema - a schema without specific sizes, it's a schema which is used by user to specify partitioning schema without details
  • Static schema - a schema for Bareon which requires exact space <-> disk mapping with exact size of each space

High level architecture

+-------------------------+
|                         |
|  Dynamic schema parser  |
|                         |
+------------+------------+
             |
             |
+------------v------------+
|                         |
|    Allocation solver    |
|                         |
+------------+------------+
             |
             |
+------------v-------------+
|                          |
|    Solution convertor    |
|                          |
+--------------------------+
  • Dynamic schema parser - parses an input from the user and prepares the data which can be consumed by Allocation solver
  • Allocation solver - an algorithm which takes dynamic schema and produces a static schema
  • Solution convertor - a result which is produced by solver, should be parsed and converted into Bareon consumable format, for example for Logical Volume Solution convertor should generate a physical volume for each disk, where it's allocated

Dynamic schema parser

In the current version we user flat schema, it's a list which consists dictionaries.

Basic syntax

  • id - id of a space
  • type - type of a space, for example Volume Group or Logical Volume
  • max_size - maximum size which is allowed for the space
  • min_size - minimal size which is allowed for the space
  • size - a static size, it's similar as to set for min_size and max_size the same value
  • contains - is required for hierarchical spaces such as Volume Group

Also there are couple of different attributes, such as mount, fs_type, which are self-explanatory. A list of such attributes is not complete and may be easily extended in the future.

- id: os
  type: vg
  contains:
    - id: swap
    - id: root

- id: root
  type: lv
  max_size: 10000
  min_size: 5000
  mount: /
  fs_type: ext4

- id: swap
  type: lv
  size: 2000
  fs_type: swap

Dynamic parameters

What if user wants to allocate a size of space based on some different parameter? As an example lets consider a size of swap which has to be based on amount of RAM the node has.

ram: 4096
disks:
  - id: /dev/disk/by-id/id-for-sda
    path: /dev/disk/by-path/path-for-sda
    dev: /dev/sda
    type: hdd
    vendor: Hitachi
    size: 5000

From Hardware Information example we can see that the node has 4096 megabytes of RAM, according to best practises on swap size allocation swap size has to be twice bigger than current RAM.

- id: swap
  type: lv
  size: 2000
  fs_type: swap
  size: |
    yaql=let(ram => $.get(ram, 1024)) ->
    selectCase(
      $ram <= 2048,
      $ram > 2048 and $ram < 8192,
      $ram > 8192 and $ram < 65536).
    switchCase(
      $ram * 2,
      $ram,
      $ram / 2,
      4096)

In order to implement an algorithm of swap size calculation we use YAQL, which is small but powerful enough query language. Any value of the parameter which matches to yaql=yaql expression will be evaluated using YAQL, execution result will be passed as is to the Solver.

Allocation solver

By the name of the chapter it can be seen that we are going to solve something.

Lets try to generalize a problem of spaces allocation:

  • there are constraints, for example size of a space cannot be bigger than size of all disks, or size of swap space cannot be bigger or smaller than size of the space
  • there exists "the best allocation static schema", it's almost impossible to find what "the best" is, what we can do is to parse all constraint and find such an allocation which fits all the constraints, and at the same time uses given resources (disks) by maximum

Lets consider an example with two spaces and a single disk, parameters which don't affect allocation problem were removed to reduce the amount of unnecessary information.

Two space root and swap, for swap there is static size which is 10, for root the size should be at least 50.

- id: root
  min_size: 50

- id: swap
  size: 10

A single ~10G disk.

disks:
  - id: sda
    size: 100

Also we can describe the same problem as:

$$\begin{aligned} \begin{cases} root + swap \le 100 \\ root \ge 50 \\ swap = 10 \end{cases} \end{aligned}$$

On disks with bigger sizes we can get a lot of solutions.

Lets consider two corner case solutions

root=50,swap=10

and

$$\begin{cases} root = 90, \quad swap = 10 \end{cases}$$

Second one is better since it uses more disks resources and doesn't leave unallocated space. So we should find a way to describe that second one is better.

It can be described with the next function.

Maximize:root+swap

Solver description

The problem is described in terms of Linear programming (note that "programming" is being used in not computer-programming sense). The method is being widely used to solve optimal resources allocation problem which is exactly what we are trying to achieve during the allocation.

max{cx:Axb}

  • cx - is an objective function for maximization
  • c - a vector of coefficients for the values to be found
  • x - a vector of result values
  • A - coefficients matrix
  • b - a vector, when combined with a row from matrix A gives as a constraint

Description of previous example in terms of Linear programming, is going to be pretty similar to what we did.

$$\begin{aligned} x_1 = root\\ x_2 = swap\\[2ex] \end{aligned}$$

Coefficients for objective function.

$$\begin{aligned} c = \begin{bmatrix} c_1 & c_2 \end{bmatrix}^{T}\\[2ex] \end{aligned}$$

A vector of values to be found, i.e. sizes of spaces.

$$\begin{aligned} x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\\[2ex] \end{aligned}$$

System of linear inequalities. Inequalities which are "less or equal" multiplied by -1 to make them "greater or equal".

$$\begin{aligned} A \ge b = \begin{cases} - x_1 - x_2 \ge -100 \\ x_1 \ge 50 \\ -x_2 \ge -10 \\ x_2 \ge 10 \\ x_1 \ge 0 \\ x_2 \ge 0 \end{cases}\\[2ex] \end{aligned}$$

A and b written in matrix and vector form respectively.

$$\begin{aligned} A = \begin{bmatrix} -1 & -1 \\ 1 & 0 \\ 0 & -1 \\ 0 & 1 \\ 1 & 0 \\ 0 & 1 \\ \end{bmatrix}\\[2ex] \end{aligned}$$$$\begin{aligned} b = \begin{bmatrix} -100 \\ 50 \\ -10 \\ 10 \\ 0 \\ 0 \end{bmatrix}\\[2ex] \end{aligned}$$

In order to solve the problem Scipy linprog module is being used. It uses Simplex algorithm to find the most feasible solution.

So what allocator does is builds a matrix and couple of vectors and using Simplex algorithm gets the result.

Two disks

If we have two spaces and two disks variable we will have 4 unkown variables:

  1. 1st space, 1st disk size
  2. 2st space, 1st disk size
  3. 1st space, 2st disk size
  4. 2st space, 2st disk size

Spaces definition which was used previously.

- id: root
  min_size: 50

- id: swap
  size: 10

And two disks.

disks:
  - id: sda
    size: 100
  - id: sdb
    size: 200

Resulting system of linear inequalities.

$$\begin{aligned} \begin{cases} x_1 + x_2 \le 100 \\ x_3 + x_4 \le 200 \\ \end{aligned}$$$$\begin{aligned} x_1 + x_3 \ge 50 \\ x_2 + x_4 = 10\\ \end{cases} \end{aligned}$$

  • x1+x2100 inequality for root and swap on the 1st disk
  • x3+x4200 inequality for root and swap on the 2nd disk
  • x1+x350 inequality for root space
  • x2+x4=10 equality for swap space

Unallocated

Integer solution

Mixed integer programming

Ordering

Weight

Best with disks