From mboxrd@z Thu Jan 1 00:00:00 1970 From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman) Subject: [PATCH review 6/8] dcache: Only read d_flags once is d_is_dir Date: Thu, 13 Aug 2015 23:34:40 -0500 Message-ID: <87y4heij33.fsf_-_@x220.int.ebiederm.org> References: <871tncuaf6.fsf@x220.int.ebiederm.org> <87mw5xq7lt.fsf@x220.int.ebiederm.org> <87a8yqou41.fsf_-_@x220.int.ebiederm.org> <874moq9oyb.fsf_-_@x220.int.ebiederm.org> <871tfkawu9.fsf_-_@x220.int.ebiederm.org> <87egjk9i61.fsf_-_@x220.int.ebiederm.org> <20150810043637.GC14139@ZenIV.linux.org.uk> <877foymrwt.fsf@x220.int.ebiederm.org> <87wpwyjxwc.fsf_-_@x220.int.ebiederm.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <87wpwyjxwc.fsf_-_-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org> (Eric W. Biederman's message of "Thu, 13 Aug 2015 23:29:23 -0500") List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Linux Containers Cc: Andrey Vagin , Miklos Szeredi , Richard Weinberger , Andy Lutomirski , "J. Bruce Fields" , Al Viro , linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jann Horn , Linus Torvalds , Willy Tarreau List-Id: containers.vger.kernel.org Cache the value of __d_entry_type in d_is_dir and test if it equal to DCACHE_DIRECTORY_TYPE or DCACHE_AUTODIR_TYPE. The generated assembly goes from: movl (%rdi), %eax # MEM[(volatile __u32 *)dentry_3(D)], tmp73 andl $7340032, %eax #, tmp73 cmpl $2097152, %eax #, tmp73 je .L1091 #, movl (%rdi), %eax # MEM[(volatile __u32 *)dentry_3(D)], tmp74 andl $7340032, %eax #, tmp74 cmpl $3145728, %eax #, tmp74 je .L1091 #, to: movl (%rdi), %eax # MEM[(volatile __u32 *)dentry_3(D)], tmp71 andl $6291456, %eax #, tmp71 cmpl $2097152, %eax #, tmp71 jne .L1091 #, Which with only one read of d_flags, one comparison and one jump is dramatically better code. As __d_entry_type is not written to allow the compiler to optimize away anything that it does, when it is possible and reasonable to optimize things away the optimization needs to be performend manually. Signed-off-by: "Eric W. Biederman" --- include/linux/dcache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 5b69856b45a2..82eb50aaf446 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -443,7 +443,8 @@ static inline bool d_is_autodir(const struct dentry *dentry) static inline bool d_is_dir(const struct dentry *dentry) { - return d_can_lookup(dentry) || d_is_autodir(dentry); + unsigned type = __d_entry_type(dentry); + return (type == DCACHE_DIRECTORY_TYPE) || (type == DCACHE_AUTODIR_TYPE); } static inline bool d_is_symlink(const struct dentry *dentry) -- 2.2.1