From patchwork Thu Mar 25 16:20:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jing zhang X-Patchwork-Id: 48533 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C0FDEB7CBD for ; Fri, 26 Mar 2010 03:20:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752287Ab0CYQU1 (ORCPT ); Thu, 25 Mar 2010 12:20:27 -0400 Received: from mail-pz0-f194.google.com ([209.85.222.194]:33202 "EHLO mail-pz0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752771Ab0CYQUY (ORCPT ); Thu, 25 Mar 2010 12:20:24 -0400 Received: by pzk32 with SMTP id 32so1791068pzk.4 for ; Thu, 25 Mar 2010 09:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=wcz7gEF9EtKIJjswTSPBgrjZ3lM2rRBDX2tKhT1KaUw=; b=RjB7E3EoULAC78ShejYqoghJmtYUIBIobSgyojE5wXWeLe4S1Dh7TmVxhpPypcPHpJ PDiWPdEcQNsGnXSS1jivSQ64HzkS2hxzgBEMY6CX5FDvR9VRLKCx861I8Y0qqvdbQ5o9 Vaa37yDTymQUsmkZs2oFdmRz3iTMcd4EddOE0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=SEhfdMpiyhd/K6P8ivWbbemwgQB6cgS+xAHcxIl3VKQ8W4ol99SLVbC2tRPPcN1U/G QILCRs481HOUG+2tcPUkXcHgIrEnC30ZHeNM2OfQUoq8CohWN1lS00fPm0nQ7wwcoOcG YEdoGKNDy6u1n1dvG9IDyH/jaGJZgooVNq/iM= MIME-Version: 1.0 Received: by 10.114.101.16 with SMTP id y16mr4403824wab.74.1269534024127; Thu, 25 Mar 2010 09:20:24 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Mar 2010 00:20:24 +0800 Message-ID: Subject: [PATCH 2/2] ext4: try to relieve ext4_mb_discard_group_preallocations() from hard work in simple way From: jing zhang To: linux-ext4 Cc: "Theodore Ts'o" , Andreas Dilger , Dave Kleikamp , "Aneesh Kumar K. V" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Jing Zhang Date: Wed Mar 25 23:15:06 2010 The function, ext4_mb_discard_group_preallocations(), works alone as hard as possible without correct understanding its caller's good thinking. With more understanding the work, the caller should be responsible for the mission. And the callee just does the correct, then feeds back, like chip. Then both get relieved. Cc: Theodore Ts'o Cc: Andreas Dilger Cc: Dave Kleikamp Cc: "Aneesh Kumar K. V" Signed-off-by: Jing Zhang --- the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- linux-2.6.32/fs/ext4/mballoc.c 2009-12-03 11:51:22.000000000 +0800 +++ ext4_mm_leak/mballoc-11-2.c 2010-03-25 23:56:24.000000000 +0800 @@ -3595,8 +3595,6 @@ ext4_mb_discard_group_preallocations(str struct ext4_allocation_context *ac; struct list_head list; struct ext4_buddy e4b; - int err; - int busy = 0; int free = 0; mb_debug(1, "discard preallocation for group %u\n", group); @@ -3611,29 +3609,25 @@ ext4_mb_discard_group_preallocations(str return 0; } - err = ext4_mb_load_buddy(sb, group, &e4b); - if (err) { + if (ext4_mb_load_buddy(sb, group, &e4b)) { ext4_error(sb, __func__, "Error in loading buddy " "information for %u", group); put_bh(bitmap_bh); return 0; } - if (needed == 0) - needed = EXT4_BLOCKS_PER_GROUP(sb) + 1; INIT_LIST_HEAD(&list); ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); if (ac) ac->ac_sb = sb; -repeat: + ext4_lock_group(sb, group); list_for_each_entry_safe(pa, tmp, &grp->bb_prealloc_list, pa_group_list) { spin_lock(&pa->pa_lock); if (atomic_read(&pa->pa_count)) { spin_unlock(&pa->pa_lock); - busy = 1; continue; } if (pa->pa_deleted) { @@ -3653,23 +3647,6 @@ repeat: list_add(&pa->u.pa_tmp_list, &list); } - /* if we still need more blocks and some PAs were used, try again */ - if (free < needed && busy) { - busy = 0; - ext4_unlock_group(sb, group); - /* - * Yield the CPU here so that we don't get soft lockup - * in non preempt case. - */ - yield(); - goto repeat; - } - - /* found anything to free? */ - if (list_empty(&list)) { - BUG_ON(free != 0); - goto out; - } /* now free all selected PAs */ list_for_each_entry_safe(pa, tmp, &list, u.pa_tmp_list) { @@ -3688,7 +3665,7 @@ repeat: call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); } -out: + ext4_unlock_group(sb, group); if (ac) kmem_cache_free(ext4_ac_cachep, ac); @@ -4183,14 +4160,24 @@ static int ext4_mb_discard_preallocation ext4_group_t i, ngroups = ext4_get_groups_count(sb); int ret; int freed = 0; + int tried = 0; trace_ext4_mb_discard_preallocations(sb, needed); +again: for (i = 0; i < ngroups && needed > 0; i++) { ret = ext4_mb_discard_group_preallocations(sb, i, needed); freed += ret; needed -= ret; } + if (needed > 0) + /* log it */ + mb_debug(1, "%d PAs undiscard\n", needed); + if (! freed && ! tried++) + /* try to avoid -ENOSPC */ + goto again; + if (! freed) + mb_debug(1, "discard PAs failed\n"); return freed; } -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in