From 284fc695670e2156c71eb4a2677cba90bfa4c3ab Mon Sep 17 00:00:00 2001 From: Elfyn McBratney Date: Fri, 12 Jan 2007 06:24:02 +0000 Subject: [PATCH] Clean a bit - to be continued... --- libseven/balloc.c | 71 ++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/libseven/balloc.c b/libseven/balloc.c index efc97d6..43a6d9f 100644 --- a/libseven/balloc.c +++ b/libseven/balloc.c @@ -1,60 +1,45 @@ -/* - * ircd-ratbox: A slightly useful ircd. - * balloc.c: A block allocator. +/* {{{ irc-seven: Cows like it. * * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2005 ircd-ratbox development team * - * File: blalloc.c - * Owner: Wohali (Joan Touzet) - * - * Modified 2001/11/29 for mmap() support by Aaron Sethman + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program 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 General Public License for more details. * - * This program 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to: * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * Free Software Foundation, Inc. + * 51 Franklin St - Fifth Floor + * Boston, MA 02110-1301 + * USA * - */ + * }}} */ -/* - * About the block allocator +/* {{{ ircd-seven block allocator (balloc) * - * Basically we have three ways of getting memory off of the operating - * system. Below are this list of methods and the order of preference. + * The block allocator, funnily enough, allocates blocks of memory of variable + * size from the operating system. There are two ways we can do this, and they + * are: * - * 1. mmap() anonymous pages with the MMAP_ANON flag. - * 2. mmap() via the /dev/zero trick. - * 3. malloc() + * 1) by mapping in an anonymous page of memory with mmap(), or + * 2) increasing the size of the data segment thereby allocating memory for + * use with sbrk() [actually done with malloc() and friends]. * - * The advantages of 1 and 2 are this. We can munmap() the pages which will - * return the pages back to the operating system, thus reducing the size - * of the process as the memory is unused. malloc() on many systems just keeps - * a heap of memory to itself, which never gets given back to the OS, except on - * exit. This of course is bad, if say we have an event that causes us to allocate - * say, 200MB of memory, while our normal memory consumption would be 15MB. In the - * malloc() case, the amount of memory allocated to our process never goes down, as - * malloc() has it locked up in its heap. With the mmap() method, we can munmap() - * the block and return it back to the OS, thus causing our memory consumption to go - * down after we no longer need it. - * - * Of course it is up to the caller to make sure BlockHeapGarbageCollect() gets - * called periodically to do this cleanup, otherwise you'll keep the memory in the - * process. + * The advantage of using mmap()-based allocation is that, unlike the sbrk() + * method, allocated pages can be returned to the operating system (freed), + * whereas memory allocated from the data segment cannot be (because the data + * segment cannot be shrunk). * - * - */ + * }}} */ #include "stdinc.h" #include "libseven.h" -- 2.11.4.GIT