[systemd-devel] [PATCH 26/26] shared: drop mempool, now unused

Lennart Poettering lennart at poettering.net
Mon Oct 20 11:43:06 PDT 2014


On Thu, 16.10.14 09:51, Michal Schmidt (mschmidt at redhat.com) wrote:

All other patches look great to me. Please go ahead and commit.

> ---
>  Makefile.am          |  2 --
>  src/shared/mempool.c | 94 ----------------------------------------------------
>  src/shared/mempool.h | 55 ------------------------------
>  3 files changed, 151 deletions(-)
>  delete mode 100644 src/shared/mempool.c
>  delete mode 100644 src/shared/mempool.h
> 
> diff --git a/Makefile.am b/Makefile.am
> index 3763228..714c050 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -769,8 +769,6 @@ libsystemd_shared_la_SOURCES = \
>  	src/shared/time-util.h \
>  	src/shared/locale-util.c \
>  	src/shared/locale-util.h \
> -	src/shared/mempool.c \
> -	src/shared/mempool.h \
>  	src/shared/hashmap.c \
>  	src/shared/hashmap.h \
>  	src/shared/siphash24.c \
> diff --git a/src/shared/mempool.c b/src/shared/mempool.c
> deleted file mode 100644
> index b1655ea..0000000
> --- a/src/shared/mempool.c
> +++ /dev/null
> @@ -1,94 +0,0 @@
> -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
> -
> -/***
> -  This file is part of systemd.
> -
> -  Copyright 2010-2014 Lennart Poettering
> -  Copyright 2014 Michal Schmidt
> -
> -  systemd is free software; you can redistribute it and/or modify it
> -  under the terms of the GNU Lesser General Public License as published by
> -  the Free Software Foundation; either version 2.1 of the License, or
> -  (at your option) any later version.
> -
> -  systemd is distributed in the hope that it will be useful, but
> -  WITHOUT ANY WARRANTY; without even the implied warranty of
> -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> -  Lesser General Public License for more details.
> -
> -  You should have received a copy of the GNU Lesser General Public License
> -  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> -***/
> -
> -#include "mempool.h"
> -#include "macro.h"
> -#include "util.h"
> -
> -struct pool {
> -        struct pool *next;
> -        unsigned n_tiles;
> -        unsigned n_used;
> -};
> -
> -void* __mempool_alloc_tile(struct mempool *mp) {
> -        unsigned i;
> -
> -        /* When a tile is released we add it to the list and simply
> -         * place the next pointer at its offset 0. */
> -
> -        assert(mp->tile_size >= sizeof(void*));
> -        assert(mp->at_least > 0);
> -
> -        if (mp->freelist) {
> -                void *r;
> -
> -                r = mp->freelist;
> -                mp->freelist = * (void**) mp->freelist;
> -                return r;
> -        }
> -
> -        if (_unlikely_(!mp->first_pool) ||
> -            _unlikely_(mp->first_pool->n_used >= mp->first_pool->n_tiles)) {
> -                unsigned n;
> -                size_t size;
> -                struct pool *p;
> -
> -                n = mp->first_pool ? mp->first_pool->n_tiles : 0;
> -                n = MAX(mp->at_least, n * 2);
> -                size = PAGE_ALIGN(ALIGN(sizeof(struct pool)) + n*mp->tile_size);
> -                n = (size - ALIGN(sizeof(struct pool))) / mp->tile_size;
> -
> -                p = malloc(size);
> -                if (!p)
> -                        return NULL;
> -
> -                p->next = mp->first_pool;
> -                p->n_tiles = n;
> -                p->n_used = 0;
> -
> -                mp->first_pool = p;
> -        }
> -
> -        i = mp->first_pool->n_used++;
> -
> -        return ((uint8_t*) mp->first_pool) + ALIGN(sizeof(struct pool)) + i*mp->tile_size;
> -}
> -
> -void __mempool_free_tile(struct mempool *mp, void *p) {
> -        * (void**) p = mp->freelist;
> -        mp->freelist = p;
> -}
> -
> -#ifdef VALGRIND
> -
> -void mempool_drop(struct mempool *mp) {
> -        struct pool *p = mp->first_pool;
> -        while (p) {
> -                struct pool *n;
> -                n = p->next;
> -                free(p);
> -                p = n;
> -        }
> -}
> -
> -#endif
> diff --git a/src/shared/mempool.h b/src/shared/mempool.h
> deleted file mode 100644
> index 7f8bb98..0000000
> --- a/src/shared/mempool.h
> +++ /dev/null
> @@ -1,55 +0,0 @@
> -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
> -
> -#pragma once
> -
> -/***
> -  This file is part of systemd.
> -
> -  Copyright 2011-2014 Lennart Poettering
> -  Copyright 2014 Michal Schmidt
> -
> -  systemd is free software; you can redistribute it and/or modify it
> -  under the terms of the GNU Lesser General Public License as published by
> -  the Free Software Foundation; either version 2.1 of the License, or
> -  (at your option) any later version.
> -
> -  systemd is distributed in the hope that it will be useful, but
> -  WITHOUT ANY WARRANTY; without even the implied warranty of
> -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> -  Lesser General Public License for more details.
> -
> -  You should have received a copy of the GNU Lesser General Public License
> -  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> -***/
> -
> -#include <stddef.h>
> -
> -struct pool;
> -
> -struct mempool {
> -        struct pool *first_pool;
> -        void *freelist;
> -        size_t tile_size;
> -        unsigned at_least;
> -};
> -
> -void* __mempool_alloc_tile(struct mempool *mp);
> -void __mempool_free_tile(struct mempool *mp, void *p);
> -
> -#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \
> -struct mempool pool_name = { \
> -        .tile_size = sizeof(tile_type), \
> -        .at_least = alloc_at_least, \
> -}; \
> -static inline tile_type* pool_name##_alloc_tile(void) { \
> -        return __mempool_alloc_tile(&pool_name); \
> -} \
> -static inline void pool_name##_free_tile(tile_type *p) { \
> -        __mempool_free_tile(&pool_name, p); \
> -} \
> -struct __useless_struct_to_allow_trailing_semicolon__
> -
> -
> -#ifdef VALGRIND
> -void mempool_drop(struct mempool *mp);
> -#endif
> -- 
> 2.1.0
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list