Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4115601imm; Mon, 11 Jun 2018 07:15:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLTt4Wif6AxNBFJyPWRfvlXKMJNxn8I2Jzv8ioWusT3OOEnkdKJITx4RN7IcGbzdCHeaI1A X-Received: by 2002:a17:902:700a:: with SMTP id y10-v6mr19136531plk.249.1528726520978; Mon, 11 Jun 2018 07:15:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726520; cv=none; d=google.com; s=arc-20160816; b=aaa26OWg+B5fQdlLmu2FnEQtaf8SWyqaUAondBRKyfXsvxY1ogCmdsHKtVoR/nRaur EwkBTH+U51SRWIwEmS/OZpYafNT5djAEyy5q0u9b3GB3Mlvw5U9tG2eogadmc6N518vj 3PdasfWFXmEkPIGW5ywqeUUt2DPXITHhI7OmKGlcl9qCd9ftrq7QSKEwX9eRR2t2xDTw Xk8w8xVNpUnufu/M+844IAoNpbt5QKPxSLf2AB2YmseTGi8vl/aIUYHDsFu6g5xQQg/A ii86amI/d9Bozp97aUJh+elvbwYX1tuhSW1vbhmSMhnbXHaUcBnJIRq4MJkY7jHZAbNL CbOA== 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=Y/xGYYXtotYGntdReNGF/yCzCA63LkwWsEkWoYLOKnA=; b=d2GV5lyDoRw02753a1UUpkC/ZIOhLazbyW0HM0V8oRPrVL/lc0lcmPst1JHQBNQEjp INhdTt8c2CDtwHw0NMuRkr+yBwMYsQ7BkVIkuv+YbZAyv2kiD4HBUrjk6UIJvFwgCU/z ZzRQVxYGaLNPzTN9mphzrq7OLSvLpiQXbYKqVue38DqWKPLrrD+Xa36jWnnbk0tVB+lL nk/vVp4KYsMDXndtYIKK1Wh0Z6Rog31ptyRITPNGa50tR9QQ2fm+bs9te//cKGZ8WPuc 5w09SdJFjcXMzL6HRg2xFDfbrYsQTmdCtj6Yh1lQCVfFSvYNo7RV9+kQKIkfzp0+/b1v yZxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=FtZ0bvKB; 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 e1-v6si65592017plk.397.2018.06.11.07.15.06; Mon, 11 Jun 2018 07:15:20 -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=FtZ0bvKB; 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 S933840AbeFKOOS (ORCPT + 99 others); Mon, 11 Jun 2018 10:14:18 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46162 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933417AbeFKOHE (ORCPT ); Mon, 11 Jun 2018 10:07:04 -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=Y/xGYYXtotYGntdReNGF/yCzCA63LkwWsEkWoYLOKnA=; b=FtZ0bvKBvOSJ0YrtqhYJieQ6z /VIP7D5CvgaWJ43rCQT800R9U0KKYIrtPxuJDUhPJW5jL0xvZ3xv77scA1QqfllamMMK1edqgHqEN jLKD1CI6JqmDuzFXM1onHJnyXhfBxY1DdK4lZS1pDEOYvTH7PLY0J6QzIGMWa5MX2VxmIbaaLDpA2 5t0KUU5MjnWEr/3/WkaioVGp2rYQMLwfSDlsoLwDcT7jNSUv/fhg0QRxGrxCM+0ulYPLv1VQ4PgtS owMdcvV9GFsc127ex1dhnMtT1pcASRreN8J7zms+n6/SJySWiyDdL3Hj9+2bS4hV5fFdDVTjlxjAv RCc0UDoGA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTL-0004t9-2l; Mon, 11 Jun 2018 14:07:03 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 49/72] shmem: Convert shmem_add_to_page_cache to XArray Date: Mon, 11 Jun 2018 07:06:16 -0700 Message-Id: <20180611140639.17215-50-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-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 This removes the last caller of radix_tree_maybe_preload_order(). Simpler code, unless we run out of memory for new xa_nodes partway through inserting entries into the xarray. Hopefully we can support multi-index entries in the page cache soon and all the awful code goes away. Signed-off-by: Matthew Wilcox --- mm/shmem.c | 87 ++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 983a27656e2e..8e702b6d84a5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -576,9 +576,10 @@ static inline bool is_huge_enabled(struct shmem_sb_info *sbinfo) */ static int shmem_add_to_page_cache(struct page *page, struct address_space *mapping, - pgoff_t index, void *expected) + pgoff_t index, void *expected, gfp_t gfp) { - int error, nr = hpage_nr_pages(page); + XA_STATE(xas, &mapping->i_pages, index); + unsigned long i, nr = 1UL << compound_order(page); VM_BUG_ON_PAGE(PageTail(page), page); VM_BUG_ON_PAGE(index != round_down(index, nr), page); @@ -587,49 +588,47 @@ static int shmem_add_to_page_cache(struct page *page, VM_BUG_ON(expected && PageTransHuge(page)); page_ref_add(page, nr); - page->mapping = mapping; page->index = index; + page->mapping = mapping; - xa_lock_irq(&mapping->i_pages); - if (PageTransHuge(page)) { - void __rcu **results; - pgoff_t idx; - int i; - - error = 0; - if (radix_tree_gang_lookup_slot(&mapping->i_pages, - &results, &idx, index, 1) && - idx < index + HPAGE_PMD_NR) { - error = -EEXIST; + do { + xas_lock_irq(&xas); + xas_create_range(&xas, index + nr - 1); + if (xas_error(&xas)) + goto unlock; + for (i = 0; i < nr; i++) { + void *entry = xas_load(&xas); + if (entry != expected) + xas_set_err(&xas, -ENOENT); + if (xas_error(&xas)) + goto undo; + xas_store(&xas, page + i); + xas_next(&xas); } - - if (!error) { - for (i = 0; i < HPAGE_PMD_NR; i++) { - error = radix_tree_insert(&mapping->i_pages, - index + i, page + i); - VM_BUG_ON(error); - } + if (PageTransHuge(page)) { count_vm_event(THP_FILE_ALLOC); + __inc_node_page_state(page, NR_SHMEM_THPS); } - } else if (!expected) { - error = radix_tree_insert(&mapping->i_pages, index, page); - } else { - error = shmem_replace_entry(mapping, index, expected, page); - } - - if (!error) { mapping->nrpages += nr; - if (PageTransHuge(page)) - __inc_node_page_state(page, NR_SHMEM_THPS); __mod_node_page_state(page_pgdat(page), NR_FILE_PAGES, nr); __mod_node_page_state(page_pgdat(page), NR_SHMEM, nr); - xa_unlock_irq(&mapping->i_pages); - } else { + goto unlock; +undo: + while (i-- > 0) { + xas_store(&xas, NULL); + xas_prev(&xas); + } +unlock: + xas_unlock_irq(&xas); + } while (xas_nomem(&xas, gfp)); + + if (xas_error(&xas)) { page->mapping = NULL; - xa_unlock_irq(&mapping->i_pages); page_ref_sub(page, nr); + return xas_error(&xas); } - return error; + + return 0; } /* @@ -1182,7 +1181,7 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, */ if (!error) error = shmem_add_to_page_cache(*pagep, mapping, index, - radswap); + radswap, gfp); if (error != -ENOMEM) { /* * Truncation and eviction use free_swap_and_cache(), which @@ -1698,7 +1697,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, false); if (!error) { error = shmem_add_to_page_cache(page, mapping, index, - swp_to_radix_entry(swap)); + swp_to_radix_entry(swap), gfp); /* * We already confirmed swap under page lock, and make * no memory allocation here, so usually no possibility @@ -1804,13 +1803,8 @@ alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, inode, PageTransHuge(page)); if (error) goto unacct; - error = radix_tree_maybe_preload_order(gfp & GFP_RECLAIM_MASK, - compound_order(page)); - if (!error) { - error = shmem_add_to_page_cache(page, mapping, hindex, - NULL); - radix_tree_preload_end(); - } + error = shmem_add_to_page_cache(page, mapping, hindex, + NULL, gfp & GFP_RECLAIM_MASK); if (error) { mem_cgroup_cancel_charge(page, memcg, PageTransHuge(page)); @@ -2277,11 +2271,8 @@ static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, if (ret) goto out_release; - ret = radix_tree_maybe_preload(gfp & GFP_RECLAIM_MASK); - if (!ret) { - ret = shmem_add_to_page_cache(page, mapping, pgoff, NULL); - radix_tree_preload_end(); - } + ret = shmem_add_to_page_cache(page, mapping, pgoff, NULL, + gfp & GFP_RECLAIM_MASK); if (ret) goto out_release_uncharge; -- 2.17.1