All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/7] Rewrite the allocators
@ 2020-10-02 15:44 Claudio Imbrenda
  2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 1/7] lib/list: Add double linked list management functions Claudio Imbrenda
                   ` (8 more replies)
  0 siblings, 9 replies; 42+ messages in thread
From: Claudio Imbrenda @ 2020-10-02 15:44 UTC (permalink / raw)
  To: kvm, pbonzini; +Cc: frankja, david, thuth, cohuck, lvivier

The KVM unit tests are increasingly being used to test more than just
KVM. They are being used to test TCG, qemu I/O device emulation, other
hypervisors, and even actual hardware.

The existing memory allocators are becoming more and more inadequate to
the needs of the upcoming unit tests (but also some existing ones, see
below).

Some important features that are lacking:
* ability to perform a small physical page allocation with a big
  alignment withtout wasting huge amounts of memory
* ability to allocate physical pages from specific pools/areaas (e.g.
  below 16M, or 4G, etc)
* ability to reserve arbitrary pages (if free), removing them from the
  free pool

Some other features that are nice, but not so fundamental:
* no need for the generic allocator to keep track of metadata
  (i.e. allocation size), this is now handled by the lower level
  allocators
* coalescing small blocks into bigger ones, to allow contiguous memory
  freed in small blocks in a random order to be used for large
  allocations again

This is achieved in the following ways:

For the virtual allocator:
* only the virtul allocator needs one extra page of metadata, but only
  for allocations that wouldn't fit in one page

For the page allocator:
* page allocator has up to 6 memory pools, each pool has a metadata
  area; the metadata has a byte for each page in the area, describing
  the order of the block it belongs to, and whether it is free
* if there are no free blocks of the desired size, a bigger block is
  split until we reach the required size; the unused parts of the block
  are put back in the free lists
* if an allocation needs ablock with a larger alignment than its size, a
  larger block of (at least) the required order is split; the unused parts
  put back in the appropriate free lists
* if the allocation could not be satisfied, the next allowed area is
  searched; the allocation fails only when all allowed areas have been
  tried
* new functions to perform allocations from specific areas; the areas
  are arch-dependent and should be set up by the arch code
* for now x86 has a memory area for "lowest" memory under 16MB, one for
  "low" memory under 4GB and one for the rest, while s390x has one for under
  2GB and one for the rest; suggestions for more fine grained areas or for
  the other architectures are welcome
* upon freeing a block, an attempt is made to coalesce it into the
  appropriate neighbour (if it is free), and so on for the resulting
  larger block thus obtained

For the physical allocator:
* the minimum alignment is now handled manually, since it has been
  removed from the common struct


This patchset addresses some current but otherwise unsolvable issues on
s390x, such as the need to allocate a block under 2GB for each SMP CPU
upon CPU activation.

This patchset has been tested on s390x, amd64 and i386. It has also been
compiled on aarch64.

V1->V2:
* Renamed some functions, as per review comments
* Improved commit messages
* Split the list handling functions into an independent header
* Addded arch-specific headers to define the memory areas
* Fixed some minor issues
* The magic value for small allocations in the virtual allocator is now
  put right before the returned pointer, like for large allocations
* Added comments to make the code more readable
* Many minor fixes

Claudio Imbrenda (7):
  lib/list: Add double linked list management functions
  lib/vmalloc: vmalloc support for handling allocation metadata
  lib/asm: Add definitions of memory areas
  lib/alloc_page: complete rewrite of the page allocator
  lib/alloc: simplify free and malloc
  lib/alloc.h: remove align_min from struct alloc_ops
  lib/alloc_page: allow reserving arbitrary memory ranges

 lib/asm-generic/memory_areas.h |  11 +
 lib/arm/asm/memory_areas.h     |  11 +
 lib/arm64/asm/memory_areas.h   |  11 +
 lib/powerpc/asm/memory_areas.h |  11 +
 lib/ppc64/asm/memory_areas.h   |  11 +
 lib/s390x/asm/memory_areas.h   |  17 ++
 lib/x86/asm/memory_areas.h     |  22 ++
 lib/alloc.h                    |   3 +-
 lib/alloc_page.h               |  80 ++++-
 lib/list.h                     |  53 ++++
 lib/alloc.c                    |  42 +--
 lib/alloc_page.c               | 541 +++++++++++++++++++++++++++------
 lib/alloc_phys.c               |   9 +-
 lib/arm/setup.c                |   2 +-
 lib/s390x/sclp.c               |   6 +-
 lib/s390x/smp.c                |   6 +-
 lib/vmalloc.c                  | 121 ++++++--
 s390x/smp.c                    |   4 +-
 18 files changed, 789 insertions(+), 172 deletions(-)
 create mode 100644 lib/asm-generic/memory_areas.h
 create mode 100644 lib/arm/asm/memory_areas.h
 create mode 100644 lib/arm64/asm/memory_areas.h
 create mode 100644 lib/powerpc/asm/memory_areas.h
 create mode 100644 lib/ppc64/asm/memory_areas.h
 create mode 100644 lib/s390x/asm/memory_areas.h
 create mode 100644 lib/x86/asm/memory_areas.h
 create mode 100644 lib/list.h

-- 
2.26.2


^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2020-12-09  8:53 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 15:44 [kvm-unit-tests PATCH v2 0/7] Rewrite the allocators Claudio Imbrenda
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 1/7] lib/list: Add double linked list management functions Claudio Imbrenda
2020-10-02 18:18   ` Andrew Jones
2020-10-05  6:57     ` Claudio Imbrenda
2020-11-06 11:29   ` Paolo Bonzini
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 2/7] lib/vmalloc: vmalloc support for handling allocation metadata Claudio Imbrenda
2020-10-03  8:46   ` Andrew Jones
2020-10-05  7:00     ` Claudio Imbrenda
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 3/7] lib/asm: Add definitions of memory areas Claudio Imbrenda
2020-10-03  9:23   ` Andrew Jones
2020-10-05  7:10     ` Claudio Imbrenda
2020-11-06 11:34   ` Paolo Bonzini
2020-11-06 12:58     ` Claudio Imbrenda
2020-11-06 13:04       ` Paolo Bonzini
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 4/7] lib/alloc_page: complete rewrite of the page allocator Claudio Imbrenda
2020-10-05 12:40   ` Andrew Jones
2020-10-05 15:56     ` Claudio Imbrenda
2020-10-05 16:53       ` Andrew Jones
2020-10-05 17:18         ` Claudio Imbrenda
2020-10-05 18:04           ` Andrew Jones
2020-12-08  0:41   ` Nadav Amit
2020-12-08  1:10     ` Nadav Amit
2020-12-08  9:15       ` Claudio Imbrenda
2020-12-08  9:23         ` Nadav Amit
2020-12-08 10:00           ` Claudio Imbrenda
2020-12-08 12:48             ` Nadav Amit
2020-12-08 13:41               ` Claudio Imbrenda
2020-12-08 14:26                 ` Andrew Jones
2020-12-09  8:53                   ` Claudio Imbrenda
2020-12-08  9:11     ` Claudio Imbrenda
2020-12-08  9:16       ` Nadav Amit
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 5/7] lib/alloc: simplify free and malloc Claudio Imbrenda
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 6/7] lib/alloc.h: remove align_min from struct alloc_ops Claudio Imbrenda
2020-11-06 11:35   ` Paolo Bonzini
2020-11-06 12:56     ` Claudio Imbrenda
2020-10-02 15:44 ` [kvm-unit-tests PATCH v2 7/7] lib/alloc_page: allow reserving arbitrary memory ranges Claudio Imbrenda
2020-10-05 11:54 ` [kvm-unit-tests PATCH v2 0/7] Rewrite the allocators Pierre Morel
2020-10-05 12:35   ` Claudio Imbrenda
2020-10-05 12:49     ` Andrew Jones
2020-10-05 12:57     ` Pierre Morel
2020-10-05 14:59       ` Claudio Imbrenda
2020-11-06 11:36 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.