Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5081226ybf; Wed, 4 Mar 2020 16:59:28 -0800 (PST) X-Google-Smtp-Source: ADFU+vsGn/lAU/Xn7B8S6UZj6Wr7xILDTXWE5Po5JwaejvL0pGIpDKX4/90307sevIGTERf+1f2v X-Received: by 2002:a9d:7d04:: with SMTP id v4mr4684087otn.308.1583369968764; Wed, 04 Mar 2020 16:59:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583369968; cv=none; d=google.com; s=arc-20160816; b=a/ka+z09ZCN5Q64MHTPrZIIXexXnz+imq7DQv/s26IRPC3OCrh+kKYBQsBDTS9UssU IENRXIFGhN2W7Yxgk+OWEz1yb2gvHa4Cj2iHyV5GV+n3Ad5EuaL1GE+nfvO6f6QVSyeJ 6loW3kh+cjRLOdVVDnu3HgmyZwu8wb3NUxcXZwUJ8N9e29yVGSZViMUCee6Vn5i7qIJU IHDqk1uqcO6zMaCm6SWI/B2mIuH726PQJEoBRYRbgqp1bYzG4kD+CRXeH4OCEVFsOIIj VRtyXRHpppJXiW2ii5nCHf56g73m7df21+wH+T5hlAcsBbYwZ8NWJ9Sl67wnEmh/1Ore Wp8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=t4z4q3EF442KjvHRBupQs53iCxAhVwgsYu5CWxCrAxo=; b=uLvq+ynt67+TCNHwlxGldG7XMQh44aqXQxmP5ul2wrSs2YOuZdxiym62qTvho6ym3z +UpxRVK3gbG6QEN4dW0/60z/uhQhQu6JIHsWcXO+IhUjhv0RfW4Msh3Njf+iRs8oacqd sz3O8TEUk/3J3LQN0y38jwogrcIQl1M4b1iCmtNScwVlJMivAtaEflgTOqLU+t/Vd6Hk CAdqaRKkM9dZxg8uSFPkhXdcaYph3eoIO2gGzqVZvcUn0vm1wfqUYEu8S99ZFr7tDsco Kt1VmoapkxnDMp6C3o4dxiAqxbqt/e+JE7fguhGPR0XeYW71spmFV11EuC6JwpPfTN2Y zJEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Fr0Yabb1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u24si2278651otk.287.2020.03.04.16.59.17; Wed, 04 Mar 2020 16:59:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Fr0Yabb1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726080AbgCEA5t (ORCPT + 99 others); Wed, 4 Mar 2020 19:57:49 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:38584 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725990AbgCEA5t (ORCPT ); Wed, 4 Mar 2020 19:57:49 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 0250vbdO013149 for ; Wed, 4 Mar 2020 16:57:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=t4z4q3EF442KjvHRBupQs53iCxAhVwgsYu5CWxCrAxo=; b=Fr0Yabb1GzmzQ5Ku84Ky7/meVzzH8Ae4h4LxtD/7OuTWL0T2J91wSb+qvSB6/zUcT0lA zMtjALjQQFn587l/ldXB294WA8v+yD4b8JadoLdpB8D9602hE23E7qAWL3tKELEP78Gp IJ4VabzqtAkjWvWoW1hAyXXT56MOfqXl6/8= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 2yhwxxqph3-13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 04 Mar 2020 16:57:47 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 4 Mar 2020 16:57:38 -0800 Received: by devvm4439.prn2.facebook.com (Postfix, from userid 111017) id 2C93F103323E4; Wed, 4 Mar 2020 16:57:36 -0800 (PST) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm4439.prn2.facebook.com To: Josef Bacik , Chris Mason , David Sterba CC: , , , Rik van Riel , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v3] btrfs: implement migratepage callback Date: Wed, 4 Mar 2020 16:57:35 -0800 Message-ID: <20200305005735.583008-1-guro@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-04_10:2020-03-04,2020-03-04 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 clxscore=1015 malwarescore=0 mlxlogscore=835 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003050003 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently btrfs doesn't provide a migratepage callback. It means that fallback_migrate_page() is used to migrate btrfs pages. fallback_migrate_page() cannot move dirty pages, instead it tries to flush them (in sync mode) or just fails (in async mode). In the sync mode pages which are scheduled to be processed by btrfs_writepage_fixup_worker() can't be effectively flushed by the migration code, because there is no established way to wait for the completion of the delayed work. It all leads to page migration failures. To fix it the patch implements a btrs-specific migratepage callback, which is similar to iomap_migrate_page() used by some other fs, except it does take care of the PagePrivate2 flag which is used for data ordering purposes. v3: fixed the build issue once again v2: fixed the build issue found by the kbuild test robot Signed-off-by: Roman Gushchin Reviewed-by: Chris Mason --- fs/btrfs/inode.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7735ce6127c3..6ed6df4afe5a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include "misc.h" @@ -8323,6 +8324,39 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) return __btrfs_releasepage(page, gfp_flags); } +#ifdef CONFIG_MIGRATION +static int btrfs_migratepage(struct address_space *mapping, + struct page *newpage, struct page *page, + enum migrate_mode mode) +{ + int ret; + + ret = migrate_page_move_mapping(mapping, newpage, page, 0); + if (ret != MIGRATEPAGE_SUCCESS) + return ret; + + if (page_has_private(page)) { + ClearPagePrivate(page); + get_page(newpage); + set_page_private(newpage, page_private(page)); + set_page_private(page, 0); + put_page(page); + SetPagePrivate(newpage); + } + + if (PagePrivate2(page)) { + ClearPagePrivate2(page); + SetPagePrivate2(newpage); + } + + if (mode != MIGRATE_SYNC_NO_COPY) + migrate_page_copy(newpage, page); + else + migrate_page_states(newpage, page); + return MIGRATEPAGE_SUCCESS; +} +#endif + static void btrfs_invalidatepage(struct page *page, unsigned int offset, unsigned int length) { @@ -10525,6 +10559,9 @@ static const struct address_space_operations btrfs_aops = { .direct_IO = btrfs_direct_IO, .invalidatepage = btrfs_invalidatepage, .releasepage = btrfs_releasepage, +#ifdef CONFIG_MIGRATION + .migratepage = btrfs_migratepage, +#endif .set_page_dirty = btrfs_set_page_dirty, .error_remove_page = generic_error_remove_page, .swap_activate = btrfs_swap_activate, -- 2.24.1