From patchwork Mon Jun 23 14:58:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 4403591 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CECD19F390 for ; Mon, 23 Jun 2014 14:59:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE8A32018B for ; Mon, 23 Jun 2014 14:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE9B02017E for ; Mon, 23 Jun 2014 14:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754328AbaFWO65 (ORCPT ); Mon, 23 Jun 2014 10:58:57 -0400 Received: from mail-lb0-f171.google.com ([209.85.217.171]:35104 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753954AbaFWO6z (ORCPT ); Mon, 23 Jun 2014 10:58:55 -0400 Received: by mail-lb0-f171.google.com with SMTP id s7so4686592lbd.2 for ; Mon, 23 Jun 2014 07:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=iMVtm2+CDnxAUM/DiVkSTrcCxbe+WlM5DfdKI6KwNfE=; b=ArLwmLqNLYutUJDNQsE8fmc4kMopkaMR3u/5GWtlDseLUaHrd9lZEP7ER/SKqwL/oX 7g8/Lyed5bsl/EfGBYD22LQbrXuIfagVkg9nl0vD4khVR/zW7MgUmoXsJP1pRs6IHWJF 1RjhAYJT9Mv1UAkYWAU0abdXzHL9wQjxQbn45/Rb/IFPah9/kNTw3dnerncnxkC5gzmq 9PTvseCRwDnpvpzs6zuhFJn+Wu40ZZymI9g00Ph69V+od91jySYFgWEFHNQa/IEdt4LE KRDJBcBWy3N4iNeZe4G66hUutGpzn5vYMlsIswGRUENQQpFc+NNbcbQC/tE3tk78F07N 58DA== X-Received: by 10.152.5.194 with SMTP id u2mr17505588lau.1.1403535534017; Mon, 23 Jun 2014 07:58:54 -0700 (PDT) Received: from localhost.localdomain ([92.43.3.32]) by mx.google.com with ESMTPSA id fb6sm7964060lac.40.2014.06.23.07.58.52 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 07:58:53 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 3/9] CIFS: Separate pages initialization from writepages Date: Mon, 23 Jun 2014 18:58:31 +0400 Message-Id: <1403535517-8301-4-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403535517-8301-1-git-send-email-pshilovsky@samba.org> References: <1403535517-8301-1-git-send-email-pshilovsky@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index f143a4f..2c7fbd7 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1878,6 +1878,40 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) return rc; } +static struct cifs_writedata * +wdata_alloc_and_fillpages(pgoff_t tofind, struct address_space *mapping, + pgoff_t end, pgoff_t *index, + unsigned int *found_pages) +{ + unsigned int nr_pages; + struct page **pages; + struct cifs_writedata *wdata; + + wdata = cifs_writedata_alloc((unsigned int)tofind, + cifs_writev_complete); + if (!wdata) + return NULL; + + /* + * find_get_pages_tag seems to return a max of 256 on each + * iteration, so we must call it several times in order to + * fill the array or the wsize is effectively limited to + * 256 * PAGE_CACHE_SIZE. + */ + *found_pages = 0; + pages = wdata->pages; + do { + nr_pages = find_get_pages_tag(mapping, index, + PAGECACHE_TAG_DIRTY, tofind, + pages); + *found_pages += nr_pages; + tofind -= nr_pages; + pages += nr_pages; + } while (nr_pages && tofind && *index <= end); + + return wdata; +} + static unsigned int wdata_prepare_pages(struct cifs_writedata *wdata, unsigned int found_pages, struct address_space *mapping, @@ -2040,35 +2074,17 @@ retry: while (!done && index <= end) { unsigned int nr_pages, found_pages; pgoff_t next = 0, tofind; - struct page **pages; tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1, end - index) + 1; - wdata = cifs_writedata_alloc((unsigned int)tofind, - cifs_writev_complete); + wdata = wdata_alloc_and_fillpages(tofind, mapping, end, &index, + &found_pages); if (!wdata) { rc = -ENOMEM; break; } - /* - * find_get_pages_tag seems to return a max of 256 on each - * iteration, so we must call it several times in order to - * fill the array or the wsize is effectively limited to - * 256 * PAGE_CACHE_SIZE. - */ - found_pages = 0; - pages = wdata->pages; - do { - nr_pages = find_get_pages_tag(mapping, &index, - PAGECACHE_TAG_DIRTY, - tofind, pages); - found_pages += nr_pages; - tofind -= nr_pages; - pages += nr_pages; - } while (nr_pages && tofind && index <= end); - if (found_pages == 0) { kref_put(&wdata->refcount, cifs_writedata_release); break;