From patchwork Sat Jul 8 05:09:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 785816 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 3x4KJx2qyPz9sNV for ; Sat, 8 Jul 2017 15:09:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=thunk.org header.i=@thunk.org header.b="yp9CetvL"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750816AbdGHFJF (ORCPT ); Sat, 8 Jul 2017 01:09:05 -0400 Received: from imap.thunk.org ([74.207.234.97]:58834 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750733AbdGHFJE (ORCPT ); Sat, 8 Jul 2017 01:09:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=Jnc7MzwuKlY2Wk8L31NCAx+zae/8tTbznATO9trmwdI=; b=yp9CetvLil9EkZh6QZjtYma8UxI4JngTRh6Nq8BsIO/Ht5XzCRAzV4SpoUBQkVeP19Qb9HG2P/Ud46ZJgv3IXdTwYnso4gUMtIJ6+rd++IC5KOqkaTfFPArkh/R37ruXQU8cqPcMUMG3pajHRpthXc/smD3PB+D/jcXsoq15Bdk=; Received: from root (helo=callcc.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.84_2) (envelope-from ) id 1dThzJ-0000Fh-G6; Sat, 08 Jul 2017 05:09:01 +0000 Received: by callcc.thunk.org (Postfix, from userid 15806) id AFF4CC00612; Sat, 8 Jul 2017 01:09:00 -0400 (EDT) Date: Sat, 8 Jul 2017 01:09:00 -0400 From: Theodore Ts'o To: Tahsin Erdogan Cc: Jaegeuk Kim , Andreas Dilger , linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] ext4: fix __ext4_new_inode() journal credits calculation Message-ID: <20170708050900.afuwwia7c4izliir@thunk.org> Mail-Followup-To: Theodore Ts'o , Tahsin Erdogan , Jaegeuk Kim , Andreas Dilger , linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org References: <20170706023819.32272-1-tahsin@google.com> <20170706023819.32272-2-tahsin@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170706023819.32272-2-tahsin@google.com> User-Agent: NeoMutt/20170306 (1.8.0) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Jul 05, 2017 at 07:38:19PM -0700, Tahsin Erdogan wrote: > ea_inode feature allows creating extended attributes that are up to > 64k in size. Update __ext4_new_inode() to pick increased credit limits. > > To avoid overallocating too many journal credits, update > __ext4_xattr_set_credits() to make a distinction between xattr create > vs update. This helps __ext4_new_inode() because all attributes are > known to be new, so we can save credits that are normally needed to > delete old values. > > Also, have fscrypt specify its maximum context size so that we don't > end up allocating credits for 64k size. > > Signed-off-by: Tahsin Erdogan I've applied the following change to this patch in order to better calculate the credits needed by ext4_new_inode. The problem is that it was estimating a worse case of 287 blocks for ext4_new_inode() on a 10MB file system using the default 1024 block size. And on such a file system, the typical size of the journal is 1024 blocks, and the maximum number of credits that are allowed by a handle is 1024 / 4 = 256 blocks. This cases a number of regression tests to blow up. In reality the SElinux label and EVM/integrity xattrs are never going to be 64k, so calculating the credits assuming that as the worst case is not productive. And normally the Posix ACL is never going to be a worst case of 64k long, either... - Ted diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 21a2538afcc2..507bfb3344d4 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -784,12 +784,38 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, } if (!handle && sbi->s_journal && !(i_flags & EXT4_EA_INODE_FL)) { - /* - * 2 ea entries for ext4_init_acl(), 2 for ext4_init_security(). - */ - nblocks += 4 * __ext4_xattr_set_credits(sb, NULL /* inode */, - NULL /* block_bh */, XATTR_SIZE_MAX, +#ifdef CONFIG_EXT4_FS_POSIX_ACL + struct posix_acl *p = get_acl(dir, ACL_TYPE_DEFAULT); + + if (p) { + int acl_size = p->a_count * sizeof(ext4_acl_entry); + + nblocks += (S_ISDIR(mode) ? 2 : 1) * + __ext4_xattr_set_credits(sb, NULL /* inode */, + NULL /* block_bh */, acl_size, + true /* is_create */); + posix_acl_release(p); + } +#endif + +#ifdef CONFIG_SECURITY + { + int num_security_xattrs = 1; + +#ifdef CONFIG_INTEGRITY + num_security_xattrs++; +#endif + /* + * We assume that security xattrs are never + * more than 1k. In practice they are under + * 128 bytes. + */ + nblocks += num_security_xattrs * + __ext4_xattr_set_credits(sb, NULL /* inode */, + NULL /* block_bh */, 1024, true /* is_create */); + } +#endif if (encrypt) nblocks += __ext4_xattr_set_credits(sb, NULL /* inode */, NULL /* block_bh */,