Received: by 10.213.65.68 with SMTP id h4csp358511imn; Tue, 13 Mar 2018 06:42:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELsgVh/Ifucvg9/SSIh9CpppXELtsdbrYvnvkAi4wrnSRNnnukpQBxtFamK78cyOUhpNy9VL X-Received: by 2002:a17:902:9a08:: with SMTP id v8-v6mr643929plp.252.1520948551172; Tue, 13 Mar 2018 06:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520948551; cv=none; d=google.com; s=arc-20160816; b=Y2mesYEFlrcEvkUK43huJLuqW6tVDAMrOk9e49zHXRNJAal7oNCIOyyWr1F/6ng2/G a+jDPEtM6G/FDE9pbk7ELg+GvxLqizQhInOJuSwClwkIkGUrGYBYbVSJ60arKe5dRmpj o/8fVvAt2qEvH8S3oBpLTNFDbiQHJ5ARycl6WE+nC97+hrXHv2cBzRgCTKbbu9bq62jk 2mEc2rhq4WWBSGVerbte1J/kZJSp85HWG7cC40fE5z1ut/2/DsRBPHdzrjokl5pt72qS LJM5vwZRgOs0m0r6iS/+F8LqVX0dj5fiMkwvdgnZgQ6mIxvorxYUYri0tcA5AuIU1Cny UEsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ZP49aq269tFFqpyGMczz8ZSYS9wJPmYPFVNznUUKnms=; b=XFvZxWXpZg6WBUJshsNjHsMewwXfb2y3CsFOwqvmjOIyZuzfHzovVL7M/kk+QRmvgP XwaP7St2inXuHW2g1/iC+4QqjCKQGdNL3IwfD4IaYp3+Uq0rreEt8q+WLGSpIOvKCECm ktSy9do0i7yVZ2YiOOJZMCLYzdLGbyeXwSrn2zXszWkXceAz441IeCBpHAaL00IffhM1 b6RiQxxDVM5VvD4sxA+UluGjepFYl5lI8/JiKEVIgrDhYvpF+D4FrbDbMPNAd78L6UbA 5SGR/y35SgDSZ+ZHYXlb+EDO6MHNqLOk51B3O7J8P8D1/3oXB5+FY6y6kf4mAaEsS6Q6 RzcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=quuMjzdd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4si118569pgd.339.2018.03.13.06.42.16; Tue, 13 Mar 2018 06:42:31 -0700 (PDT) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=quuMjzdd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932734AbeCMNkj (ORCPT + 99 others); Tue, 13 Mar 2018 09:40:39 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35376 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932520AbeCMN07 (ORCPT ); Tue, 13 Mar 2018 09:26:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZP49aq269tFFqpyGMczz8ZSYS9wJPmYPFVNznUUKnms=; b=quuMjzddJh3CvK/i+VkdWSe9Z UilGsfjJoopdWVpx5Exom/YrOMx1cQ3IHtfgTf7gvjCJKoxZwbHlr9IkEKofXwbTR7tY8g0cdIylS ijlN0zy+HOCYwEdLdZEweRqLTtBkKbzfGyyeUAXMlpisY/CUiDLUxb5SIVZcxI4raErPLPN1IIgEt 5gk816xuJ2r0Fd8a/F6+NoHQz6mVzNUn22C/I21krWdXQ2sE8YtrmioGHmB88tkqYOmKjp51u++cg Z53gKv859GBW6s1GepWXtYfO6a8j6EEx2g+AFrf5atk91S/8HcVkFeS0QCtn2gGgGMGXdznBeRUlH 3Rhn2CNzw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1evjxC-0004iF-Co; Tue, 13 Mar 2018 13:26:58 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v9 38/61] mm: Convert page migration to XArray Date: Tue, 13 Mar 2018 06:26:16 -0700 Message-Id: <20180313132639.17387-39-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313132639.17387-1-willy@infradead.org> References: <20180313132639.17387-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Signed-off-by: Matthew Wilcox --- mm/migrate.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 740b71857898..9a15d27768a0 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -322,7 +322,7 @@ void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, page = migration_entry_to_page(entry); /* - * Once radix-tree replacement of page migration started, page_count + * Once page cache replacement of page migration started, page_count * *must* be zero. And, we don't want to call wait_on_page_locked() * against a page without get_page(). * So, we use get_page_unless_zero(), here. Even failed, page fault @@ -437,10 +437,10 @@ int migrate_page_move_mapping(struct address_space *mapping, struct buffer_head *head, enum migrate_mode mode, int extra_count) { + XA_STATE(xas, &mapping->i_pages, page_index(page)); struct zone *oldzone, *newzone; int dirty; int expected_count = 1 + extra_count; - void **pslot; /* * Device public or private pages have an extra refcount as they are @@ -466,21 +466,16 @@ int migrate_page_move_mapping(struct address_space *mapping, oldzone = page_zone(page); newzone = page_zone(newpage); - xa_lock_irq(&mapping->i_pages); - - pslot = radix_tree_lookup_slot(&mapping->i_pages, - page_index(page)); + xas_lock_irq(&xas); expected_count += 1 + page_has_private(page); - if (page_count(page) != expected_count || - radix_tree_deref_slot_protected(pslot, - &mapping->i_pages.xa_lock) != page) { - xa_unlock_irq(&mapping->i_pages); + if (page_count(page) != expected_count || xas_load(&xas) != page) { + xas_unlock_irq(&xas); return -EAGAIN; } if (!page_ref_freeze(page, expected_count)) { - xa_unlock_irq(&mapping->i_pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -494,7 +489,7 @@ int migrate_page_move_mapping(struct address_space *mapping, if (mode == MIGRATE_ASYNC && head && !buffer_migrate_lock_buffers(head, mode)) { page_ref_unfreeze(page, expected_count); - xa_unlock_irq(&mapping->i_pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -522,7 +517,7 @@ int migrate_page_move_mapping(struct address_space *mapping, SetPageDirty(newpage); } - radix_tree_replace_slot(&mapping->i_pages, pslot, newpage); + xas_store(&xas, newpage); /* * Drop cache reference from old page by unfreezing @@ -531,7 +526,7 @@ int migrate_page_move_mapping(struct address_space *mapping, */ page_ref_unfreeze(page, expected_count - 1); - xa_unlock(&mapping->i_pages); + xas_unlock(&xas); /* Leave irq disabled to prevent preemption while updating stats */ /* @@ -571,22 +566,18 @@ EXPORT_SYMBOL(migrate_page_move_mapping); int migrate_huge_page_move_mapping(struct address_space *mapping, struct page *newpage, struct page *page) { + XA_STATE(xas, &mapping->i_pages, page_index(page)); int expected_count; - void **pslot; - - xa_lock_irq(&mapping->i_pages); - - pslot = radix_tree_lookup_slot(&mapping->i_pages, page_index(page)); + xas_lock_irq(&xas); expected_count = 2 + page_has_private(page); - if (page_count(page) != expected_count || - radix_tree_deref_slot_protected(pslot, &mapping->i_pages.xa_lock) != page) { - xa_unlock_irq(&mapping->i_pages); + if (page_count(page) != expected_count || xas_load(&xas) != page) { + xas_unlock_irq(&xas); return -EAGAIN; } if (!page_ref_freeze(page, expected_count)) { - xa_unlock_irq(&mapping->i_pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -595,11 +586,11 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, get_page(newpage); - radix_tree_replace_slot(&mapping->i_pages, pslot, newpage); + xas_store(&xas, newpage); page_ref_unfreeze(page, expected_count - 1); - xa_unlock_irq(&mapping->i_pages); + xas_unlock_irq(&xas); return MIGRATEPAGE_SUCCESS; } -- 2.16.1