From patchwork Mon Feb 6 16:25:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 53425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2337366wrn; Mon, 6 Feb 2023 08:46:51 -0800 (PST) X-Google-Smtp-Source: AK7set9AykJJtdxf8O5aBacvmGKp0P8ceDz1FoPq9gDoMMwdCOzAx0f272fmeL0cMvXv/tEUUPuL X-Received: by 2002:a50:d61b:0:b0:4aa:a6a9:3736 with SMTP id x27-20020a50d61b000000b004aaa6a93736mr201404edi.18.1675702011369; Mon, 06 Feb 2023 08:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675702011; cv=none; d=google.com; s=arc-20160816; b=y4y0W6g1o7lPlLnvKdDD+1if0cExA/Jjx6W8IC/5LAbzJccXZi0oNv4PPAO/2F4VFd Rzkek/utfeQIPXtFcs/Q/YCEl0QGWAbyJhBgd/I2k6bsElcZOXipj9f3H4d2Dgoa2OmE H/+AwD+m5k9qsGAtZn3kt+19UTrHCka5but+csI7fVnbPvrCVtR8HWY6iVNWZJ/eAOOq QcmsxcHujxUq4stQ6RK3IQklupDyszkY//cTecLGlq6oMXtuNQ8x1FxMbl1nJLjStLVc diAuSiejrYwcJQVw5juq/uxVrFGL+clzfFUMhM7mi0qhvjSiTnFbzPoclt3z44gyRDUL yyWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nF6VemGYIMnYuGIHOUFNbRptyFqb1wpSr8JOeBMchwA=; b=MEVBc0mrM1mVaTzmkwf3yY6AZghMzPYaq1OaSXsQyijQoL6HQzP9BNl3oPS8tVOqpS MyfNspMXOxKQZocK2f02xYzJMDhnIp9NgyfMzwgToYXbog/JEibqXlCZBgCKaBh2jyyq 2GTE3fcKeyzd78RZR5S3/hTC0CTRCjMkUues8bouuoQtbRhEUkNCHS4CSnepEnSmwroR sJAXdg1NTl8oYJOcpqM5Ke4bOMIYt0DKv9Xt9/AhFGWz1WTHK+1jsfNnuFkGA+33/qYT 54M9ahkgYbh7R0blaroKp6ki2CNlcQP/Uq8VncdcjBkjBBi0VRYXP1HV8vQnrP7HcM9y zmCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=JE08NReq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id es26-20020a056402381a00b00489df0e67aasi12312764edb.549.2023.02.06.08.46.26; Mon, 06 Feb 2023 08:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=JE08NReq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbjBFQZw (ORCPT + 99 others); Mon, 6 Feb 2023 11:25:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjBFQZu (ORCPT ); Mon, 6 Feb 2023 11:25:50 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B64012060 for ; Mon, 6 Feb 2023 08:25:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=nF6VemGYIMnYuGIHOUFNbRptyFqb1wpSr8JOeBMchwA=; b=JE08NReqM+L8JNrJTSlKV36WgV brl6e/hTgH3unVH/VHUnnBP+gnb2HnmY9YhCJjHxuSe+glqLFFsi4Czrmsid6uvwYUmhoGCLqBjZ7 bMsuY1FH+siGfDtQoY8o3sh766KqFqwc6MfJ6DRGlXlXz8gkpIlVxLAyStjcK3v6ayquUDkSXaFQx D1K8LzLDsOGz0IIJWpNq89Mz72tlhWFkT9+L03QegIsi10xF9o7qVJefZhxDG+zwcBlhlYwp0XuN+ JRF5DdVhRZDbdSQgEx0WEq6MldHmE0LLV5ThXMj8onAHSF0RyO029DIp3kugg4uqGBraOdSRLQoZS +GuwyxhA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pP4JG-00Gu8d-BT; Mon, 06 Feb 2023 16:25:38 +0000 From: "Matthew Wilcox (Oracle)" To: akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, markhemm@googlemail.com, rientjes@google.com, surenb@google.com, shakeelb@google.com, mhocko@suse.com, vbabka@suse.cz, quic_pkondeti@quicinc.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Charan Teja Kalla Subject: [PATCH 1/2] filemap: Add mapping_read_folio_gfp() Date: Mon, 6 Feb 2023 16:25:19 +0000 Message-Id: <20230206162520.4029022-1-willy@infradead.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757100911893193815?= X-GMAIL-MSGID: =?utf-8?q?1757100911893193815?= This is like read_cache_page_gfp() except it returns the folio instead of the precise page. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 47069662f4b8..cf0677419981 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -758,6 +758,8 @@ static inline struct page *grab_cache_page(struct address_space *mapping, struct folio *read_cache_folio(struct address_space *, pgoff_t index, filler_t *filler, struct file *file); +struct folio *mapping_read_folio_gfp(struct address_space *, pgoff_t index, + gfp_t flags); struct page *read_cache_page(struct address_space *, pgoff_t index, filler_t *filler, struct file *file); extern struct page * read_cache_page_gfp(struct address_space *mapping, diff --git a/mm/filemap.c b/mm/filemap.c index 992554c18f1f..2ebcf500871d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3585,6 +3585,30 @@ struct folio *read_cache_folio(struct address_space *mapping, pgoff_t index, } EXPORT_SYMBOL(read_cache_folio); +/** + * mapping_read_folio_gfp - Read into page cache, using specified allocation flags. + * @mapping: The address_space for the folio. + * @index: The index that the allocated folio will contain. + * @gfp: The page allocator flags to use if allocating. + * + * This is the same as "read_cache_folio(mapping, index, NULL, NULL)", but with + * any new memory allocations done using the specified allocation flags. + * + * The most likely error from this function is EIO, but ENOMEM is + * possible and so is EINTR. If ->read_folio returns another error, + * that will be returned to the caller. + * + * The function expects mapping->invalidate_lock to be already held. + * + * Return: Uptodate folio on success, ERR_PTR() on failure. + */ +struct folio *mapping_read_folio_gfp(struct address_space *mapping, + pgoff_t index, gfp_t gfp) +{ + return do_read_cache_folio(mapping, index, NULL, NULL, gfp); +} +EXPORT_SYMBOL(mapping_read_folio_gfp); + static struct page *do_read_cache_page(struct address_space *mapping, pgoff_t index, filler_t *filler, struct file *file, gfp_t gfp) { From patchwork Mon Feb 6 16:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 53426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2337369wrn; Mon, 6 Feb 2023 08:46:52 -0800 (PST) X-Google-Smtp-Source: AK7set+GEQRHgozViwWQ3ywP3EvUwNCe39ngxxPKHrgRQXYadvhk/1ufODk2Bhpj43b4EUSlprI4 X-Received: by 2002:a05:6402:3894:b0:4a3:43c1:843b with SMTP id fd20-20020a056402389400b004a343c1843bmr15872137edb.15.1675702011952; Mon, 06 Feb 2023 08:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675702011; cv=none; d=google.com; s=arc-20160816; b=J3kEi/lb36guSK6fZuOxwQAi7b5lZsDUW1Fjn26oAA4iFECxDcbcKe1TO5EnPc3vqA hRxYXcu+HkSH+yHd8/99K0S8+3x7HztKRzhKOEaYtfYQJeqxvWmGIT1u6bmWPWOD+kEL 5mYK86mhVu4zW80YWrY8BuzTb566xu4L++HJTItZk/w7zMPZLMDQ6Z1K07/4zkp2kqnf gKUjvB8IGezfJEHM6tz32H/Ba8MXRH0E1IA2RBzYaFshciDzTtMF+utJ5zvOWrvXYAdH ncOyAIMwwGYWl47X2aUbvZywiiFmhaZYS9kxCMBbsKaPkU8eGZ45DJY1nwhvBv5lKCul 6s7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EmvsNc/fNNCqQFlmART0Ciul5K1EvPWXNpRv8kY4JJ8=; b=K3TebDeGiWORfQSEcqvpzOw/gbmeQzyTODijG5aoM4+YGlUKwkGB2DZskNZitQ88+z S/hJDcjsuSFTU6gMwLufyCWgwsjLanhQ8iFKGQSimVuXSh2nZ8BI1k/5Slzhrs4II+1t Dv9r8nbqyhchFLtox4avXG+3DV/nUjENr2K3QtkKW1bXNEwU6cOGwzFLVQWu2n3LoqGL pctmk5nZwkvP97Iq4SKo4k2x1Szirv0a+/t0oTQsTXspwrkZAPuUMT8lnPY1nLbA8aWI RNFE1w9PTmiJETTWUwL9fGZbj1P5/iBumdlx0p4KUEpWODjqpkWr3hcBus9ZrbQQMJqJ Xcpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=E3MDzH1w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i26-20020a05640200da00b004a08a5f9e49si12343064edu.48.2023.02.06.08.46.27; Mon, 06 Feb 2023 08:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=E3MDzH1w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjBFQZ4 (ORCPT + 99 others); Mon, 6 Feb 2023 11:25:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbjBFQZx (ORCPT ); Mon, 6 Feb 2023 11:25:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85E201DB86 for ; Mon, 6 Feb 2023 08:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=EmvsNc/fNNCqQFlmART0Ciul5K1EvPWXNpRv8kY4JJ8=; b=E3MDzH1w/xhETRMs+vkPf24prX meYolBlytktHBxGoiWbdWLqJyceli3AZQPEJdg0PxCBAc3MgKTNBUKpK4updO+wuvtWK5XOvIdAvA Y9yw9DDO3WuDVR9rfKTYAXLjteZ/OsnV1pN296p4UE2vmRrdy9ggpNtOqCtxelV1HSpss7mR56ZnM SZqQk46Dxmg2RNBc/mT+363viD6EhgdifvCgyWfWrMfXOIRuD5tsc75XRurDeJOsn1nH9p4QFGlS7 6Okrr57eXr/mGbh03r3P/GnY1hj6SEyscBkYmy7hw77nl9hGIxFNqVht5PjCNw102kvvYmo7QSUik 1aLCQVOg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pP4JG-00Gu8f-EM; Mon, 06 Feb 2023 16:25:38 +0000 From: "Matthew Wilcox (Oracle)" To: akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, markhemm@googlemail.com, rientjes@google.com, surenb@google.com, shakeelb@google.com, mhocko@suse.com, vbabka@suse.cz, quic_pkondeti@quicinc.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Charan Teja Kalla Subject: [PATCH 2/2] shmem: Add shmem_read_folio() and shmem_read_folio_gfp() Date: Mon, 6 Feb 2023 16:25:20 +0000 Message-Id: <20230206162520.4029022-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230206162520.4029022-1-willy@infradead.org> References: <20230206162520.4029022-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757100913225408584?= X-GMAIL-MSGID: =?utf-8?q?1757100913225408584?= These are the folio replacements for shmem_read_mapping_page() and shmem_read_mapping_page_gfp(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/shmem_fs.h | 8 ++++++++ mm/shmem.c | 34 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index d09d54be4ffd..103d1000a5a2 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -109,6 +109,14 @@ enum sgp_type { int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, enum sgp_type sgp); +struct folio *shmem_read_folio_gfp(struct address_space *mapping, + pgoff_t index, gfp_t gfp); + +static inline struct folio *shmem_read_folio(struct address_space *mapping, + pgoff_t index) +{ + return shmem_read_folio_gfp(mapping, index, mapping_gfp_mask(mapping)); +} static inline struct page *shmem_read_mapping_page( struct address_space *mapping, pgoff_t index) diff --git a/mm/shmem.c b/mm/shmem.c index 28f3c699c8ce..d333deddc2b9 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4320,9 +4320,9 @@ int shmem_zero_setup(struct vm_area_struct *vma) } /** - * shmem_read_mapping_page_gfp - read into page cache, using specified page allocation flags. - * @mapping: the page's address_space - * @index: the page index + * shmem_read_folio_gfp - read into page cache, using specified page allocation flags. + * @mapping: the folio's address_space + * @index: the folio index * @gfp: the page allocator flags to use if allocating * * This behaves as a tmpfs "read_cache_page_gfp(mapping, index, gfp)", @@ -4334,13 +4334,12 @@ int shmem_zero_setup(struct vm_area_struct *vma) * i915_gem_object_get_pages_gtt() mixes __GFP_NORETRY | __GFP_NOWARN in * with the mapping_gfp_mask(), to avoid OOMing the machine unnecessarily. */ -struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, - pgoff_t index, gfp_t gfp) +struct folio *shmem_read_folio_gfp(struct address_space *mapping, + pgoff_t index, gfp_t gfp) { #ifdef CONFIG_SHMEM struct inode *inode = mapping->host; struct folio *folio; - struct page *page; int error; BUG_ON(!shmem_mapping(mapping)); @@ -4350,18 +4349,27 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, return ERR_PTR(error); folio_unlock(folio); - page = folio_file_page(folio, index); + return folio; +#else + /* + * The tiny !SHMEM case uses ramfs without swap + */ + return mapping_read_folio_gfp(mapping, index, gfp); +#endif +} +EXPORT_SYMBOL_GPL(shmem_read_folio_gfp); + +struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, + pgoff_t index, gfp_t gfp) +{ + struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp); + struct page *page = folio_file_page(folio, index); + if (PageHWPoison(page)) { folio_put(folio); return ERR_PTR(-EIO); } return page; -#else - /* - * The tiny !SHMEM case uses ramfs without swap - */ - return read_cache_page_gfp(mapping, index, gfp); -#endif } EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);