From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-f195.google.com ([209.85.219.195]:45699 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726732AbeJENiL (ORCPT ); Fri, 5 Oct 2018 09:38:11 -0400 MIME-Version: 1.0 References: <153870027422.29072.7433543674436957232.stgit@magnolia> <153870036143.29072.11970142092673351715.stgit@magnolia> In-Reply-To: <153870036143.29072.11970142092673351715.stgit@magnolia> From: Amir Goldstein Date: Fri, 5 Oct 2018 09:40:44 +0300 Message-ID: Subject: Re: [PATCH 12/15] vfs: implement opportunistic short dedupe To: "Darrick J. Wong" Cc: Dave Chinner , linux-xfs , linux-fsdevel , Linux Btrfs , ocfs2-devel@oss.oracle.com, Eric Sandeen Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Oct 5, 2018 at 3:46 AM Darrick J. Wong wrote: > > From: Darrick J. Wong > > For a given dedupe request, the bytes_deduped field in the control > structure tells userspace if we managed to deduplicate some, but not all > of, the requested regions starting from the file offsets supplied. > However, due to sloppy coding, the current dedupe code returns > FILE_DEDUPE_RANGE_DIFFERS if any part of the range is different. > Fix this so that we can actually support partial request completion. > > Signed-off-by: Darrick J. Wong > --- > fs/read_write.c | 44 +++++++++++++++++++++++++++++++++++--------- > include/linux/fs.h | 2 +- > 2 files changed, 36 insertions(+), 10 deletions(-) > > > diff --git a/fs/read_write.c b/fs/read_write.c > index 292d68c2f47c..9be9f261edd2 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -1781,13 +1781,11 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, > * Check that the extents are the same. > */ > if (is_dedupe) { > - bool is_same = false; > - > ret = vfs_dedupe_file_range_compare(inode_in, pos_in, > - inode_out, pos_out, *len, &is_same); > + inode_out, pos_out, len); > if (ret) > return ret; > - if (!is_same) > + if (*len == 0) > return -EBADE; > } > > @@ -1872,13 +1870,30 @@ static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset) > return page; > } > > +static unsigned int vfs_dedupe_memcmp(const char *s1, const char *s2, > + unsigned int cmp_len) > +{ > + const char *orig_s1 = s1; > + const char *e1 = s1 + cmp_len; > + const char *e2 = s2 + cmp_len; > + > + while (s1 < e1 && s2 < e2) { > + if (*s1 != *s2) > + break; > + s1++; > + s2++; > + } > + > + return s1 - orig_s1; > +} > + A few nits: 'len' wouldn't have been ambiguous in this context. I find the for loop in memcmp more elegant. It is definitely shorter. Not sure how differently the variants compile, but decrementing count/len seems much more sane then checking 2 conditions that always have the same result. Thanks, Amir.