[Drbd-dev] [PATCH 04/16] drbd: dirty bitmap
Andrew Morton
akpm at linux-foundation.org
Tue Jul 21 07:49:57 CEST 2009
On Mon, 6 Jul 2009 17:39:23 +0200 Philipp Reisner <philipp.reisner at linbit.com> wrote:
> DRBD maintains a dirty bitmap in case it has to run without peer node or
> without local disk. Writes to the on disk dirty bitmap are minimized by the
> activity log (=AL). Each time an extent is evicted from the AL the part of
> the bitmap no longer covered by the AL is written to disk.
>
> ...
>
> +static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
> +{
> + struct page **old_pages = b->bm_pages;
> + struct page **new_pages, *page;
> + unsigned int i, bytes, vmalloced = 0;
> + unsigned long have = b->bm_number_of_pages;
> +
> + BUG_ON(have == 0 && old_pages != NULL);
> + BUG_ON(have != 0 && old_pages == NULL);
> +
> + if (have == want)
> + return old_pages;
> +
> + /* Trying kmalloc first, falling back to vmalloc.
> + * GFP_KERNEL is ok, as this is done when a lower level disk is
> + * "attached" to the drbd. Context is receiver thread or cqueue
> + * thread. As we have no disk yet, we are not in the IO path,
> + * not even the IO path of the peer. */
> + bytes = sizeof(struct page *)*want;
> + new_pages = kmalloc(bytes, GFP_KERNEL);
> + if (!new_pages) {
> + new_pages = vmalloc(bytes);
> + if (!new_pages)
> + return NULL;
> + vmalloced = 1;
> + }
> +
> + memset(new_pages, 0, bytes);
> + if (want >= have) {
> + for (i = 0; i < have; i++)
> + new_pages[i] = old_pages[i];
> + for (; i < want; i++) {
> + page = alloc_page(GFP_HIGHUSER);
> + if (!page) {
> + bm_free_pages(new_pages + have, i - have);
> + bm_vk_free(new_pages, vmalloced);
> + return NULL;
> + }
> + new_pages[i] = page;
> + }
> + } else {
> + for (i = 0; i < want; i++)
> + new_pages[i] = old_pages[i];
> + /* NOT HERE, we are outside the spinlock!
> + bm_free_pages(old_pages + want, have - want);
> + */
> + }
> +
> + if (vmalloced)
> + set_bit(BM_P_VMALLOCED, &b->bm_flags);
> + else
> + clear_bit(BM_P_VMALLOCED, &b->bm_flags);
> +
> + return new_pages;
> +}
The vmalloc is always troublesome.
It's a pretty commonly-occurring pattern and I've been suggesting that
we implement a generic dynamic-array facility so that those callsites
which wish to do huge contiguous allocations need no longer do that.
Please take a look at this thread: http://lkml.org/lkml/2009/7/2/464
and let's see if there's any useful commonality here. I think there
is...
More information about the drbd-dev
mailing list