From patchwork Tue Dec 11 17:21:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37F07112E for ; Tue, 11 Dec 2018 17:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 195272B553 for ; Tue, 11 Dec 2018 17:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D08E2B561; Tue, 11 Dec 2018 17:21:55 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E46C2B553 for ; Tue, 11 Dec 2018 17:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECFF08E00B6; Tue, 11 Dec 2018 12:21:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1F2A8E0095; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1F828E0095; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 6EE2A8E00B4 for ; Tue, 11 Dec 2018 12:21:51 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id n17so13120540pfk.23 for ; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=k+qEjUPWQaTOi2SwKwehGKb14/YuxiclPBnzQY1y55Y=; b=EMnW3aExhvKU/nZxYvFH0O6Q3citOXB6/CmkN+qpdYgluDhhNKHpOYwIIEAQZj9bpN zHZQM53l375E7srzPqFyBh8XxKGWmBfGg+RvsT7FSHi1YVmF4D8OFIPEEP+rJ82/H2I6 FQHCdqeJqbPoB+4oPI7NqJ/DyklHq4+YPLLm5Q7xFgUImPh51qw0wO/qu66Sq1SlPvqI CK3IHF69yj6scwFG71nwCHIBghk6BIhTRg0eiPWpT6wnjIp0PSwWoPue3icdcNVItGF1 z5zz/fd9aeuyXq81WnY7E6iC2Oj+F+WsP4SN84Ga2KYx8LA+qxMYPDod1W+In2vlj6r/ x8Vw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWa8LdXz5sL4oC/gj8xfs8zKN+xFNz7XBa6Z7r2yAUNtnlbPPgxD A8SEjhOvUg8ZhJIQfkomK2qC2UqcPKpuDc6Pho7yV5qH1buFEzQQxK94ddYrf7U51LO3jRbFm7w aYM2JoB/I/UbPUUrGs37lFByusfR6AVQ7ZpzHjf0Dqup7FRZgK4MoeyXMEDnwbZes9Q== X-Received: by 2002:a62:b24a:: with SMTP id x71mr17546591pfe.148.1544548911084; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/WwMW9HlvC47Blkf+SZCK+H67XmEp+aD9wwidmmjM1AH09hDkgikRB8/ZQkohTYwhgRbYCp X-Received: by 2002:a62:b24a:: with SMTP id x71mr17546548pfe.148.1544548910327; Tue, 11 Dec 2018 09:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548910; cv=none; d=google.com; s=arc-20160816; b=Dh7MY3HpepQLVBlDb3RDr3/Wg7ItvfaalTYpNg4jbSjm8tGCaE4d3kF0KLp50iSOJm LMCniyYSB5Zrg715opeT+BAMbccFHOxc5nwVqxLMv41b4d38OlOcZbYSLk8M4ZRIWD8b ylz/O2XHsQpnf0lh1KeL25OdmoOY0K0evQ6S0c2xJucWPFu1lmFkQNfOKzhUvR/gYFg6 8alU6uP/qyd3Gq/kcV7mqCRVor8wLnAwE++6ZPR9L0E7xj3fLxmSw4ejWTPuX+5vHsIB jl4QfGW75hGeL3A2I3oRbrRDwWnB7SuOv3/02lZ2GXgM1q642Yx2Y65a26+TneOw5YEd KcmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=k+qEjUPWQaTOi2SwKwehGKb14/YuxiclPBnzQY1y55Y=; b=LBKXA5IYQNuVybEsA2txDYvQ69XO6JL9OY5950sjVJvqPZxrWw3IdEkCn+AD8BBEe5 2sK45iJTaQyMEOSXOSdH7L3wVccvDUgldxiqCiA3mNAqjwioVZl4IGPwD7f/rsFFzKvz Fhsv4fCCfKKe7SqOH5cNpbtoiqQaDa3GTeO9OVjyvo4HVy7uw/dhNLi7Rt3wc4aVvoEw U3QiQr1H4y4PDHN4V8WqPk7T2bcTEJdCZHbcnVTlSUcWK18BujEjk5vZ8mmXIGy50/ZG g2V4QvSj6eLAIfyuYjEKKegXNmBQHaoanhxlUzq1du0zZcwttOmkdbmKSRINZwQxmS4b CsBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id o11si12668575pgd.234.2018.12.11.09.21.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:50 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BDD56B010 for ; Tue, 11 Dec 2018 17:21:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 5EE6D1E0620; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 1/6] mm: migration: Factor out code to compute expected number of page references Date: Tue, 11 Dec 2018 18:21:38 +0100 Message-Id: <20181211172143.7358-2-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Factor out function to compute number of expected page references in migrate_page_move_mapping(). Note that we move hpage_nr_pages() and page_has_private() checks from under xas_lock_irq() however this is safe since we hold page lock. Signed-off-by: Jan Kara Acked-by: Mel Gorman --- mm/migrate.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index f7e4bfdc13b7..789c7bc90a0c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -428,6 +428,22 @@ static inline bool buffer_migrate_lock_buffers(struct buffer_head *head, } #endif /* CONFIG_BLOCK */ +static int expected_page_refs(struct page *page) +{ + int expected_count = 1; + + /* + * Device public or private pages have an extra refcount as they are + * ZONE_DEVICE pages. + */ + expected_count += is_device_private_page(page); + expected_count += is_device_public_page(page); + if (page->mapping) + expected_count += hpage_nr_pages(page) + page_has_private(page); + + return expected_count; +} + /* * Replace the page in the mapping. * @@ -444,14 +460,7 @@ int migrate_page_move_mapping(struct address_space *mapping, XA_STATE(xas, &mapping->i_pages, page_index(page)); struct zone *oldzone, *newzone; int dirty; - int expected_count = 1 + extra_count; - - /* - * Device public or private pages have an extra refcount as they are - * ZONE_DEVICE pages. - */ - expected_count += is_device_private_page(page); - expected_count += is_device_public_page(page); + int expected_count = expected_page_refs(page) + extra_count; if (!mapping) { /* Anonymous page without mapping */ @@ -471,8 +480,6 @@ int migrate_page_move_mapping(struct address_space *mapping, newzone = page_zone(newpage); xas_lock_irq(&xas); - - expected_count += hpage_nr_pages(page) + page_has_private(page); if (page_count(page) != expected_count || xas_load(&xas) != page) { xas_unlock_irq(&xas); return -EAGAIN; From patchwork Tue Dec 11 17:21:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C99113BF for ; Tue, 11 Dec 2018 17:22:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EEA82B553 for ; Tue, 11 Dec 2018 17:22:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A9A2B561; Tue, 11 Dec 2018 17:22:00 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE7B22B553 for ; Tue, 11 Dec 2018 17:21:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 668098E00B8; Tue, 11 Dec 2018 12:21:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1E5FA8E00B4; Tue, 11 Dec 2018 12:21:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBC1D8E00B5; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 93FE38E00B6 for ; Tue, 11 Dec 2018 12:21:51 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id c14so10998522pls.21 for ; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=xTWVXPZMynHyyB/Xpz095FuvdPrtjUfdZ8FU5/jeDNo=; b=hdi7HVy/+9y/sWwoTIKZghORrMStIYNWu6x6mSuTkB4LwPUY+87T/q1IOAzqBKhJOU O7YuXXn55rdMuuT9wE1QpjUKWI20qsBP0u4z+dmwwQJY1YrjgBvD9Jt7iAO/X9ZUHwfH huVTGA8H+fHaxGKaLBpAejw7SM5TolDXsEvmforqSXhxfhiC3eNCBsgBw9bzUSxEEh7v zLYDq7VprQSwK7Avixf4+oVi8g+0R0kvwLfurcMKicr1s7Zkc+nQMzNIF+V8BlBj9JDs wSjaqtIG1vrrOLvXP//EnTlNzd6RZkzFymO5WVwOHxck3J7U7hO9ZX9qHFD9aWPe3KTC IwiQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWY3UVOw63d/cTVwN1aYL1AzSPSpu6vGAI6soSKAJbb307e0BrOJ hMWp8Fg9C4FZyQSFZE1OlROwWKlYVWZNJ+gOfPwiqmrbLJ3TKvRd7wFPGJfO38oqcpJovbZmcGv vGGMzpjxbNAbw1k2egv9abjLAY7ix38Gn1Nh10lesCsQ7QOuij9yxoku0LLAWjmrn0g== X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr16456062plg.222.1544548911205; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/UAf3BK/tc36lcz2sSK/+bSgAaXk5y4SdbZlDrokOphEZ7okvcLvCTTztSrDOic2BK73ohr X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr16456010plg.222.1544548910376; Tue, 11 Dec 2018 09:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548910; cv=none; d=google.com; s=arc-20160816; b=Ie0c9F4nyLETzRr8O3L5VhdgDUbW0qybZgauMsGiKHh/2MSPld/UCjgDwqfWFESWqY iF8ccvobyeuzomKecVohZL0Po5L327hTcqoqSI5N/CGhd6DGqLWAShFA71Cy3zbpPpRr yWMqmzRx2uArzSsart9tiU/hKUSZtYD6Z1hYNmhR3JFiOKMFTrdgza+KfWOlfU96mOXm igJlqRCMGiY6nqap2tLy/PoytxhAMnLrP+vTVqJT4o5aIq7yqb7mpGsy16AjtvHCF4Ks 2Qga2i5QR6NDfGNeZPCkfEEbgc/wpKIDRt6uO0hIHx/WrnZo0N+gUg1kPltyIX+eS+6v +4DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=xTWVXPZMynHyyB/Xpz095FuvdPrtjUfdZ8FU5/jeDNo=; b=DoGB3uX3sQllZdlRCV9RxP+NHOCii7WO2oFC5ZLWfbILgR0Vt/Gka/iqnFtqP+Xh/c P72R8/pVwrkTqDOVp9jvi0JvLKRXTL6NcEaivxdKgh4zDBVIU6iAt5wkT0xzN7AsTmmB 582hXCodZzNT+BjobyN+aF3BKxWiJFxBzrxY0SK1wLi+ojuK6+vlGh9M3HXnWK+JTHvT xtmhatoTHL2Bfqv4a19pBYoIDgLkJ4jR3f1340tNe6W5DJtM8KKFQnAL34qh8OhiL+zK ygYnVt7NfPLDB+EPcQpzQblwsG758Rv7GL7A7nYkQvxoKV58tLceyKEj+RmI6eBrX0ZK zuWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id j21si12437231pll.150.2018.12.11.09.21.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:50 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BE8E6B012 for ; Tue, 11 Dec 2018 17:21:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 62A201E140E; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 2/6] mm: migrate: Lock buffers before migrate_page_move_mapping() Date: Tue, 11 Dec 2018 18:21:39 +0100 Message-Id: <20181211172143.7358-3-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Lock buffers before calling into migrate_page_move_mapping() so that that function doesn't have to know about buffers (which is somewhat unexpected anyway) and all the buffer head logic is in buffer_migrate_page(). Signed-off-by: Jan Kara Acked-by: Mel Gorman --- mm/migrate.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 789c7bc90a0c..d58a8ecf275e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -490,20 +490,6 @@ int migrate_page_move_mapping(struct address_space *mapping, return -EAGAIN; } - /* - * In the async migration case of moving a page with buffers, lock the - * buffers using trylock before the mapping is moved. If the mapping - * was moved, we later failed to lock the buffers and could not move - * the mapping back due to an elevated page count, we would have to - * block waiting on other references to be dropped. - */ - if (mode == MIGRATE_ASYNC && head && - !buffer_migrate_lock_buffers(head, mode)) { - page_ref_unfreeze(page, expected_count); - xas_unlock_irq(&xas); - return -EAGAIN; - } - /* * Now we know that no one else is looking at the page: * no turning back from here. @@ -779,24 +765,23 @@ int buffer_migrate_page(struct address_space *mapping, { struct buffer_head *bh, *head; int rc; + int expected_count; if (!page_has_buffers(page)) return migrate_page(mapping, newpage, page, mode); - head = page_buffers(page); + /* Check whether page does not have extra refs before we do more work */ + expected_count = expected_page_refs(page); + if (page_count(page) != expected_count) + return -EAGAIN; - rc = migrate_page_move_mapping(mapping, newpage, page, head, mode, 0); + head = page_buffers(page); + if (!buffer_migrate_lock_buffers(head, mode)) + return -EAGAIN; + rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); if (rc != MIGRATEPAGE_SUCCESS) - return rc; - - /* - * In the async case, migrate_page_move_mapping locked the buffers - * with an IRQ-safe spinlock held. In the sync case, the buffers - * need to be locked now - */ - if (mode != MIGRATE_ASYNC) - BUG_ON(!buffer_migrate_lock_buffers(head, mode)); + goto unlock_buffers; ClearPagePrivate(page); set_page_private(newpage, page_private(page)); @@ -818,6 +803,8 @@ int buffer_migrate_page(struct address_space *mapping, else migrate_page_states(newpage, page); + rc = MIGRATEPAGE_SUCCESS; +unlock_buffers: bh = head; do { unlock_buffer(bh); @@ -826,7 +813,7 @@ int buffer_migrate_page(struct address_space *mapping, } while (bh != head); - return MIGRATEPAGE_SUCCESS; + return rc; } EXPORT_SYMBOL(buffer_migrate_page); #endif From patchwork Tue Dec 11 17:21:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B365513BF for ; Tue, 11 Dec 2018 17:21:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 926D62B553 for ; Tue, 11 Dec 2018 17:21:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80D202B561; Tue, 11 Dec 2018 17:21:57 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 072052B553 for ; Tue, 11 Dec 2018 17:21:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 283708E0095; Tue, 11 Dec 2018 12:21:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2C058E00B9; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB5DE8E00B4; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 76CA18E00B5 for ; Tue, 11 Dec 2018 12:21:51 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id o17so10254965pgi.14 for ; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=UfYxUWZATmiK33K0DvyU9w5Yf3Ak1Oi/0SQl74QEL7c=; b=hYy4i/Ko0MgIEuIypIbOEYfgTYn1ki5/WnGZvaT8wK+LSsN44+UBawzJapsFVB/4qN d4QmQ7Rja4Cwd2z2qqrWADlyCI2AGQs3uFq9L5Yl8WsvpZoux71bRyqMnAYxoTSyAYg8 BYBEuCQZlHI6b8sz5nOs30Y6sfB7pN1VfV5ZKoq1yW6LQuDzABIxVA/F+//sNd7hL7cP JBkbOTTCkPX//EANLFXQAqutJUqlhsl8/NxXt1wtrGvekr9XKVq9b5IG5GJJG1dKuiZN LCC0B1Gu0a5PMyl01i4CpjIVhXJTEq9Nrp1Cmy4xN8SRt5dn9wxbJMKgTC2tH/aAGzMz OBrw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWZex4R/z2/vh/JbdkLI65NHEGaXP9SavzF6zx/P1316Nk+13Jq3 RSwsbgjBeFtg7AW8h2QVlVYcnT6nRmOQ1IefF0Mk4CkFGqM5E10B25V+4MwtFrEv/wc+3qQQkz6 zcKg/1QsXzyR3OPk+eKOSIWM9Fo2Pl/2NH0b71VrSNfukUP++FkWsREIGihCHNqL51w== X-Received: by 2002:a17:902:128c:: with SMTP id g12mr16050745pla.146.1544548911096; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/WxWPNf6RG/ZV7WElUYBKs2O++Jlx+VO7z2eL65Dch4noQaC8Y9t8Jh8vuEk8sAjjl0qYcW X-Received: by 2002:a17:902:128c:: with SMTP id g12mr16050706pla.146.1544548910365; Tue, 11 Dec 2018 09:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548910; cv=none; d=google.com; s=arc-20160816; b=Pbx6qvU1ozNVSJ8abaUUfVnb9d+xAlSeqjkuzjec3ZaxTJzLhAfd/4EUzze+FWYe11 yUwQeCsWG3mLgRAm1MVhJ1gJofeyrb6hAErFi2Yn2AmXyGnGKkr82pqRtjSVBxaW1lj5 j7PEh28PTPUXyiN1CEMK5xGZ+kMfUvWWvqeuaBMnSc0YlFEHASZI4Q6nWK0bWmCfRrc4 IVpcL8ohd37NiuZRoTQLwxannUw+YUcNUm9SOMpNLe0XTSnmRl2eojhBqBkpSMGMHAAf eJzM1yItVxP8rUtWtsan2SgJCAIY8e08gd9J9CvMwRNR3ysXDbVaKdnJjuRDxJCevlD0 eKNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=UfYxUWZATmiK33K0DvyU9w5Yf3Ak1Oi/0SQl74QEL7c=; b=yrMhXF5VgR/uCfg3LPhsMAzqF2ZcFBm1O3fZXLFquJQsVs5Gr1I6ISfFfcPpyOjBV2 XfjZrjQ16XyiszIPCb+r1TuuP51kYuYCXmjUVLy4/fHyCA1S5jZjieyBKiTqZl2mZ3AB oF/O3s5VJfnle9b6fDAyNfVJpBlfqNYxue5IktmNo51eoOhvwWLHF688+tpqMei8lXbd Ydh34JfsMGw1iV1kjoFO9l3gehsS/6BLUTTOoUOYmBHgokL6rls9i0KBG811z/h0prCF QVG/HBUipV1EW47Dflht436xgUsKk8cG16DvvNKKbhK8AUQRcYGeacyGoL+dPjZjqpsH XoQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id i4si13505633pfg.218.2018.12.11.09.21.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:50 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C0290B017 for ; Tue, 11 Dec 2018 17:21:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 66F7A1E1412; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 3/6] mm: migrate: Move migrate_page_lock_buffers() Date: Tue, 11 Dec 2018 18:21:40 +0100 Message-Id: <20181211172143.7358-4-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP buffer_migrate_page() is the only caller of migrate_page_lock_buffers() move it close to it and also drop the now unused stub for !CONFIG_BLOCK. Signed-off-by: Jan Kara Acked-by: Mel Gorman --- mm/migrate.c | 92 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index d58a8ecf275e..f8df1ad6e7cf 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -378,56 +378,6 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd_t *pmd) } #endif -#ifdef CONFIG_BLOCK -/* Returns true if all buffers are successfully locked */ -static bool buffer_migrate_lock_buffers(struct buffer_head *head, - enum migrate_mode mode) -{ - struct buffer_head *bh = head; - - /* Simple case, sync compaction */ - if (mode != MIGRATE_ASYNC) { - do { - get_bh(bh); - lock_buffer(bh); - bh = bh->b_this_page; - - } while (bh != head); - - return true; - } - - /* async case, we cannot block on lock_buffer so use trylock_buffer */ - do { - get_bh(bh); - if (!trylock_buffer(bh)) { - /* - * We failed to lock the buffer and cannot stall in - * async migration. Release the taken locks - */ - struct buffer_head *failed_bh = bh; - put_bh(failed_bh); - bh = head; - while (bh != failed_bh) { - unlock_buffer(bh); - put_bh(bh); - bh = bh->b_this_page; - } - return false; - } - - bh = bh->b_this_page; - } while (bh != head); - return true; -} -#else -static inline bool buffer_migrate_lock_buffers(struct buffer_head *head, - enum migrate_mode mode) -{ - return true; -} -#endif /* CONFIG_BLOCK */ - static int expected_page_refs(struct page *page) { int expected_count = 1; @@ -755,6 +705,48 @@ int migrate_page(struct address_space *mapping, EXPORT_SYMBOL(migrate_page); #ifdef CONFIG_BLOCK +/* Returns true if all buffers are successfully locked */ +static bool buffer_migrate_lock_buffers(struct buffer_head *head, + enum migrate_mode mode) +{ + struct buffer_head *bh = head; + + /* Simple case, sync compaction */ + if (mode != MIGRATE_ASYNC) { + do { + get_bh(bh); + lock_buffer(bh); + bh = bh->b_this_page; + + } while (bh != head); + + return true; + } + + /* async case, we cannot block on lock_buffer so use trylock_buffer */ + do { + get_bh(bh); + if (!trylock_buffer(bh)) { + /* + * We failed to lock the buffer and cannot stall in + * async migration. Release the taken locks + */ + struct buffer_head *failed_bh = bh; + put_bh(failed_bh); + bh = head; + while (bh != failed_bh) { + unlock_buffer(bh); + put_bh(bh); + bh = bh->b_this_page; + } + return false; + } + + bh = bh->b_this_page; + } while (bh != head); + return true; +} + /* * Migration function for pages with buffers. This function can only be used * if the underlying filesystem guarantees that no other references to "page" From patchwork Tue Dec 11 17:21:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF34A13BF for ; Tue, 11 Dec 2018 17:22:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A16232B553 for ; Tue, 11 Dec 2018 17:22:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95F152B561; Tue, 11 Dec 2018 17:22:03 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 279D32B553 for ; Tue, 11 Dec 2018 17:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BC618E00B4; Tue, 11 Dec 2018 12:21:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C3E88E00B5; Tue, 11 Dec 2018 12:21:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0385A8E00BA; Tue, 11 Dec 2018 12:21:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 9AB808E00B8 for ; Tue, 11 Dec 2018 12:21:51 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id b24so6931357pls.11 for ; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=mPWGpmOK7whuIEeXcPbpeRb1vJRiyG4ocRe4rWqTPSk=; b=t5282N6gPc0qsqBrR0Hn05bnM2YxMVT/N4mHRO4zmdP/YneZnRAbD6kd4cgF7qVkng ZMBr3QCLAsa3FPoF0jT+Qld5E9PQthdnQlYQrkQD+9zFv5M8TQX31VRKs/n8rtMut0ti 0nfW9cL28/83VMi62mFQwyPzZMp9rYvCX6KKj1kZyWoLimyO8Uh19ZwhTPThWdPuhnR+ VzCLy2T/j9ASvsRyyY4I1XbxgeHM/cdPui8VVfKGPLVnlxlKEtj47DmQFDGAEvyvFp/i G+81Ck2s+apYp/8zDW7YXGsnh8tgRu0jIRE8zDu+T0Ev3a61ZERm62MbJXaF8OfDJT44 ohrw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWZbUKj6pq/nCkYZAK3qhmyoo1gETYgUCfpUgnQJ9uVmk64wxd6y bHSMK0mOj8BNSzY1SRwQNbtN0cRnpqzc/Rv2htRcS5guNPBnWBHfabnYEatWYvTgEZYNUNtKm4Z LQUI1fAGfm2lF5xsyVk1XKNe5t7ZMMcP0lrtwOazU5jM2e2uidKb/rtYwqELqqjPPbQ== X-Received: by 2002:a62:6204:: with SMTP id w4mr17284252pfb.5.1544548911298; Tue, 11 Dec 2018 09:21:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/WIor4Z/nUGqkaJeLvY+M0QuoDJ7mdu0n6gY9DM2j8U5GTBhTE3XLC6+/SseMrkKJ1z7Vd1 X-Received: by 2002:a62:6204:: with SMTP id w4mr17284214pfb.5.1544548910543; Tue, 11 Dec 2018 09:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548910; cv=none; d=google.com; s=arc-20160816; b=ZZOoyDoLBLMOhQVYMYFjQjwAa4cLZ8LYahxm2mNFNP1i4RLIr/fUWF4P0EelPOc0zv PXHo2PAw9fCkqWCp1P4rJ88MQwONFfCPRrc1bJSsNINsAOPOKIEuFX3aEd3SaYko22kL 151qrSJxjN7Hnex0fJgBCTvPUX7hb9RjdtT00uR9esJZzhtWiH/6keaBCJDJzADrC1Wv 9COC1Fx3g5ZZ9BJytqLR2miTvV/c9AGWKmOz/yad9380OB0MiTH92akA0oKV+uozJPr9 C5qX8/rlnwMC9KtSkqQuFyH0WjMAt9eU2TmjSngpmr2e18c5cxfi8hWZyooL2ZJ03wj7 foRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=mPWGpmOK7whuIEeXcPbpeRb1vJRiyG4ocRe4rWqTPSk=; b=JQLjmJDzJ2rkNLDcNQolql5FtAIVNSc4fq/IoIkz5IarmSakpsZVqNxXDZ9hhjhg3W Ixe8vuR+jUIBT/11fgCwhmraksOMcpVPXs77aCDDYD6n2Y51HTa5LIpD/qdQaZ29AY27 ElP0e6B300cX4vOpaGqiCi7zZ3RUJdKRhNHGBi00FQBpVTKe3DZOCe66ulmmUeMU6/bR 6phXGQ5T5mlp82UE7aGnCg6wefqwnj7ZRE0Dm/aOshhk2OYzYwXZcfUd3eFElN3FQuVZ JkGbsSCiVMLMaPQj913sED0oS4UekgAzlSWoO+/FIG0sV7YUeg5qH258qaDnw+uA7bh7 khLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id a17si13329103pfn.213.2018.12.11.09.21.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:50 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D6DF5B029 for ; Tue, 11 Dec 2018 17:21:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6AB161E141C; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 4/6] mm: migrate: Provide buffer_migrate_page_norefs() Date: Tue, 11 Dec 2018 18:21:41 +0100 Message-Id: <20181211172143.7358-5-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Provide a variant of buffer_migrate_page() that also checks whether there are no unexpected references to buffer heads. This function will then be safe to use for block device pages. Signed-off-by: Jan Kara Acked-by: Mel Gorman --- include/linux/fs.h | 4 ++++ mm/migrate.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index c95c0807471f..4bb1a8b65474 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3264,8 +3264,12 @@ extern int generic_check_addressable(unsigned, u64); extern int buffer_migrate_page(struct address_space *, struct page *, struct page *, enum migrate_mode); +extern int buffer_migrate_page_norefs(struct address_space *, + struct page *, struct page *, + enum migrate_mode); #else #define buffer_migrate_page NULL +#define buffer_migrate_page_norefs NULL #endif extern int setattr_prepare(struct dentry *, struct iattr *); diff --git a/mm/migrate.c b/mm/migrate.c index f8df1ad6e7cf..c4075d5ec073 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -747,13 +747,9 @@ static bool buffer_migrate_lock_buffers(struct buffer_head *head, return true; } -/* - * Migration function for pages with buffers. This function can only be used - * if the underlying filesystem guarantees that no other references to "page" - * exist. - */ -int buffer_migrate_page(struct address_space *mapping, - struct page *newpage, struct page *page, enum migrate_mode mode) +static int __buffer_migrate_page(struct address_space *mapping, + struct page *newpage, struct page *page, enum migrate_mode mode, + bool check_refs) { struct buffer_head *bh, *head; int rc; @@ -771,6 +767,33 @@ int buffer_migrate_page(struct address_space *mapping, if (!buffer_migrate_lock_buffers(head, mode)) return -EAGAIN; + if (check_refs) { + bool busy; + bool invalidated = false; + +recheck_buffers: + busy = false; + spin_lock(&mapping->private_lock); + bh = head; + do { + if (atomic_read(&bh->b_count)) { + busy = true; + break; + } + bh = bh->b_this_page; + } while (bh != head); + spin_unlock(&mapping->private_lock); + if (busy) { + if (invalidated) { + rc = -EAGAIN; + goto unlock_buffers; + } + invalidate_bh_lrus(); + invalidated = true; + goto recheck_buffers; + } + } + rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); if (rc != MIGRATEPAGE_SUCCESS) goto unlock_buffers; @@ -807,7 +830,31 @@ int buffer_migrate_page(struct address_space *mapping, return rc; } + +/* + * Migration function for pages with buffers. This function can only be used + * if the underlying filesystem guarantees that no other references to "page" + * exist. For example attached buffer heads are accessed only under page lock. + */ +int buffer_migrate_page(struct address_space *mapping, + struct page *newpage, struct page *page, enum migrate_mode mode) +{ + return __buffer_migrate_page(mapping, newpage, page, mode, false); +} EXPORT_SYMBOL(buffer_migrate_page); + +/* + * Same as above except that this variant is more careful and checks that there + * are also no buffer head references. This function is the right one for + * mappings where buffer heads are directly looked up and referenced (such as + * block device mappings). + */ +int buffer_migrate_page_norefs(struct address_space *mapping, + struct page *newpage, struct page *page, enum migrate_mode mode) +{ + return __buffer_migrate_page(mapping, newpage, page, mode, true); +} +EXPORT_SYMBOL(buffer_migrate_page_norefs); #endif /* From patchwork Tue Dec 11 17:21:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8AEB112E for ; Tue, 11 Dec 2018 17:22:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB2B72B553 for ; Tue, 11 Dec 2018 17:22:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF74C2B561; Tue, 11 Dec 2018 17:22:09 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F83C2B553 for ; Tue, 11 Dec 2018 17:22:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D92318E00B5; Tue, 11 Dec 2018 12:21:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CEB348E00BB; Tue, 11 Dec 2018 12:21:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3AA18E00B9; Tue, 11 Dec 2018 12:21:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 709188E00B9 for ; Tue, 11 Dec 2018 12:21:53 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id p4so10234182pgj.21 for ; Tue, 11 Dec 2018 09:21:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=iRZMppqwLvoaloO//8PuSrRyXk2LsEtimnejpJVSEh8=; b=lXpM8KP5RmMurQqz9QAhgxgaQD17eMnK3zH8/qGaiym0Uz93NxMrHbM4L62BJOU3Mm gTCcksoYUrTVM5gm1/ObWdhd8zbTOhuWKCnAk/trvS/WS249vakeej2yR/41U48Icmq+ ZZs5yjXh4yyYXBkDJub6U5A/AQX8dwnZ9Pj2dhGMaEWDXBUhV/MaOBklbr7kkfHELl+X LZ6CHM/mjMM9OJ8m95ouHpoApvatSTG66McZknzZdYXee6ZL2lKGA25z3C4wyaaWtcWg uqNuJYgJwNLJTnsTobAIwJoxY/ilda1i9jUplcIyI05Z6mXRpSlNndItKGl6va3xMoNl 9kUQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWYRqQigvb8VVB4Tc+0iYi5uQ5I2rgtfxwve/E6/8FtAhyIZuQZW vKJq0AOVG+9+bI77JOAdpEz3UtS7GZKzyATbGcHKgi/+N4hYJj1lfVlAA9htwdsAbP0TVhKPFkD ljP1RJRxGCB1tpNSn5yfEzXqIvsbsoa9/bXVY1rgqlr3WAylv35z9QsB5NPfxbPsx/A== X-Received: by 2002:a63:9501:: with SMTP id p1mr15492651pgd.149.1544548913084; Tue, 11 Dec 2018 09:21:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vsa2qRuqpy/6wgW3gvoZZCrsWbaqrXldND08WlYqQAxzN6FcWzsvxI4CEevY0SWcOi1aj1 X-Received: by 2002:a63:9501:: with SMTP id p1mr15492582pgd.149.1544548911832; Tue, 11 Dec 2018 09:21:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548911; cv=none; d=google.com; s=arc-20160816; b=pBmUox2Xcff70H9/IdUH97dINZSrYudn14Oe06b3U3XRumz7EPH8lvZ/sIFnVuSgRF QJLhiSXzgfokpTDYlWFJ69U35YxI5Q/N/jS/wa58VzUfjRs6w5CvnEXo9xFEG2Izhf9V wZWlGbP62WvOutSId5NQIn/el4jSM6YPtur+LfTlx/PJeZxHl/i9BXtTFPb/Ff+1VkBF zszDL+XafCb/3bCtYpcZJDVb7tBu9ATcM/dS3a4LnsIj0Z0XbePEPFa2p97d3XEmGcjo ozyHH1x/yJ7Ohu535PTMx8op8+iWW3mZZmWniGl6DwY25AF6fn1HEY9z7LCdIleYvkwi hhwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=iRZMppqwLvoaloO//8PuSrRyXk2LsEtimnejpJVSEh8=; b=poFb8WlwXnKqYIJ63O8F5m8uEQswlqsqo1cnRxO+BUbenAIhx7DX+59CcMd1bRqe5X f9gVQ/mie2ZNi6SZKHbm/T5L2LTpdFW3w2UcMvqS01A5TZq5K3S/P9suL2nKaJnQAEgI 7cpWMKz+CT5PLAR2RnsN8W+vYkEyvjnJLyt6RrML2ToNER23+/PUqMVePUC+mR2GEUz8 tzRtu7Up861x3SUjETUuvJ+Ah6pPLhNk5r2fZKFvRpu5vDuehiJCzuHqsInfoeH1a3Eq DdZlsb6SJ7saUCVJeqkhs7Euj2o8dRxMtzJ1Nd/DG0qWCzqZrum4G0Dq6ypuonpj0FX9 bXsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id b36si6875828pgl.596.2018.12.11.09.21.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2544DB063 for ; Tue, 11 Dec 2018 17:21:49 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6DB921E1424; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 5/6] blkdev: Avoid migration stalls for blkdev pages Date: Tue, 11 Dec 2018 18:21:42 +0100 Message-Id: <20181211172143.7358-6-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently, block device pages don't provide a ->migratepage callback and thus fallback_migrate_page() is used for them. This handler cannot deal with dirty pages in async mode and also with the case a buffer head is in the LRU buffer head cache (as it has elevated b_count). Thus such page can block memory offlining. Fix the problem by using buffer_migrate_page_norefs() for migrating block device pages. That function takes care of dropping bh LRU in case migration would fail due to elevated buffer refcount to avoid stalls and can also migrate dirty pages without writing them. Signed-off-by: Jan Kara Acked-by: Mel Gorman --- fs/block_dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/block_dev.c b/fs/block_dev.c index a80b4f0ee7c4..de2135178e62 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1966,6 +1966,7 @@ static const struct address_space_operations def_blk_aops = { .writepages = blkdev_writepages, .releasepage = blkdev_releasepage, .direct_IO = blkdev_direct_IO, + .migratepage = buffer_migrate_page_norefs, .is_dirty_writeback = buffer_check_dirty_writeback, }; From patchwork Tue Dec 11 17:21:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10724269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B594C112E for ; Tue, 11 Dec 2018 17:22:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9724A2B553 for ; Tue, 11 Dec 2018 17:22:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B7622B561; Tue, 11 Dec 2018 17:22:06 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EF3E2B553 for ; Tue, 11 Dec 2018 17:22:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7BBA8E00BA; Tue, 11 Dec 2018 12:21:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0858E00B5; Tue, 11 Dec 2018 12:21:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8512D8E00BA; Tue, 11 Dec 2018 12:21:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 360728E00B5 for ; Tue, 11 Dec 2018 12:21:53 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id b24so6931420pls.11 for ; Tue, 11 Dec 2018 09:21:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=INRYCEL6vCtvMfVy1XV6+7WZ8+Bl536OsWF1QZwcibU=; b=cBHlpNi1Y76j/cR7x9g2fnkj+P2ir8dV7C7AHzaRukDfZxhOtw8jfEVpvNsql6yEIc 7ulxzgMn2/3gDQbiNzUSDo8w8cQlA8riOY5n57fY44U8u7L9gEAcc+t2+c+/FvOn/SJt jxpoDxL+2S/xoDJCh/m5xQKEwbC25zG8lT5xQCjJpCqklrVL9uOdlg4LP0OLCrLhnNtw PgpWUsXj9RynMDF98L4cIQd/YmSHgJM45xBJ11ppFFxXieasb5mYhXKfITYg6M5VUpUy RJqujrmg2aQleJTEmnX/IMTjz/7guCoAfNkEp6AEikG3iLgNqYQO4rvfJ6UC0hZ4/zFE vL1A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Gm-Message-State: AA+aEWbiWjopHwGOapbLilxrOO9POK5qO8v9MfeiKeAcfgIK7Em2/nGs +/mdT4OCUJlwKwS8uNCraUjgLar4D6+NliJ8JygfRmDsdQ14vGs8ZHOECS8ke6pEMDY44pbWz5s s/6sNSn3zRzsgSvTUP5G5i/gr9HIu30BA8KCQ/Gv0MQboYOiOjoSbuJih0uUMKZcRuA== X-Received: by 2002:a62:2b8b:: with SMTP id r133mr17098017pfr.246.1544548912862; Tue, 11 Dec 2018 09:21:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKtK1kde+VtQlhJtBBIK9cpwpDWowjttKn30e3qdrIpm4Hdvd+gVl3EhRzp4lud5PhOIU+ X-Received: by 2002:a62:2b8b:: with SMTP id r133mr17097965pfr.246.1544548911995; Tue, 11 Dec 2018 09:21:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548911; cv=none; d=google.com; s=arc-20160816; b=zgxY0VN+DNn3U59yIEjZyVANqbdGuTYkJHjVwcvU1F1ysFJmWJxQiC+hDqrrK40tE0 rHy6Sn4EWiUO/ZCXpS4i4e5+T79XbaNMMEPQDLnQibwsENtmW3XfFUzFw6EY8ipZYvOk zvMDZLbJwXcM+mqSLCsU5iqf6NqHKdCQxgenf8QRd4HioGqljLhygEY9RaAzsRERoNi0 Rbwk5o83mVniAbS2eHWivxLHMf6AZRzM8YGft/RQ1echZKwbYGhyTcltUgI27fJyw4oj Hey4ygn4nKzMOqd1FkfGyUQsnO7MgqS1CaxvrXpEL+9FF3LUnUelkwew0OFQLqv+dL5m 86og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=INRYCEL6vCtvMfVy1XV6+7WZ8+Bl536OsWF1QZwcibU=; b=IzxgreHGly++3rMz/o3XtlpNsYWSRQYorGpxC2pfk+9MaWZSLA6MuN4uxFU+IUR3KK FfwjPRmxu5DzDNrzLPven0BTSvYUEe+VpZ/3jl9iFSVqj8a/clO8wOTRAhobNXfRk7ZI 5b4LfHzXGGYSyB6vL7ti6HsjIoedPQNiH4GuH55IBf9XiEJ4l1J5HeGFRipgjcWkpZtI DT8ys7psOoRvFFwFLuckLRjpLWM9aSZv3rKmoeAtaXs4m/nZi5YiNFGE4iVqwrDWFSdW ejV7kEQeQR6VS5UWUrHa4hIfLNuH75JsobmDZZwQhkgyBg8tsqE/Uta0T7hvL4/k0IQ4 QLjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id m64si14303764pfb.224.2018.12.11.09.21.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 09:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 21733B042 for ; Tue, 11 Dec 2018 17:21:49 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 710631E1430; Tue, 11 Dec 2018 18:21:48 +0100 (CET) From: Jan Kara To: Cc: mhocko@suse.cz, mgorman@suse.de, Jan Kara Subject: [PATCH 6/6] mm: migrate: Drop unused argument of migrate_page_move_mapping() Date: Tue, 11 Dec 2018 18:21:43 +0100 Message-Id: <20181211172143.7358-7-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181211172143.7358-1-jack@suse.cz> References: <20181211172143.7358-1-jack@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP All callers of migrate_page_move_mapping() now pass NULL for 'head' argument. Drop it. Signed-off-by: Jan Kara Acked-by: Mel Gorman --- fs/aio.c | 2 +- fs/f2fs/data.c | 2 +- fs/iomap.c | 2 +- fs/ubifs/file.c | 2 +- include/linux/migrate.h | 3 +-- mm/migrate.c | 7 +++---- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 97f983592925..4f4878ebca9a 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -408,7 +408,7 @@ static int aio_migratepage(struct address_space *mapping, struct page *new, BUG_ON(PageWriteback(old)); get_page(new); - rc = migrate_page_move_mapping(mapping, new, old, NULL, mode, 1); + rc = migrate_page_move_mapping(mapping, new, old, mode, 1); if (rc != MIGRATEPAGE_SUCCESS) { put_page(new); goto out_unlock; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b293cb3e27a2..008b74eff00d 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2738,7 +2738,7 @@ int f2fs_migrate_page(struct address_space *mapping, */ extra_count = (atomic_written ? 1 : 0) - page_has_private(page); rc = migrate_page_move_mapping(mapping, newpage, - page, NULL, mode, extra_count); + page, mode, extra_count); if (rc != MIGRATEPAGE_SUCCESS) { if (atomic_written) mutex_unlock(&fi->inmem_lock); diff --git a/fs/iomap.c b/fs/iomap.c index 3ffb776fbebe..8df6a75d2d11 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -550,7 +550,7 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage, { int ret; - ret = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); + ret = migrate_page_move_mapping(mapping, newpage, page, mode, 0); if (ret != MIGRATEPAGE_SUCCESS) return ret; diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 1b78f2e09218..5d2ffb1a45fc 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1481,7 +1481,7 @@ static int ubifs_migrate_page(struct address_space *mapping, { int rc; - rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); + rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); if (rc != MIGRATEPAGE_SUCCESS) return rc; diff --git a/include/linux/migrate.h b/include/linux/migrate.h index f2b4abbca55e..8eeeaf946f95 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -77,8 +77,7 @@ extern void migrate_page_copy(struct page *newpage, struct page *page); extern int migrate_huge_page_move_mapping(struct address_space *mapping, struct page *newpage, struct page *page); extern int migrate_page_move_mapping(struct address_space *mapping, - struct page *newpage, struct page *page, - struct buffer_head *head, enum migrate_mode mode, + struct page *newpage, struct page *page, enum migrate_mode mode, int extra_count); #else diff --git a/mm/migrate.c b/mm/migrate.c index c4075d5ec073..1e47ea88a5b3 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -403,8 +403,7 @@ static int expected_page_refs(struct page *page) * 3 for pages with a mapping and PagePrivate/PagePrivate2 set. */ int migrate_page_move_mapping(struct address_space *mapping, - struct page *newpage, struct page *page, - struct buffer_head *head, enum migrate_mode mode, + struct page *newpage, struct page *page, enum migrate_mode mode, int extra_count) { XA_STATE(xas, &mapping->i_pages, page_index(page)); @@ -691,7 +690,7 @@ int migrate_page(struct address_space *mapping, BUG_ON(PageWriteback(page)); /* Writeback must be complete */ - rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); + rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); if (rc != MIGRATEPAGE_SUCCESS) return rc; @@ -794,7 +793,7 @@ static int __buffer_migrate_page(struct address_space *mapping, } } - rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); + rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); if (rc != MIGRATEPAGE_SUCCESS) goto unlock_buffers;