From patchwork Tue Feb 28 15:41:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9596071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8A0A7601D7 for ; Tue, 28 Feb 2017 15:43:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AFDC28538 for ; Tue, 28 Feb 2017 15:43:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FF192853C; Tue, 28 Feb 2017 15:43:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F3328538 for ; Tue, 28 Feb 2017 15:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752551AbdB1PnH (ORCPT ); Tue, 28 Feb 2017 10:43:07 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35906 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751768AbdB1PmU (ORCPT ); Tue, 28 Feb 2017 10:42:20 -0500 Received: by mail-pf0-f193.google.com with SMTP id j5so1489462pfb.3; Tue, 28 Feb 2017 07:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LRKL3IIn+WTGG5sy5evKRMXRwH9xK7ukUwPSdFxu9xI=; b=ohqeH0elf/YGGmcByr1OWWTQ4KwDgoKRpail7kB4a3m81Gj9s9X35nPdFJDIwdB7CX MdSGN50cEFLCxxrW7rlD8+srOLQKS8oKkjhGV6ikwJxQDjPqS1ffG5BuVpOvqwKFr8a8 w1XeuDf2MPYWUrFpqmVMGVsY/SUsX2/Q4/G8GUZiWr3dOaGAictFmKE9wYzYPFnw+CZJ f0XnWNikjGq62Wx5QR+r8be+ddeCDn+Gpt94cGJWkBEes4j870PAqcXzruaQilqkQG9N o/t8Ncocxo/c/9f5r/t+XFo3eIC3DH8O0VRuHvpbgGXNtqzzQvzScKgBBj2p0llODv0u eaQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LRKL3IIn+WTGG5sy5evKRMXRwH9xK7ukUwPSdFxu9xI=; b=d6BpKPE7HRV8OLmcPcjaPEWAskrrVfPnGcyjRGuQmrIJAZhMUfJot9TIITFl6dV0E3 IRqBmixuEDCgFxkKSIMMi2wUvke9UiTgcOY7LTh1fwDMrzLil2h7jeJ24mYhCvWEw1Bx HUiakQNdUk1UrHPFKiyl656RwA9NZFcalcyjEyJDrHRnuXTfAQiJMJTmaDx2O6+gxKNq 1uVejHgKh9wSzp5i/F+Nwy3tNrKtbYn5hAk4p6lqRJDBE529fOduD+qf3rqHC68CHTFX YeCcv/Cz+A2cQfcKoXZeDjzzZr0DYE+tFc0lX9/2Hmitv+JskX37Gfk5EJC+8RMkhjsX ru/A== X-Gm-Message-State: AMke39nVJJCIjM4IGpTkEUXuN8NZcWcryj87cT+SGjXBH6m8kPHlqJGslhebumGh0Es9DQ== X-Received: by 10.99.36.71 with SMTP id k68mr3284693pgk.68.1488296537965; Tue, 28 Feb 2017 07:42:17 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id s26sm5105363pge.33.2017.02.28.07.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 07:42:17 -0800 (PST) From: Ming Lei To: Shaohua Li , Jens Axboe , linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig Cc: Ming Lei Subject: [PATCH v2 04/13] md: prepare for managing resync I/O pages in clean way Date: Tue, 28 Feb 2017 23:41:34 +0800 Message-Id: <1488296503-4987-5-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488296503-4987-1-git-send-email-tom.leiming@gmail.com> References: <1488296503-4987-1-git-send-email-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now resync I/O use bio's bec table to manage pages, this way is very hacky, and may not work any more once multipage bvec is introduced. So introduce helpers and new data structure for managing resync I/O pages more cleanly. Signed-off-by: Ming Lei --- drivers/md/md.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/md/md.h b/drivers/md/md.h index 1d63239a1be4..b5a638d85cb4 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -720,4 +720,58 @@ static inline void mddev_check_writesame(struct mddev *mddev, struct bio *bio) #define RESYNC_BLOCK_SIZE (64*1024) #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE) +/* for managing resync I/O pages */ +struct resync_pages { + unsigned idx; /* for get/put page from the pool */ + void *raid_bio; + struct page *pages[RESYNC_PAGES]; +}; + +static inline int resync_alloc_pages(struct resync_pages *rp, + gfp_t gfp_flags) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) { + rp->pages[i] = alloc_page(gfp_flags); + if (!rp->pages[i]) + goto out_free; + } + + return 0; + + out_free: + while (--i >= 0) + __free_page(rp->pages[i]); + return -ENOMEM; +} + +static inline void resync_free_pages(struct resync_pages *rp) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) + __free_page(rp->pages[i]); +} + +static inline void resync_get_all_pages(struct resync_pages *rp) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) + get_page(rp->pages[i]); +} + +static inline struct page *resync_fetch_page(struct resync_pages *rp) +{ + if (WARN_ON_ONCE(rp->idx >= RESYNC_PAGES)) + return NULL; + return rp->pages[rp->idx++]; +} + +static inline bool resync_page_available(struct resync_pages *rp) +{ + return rp->idx < RESYNC_PAGES; +} + #endif /* _MD_MD_H */